[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAHX4x85id5dwXrBSVHTZaRV43JGAxZwMkvnDN6yH5_Mg4UxRPg@mail.gmail.com>
Date: Wed, 19 Jun 2019 09:44:50 -0600
From: Nick Crews <ncrews@...omium.org>
To: Dan Carpenter <dan.carpenter@...cle.com>
Cc: Colin King <colin.king@...onical.com>,
Benson Leung <bleung@...omium.org>,
Enric Balletbo i Serra <enric.balletbo@...labora.com>,
kernel-janitors@...r.kernel.org,
linux-kernel <linux-kernel@...r.kernel.org>,
Dmitry Torokhov <dtor@...gle.com>
Subject: Re: [PATCH][next] platform/chrome: wilco_ec: fix null pointer
dereference on failed kzalloc
On Tue, Jun 18, 2019 at 11:30 PM Dan Carpenter <dan.carpenter@...cle.com> wrote:
>
> On Tue, Jun 18, 2019 at 04:39:24PM +0100, Colin King wrote:
> > diff --git a/drivers/platform/chrome/wilco_ec/event.c b/drivers/platform/chrome/wilco_ec/event.c
> > index c975b76e6255..e251a989b152 100644
> > --- a/drivers/platform/chrome/wilco_ec/event.c
> > +++ b/drivers/platform/chrome/wilco_ec/event.c
> > @@ -112,8 +112,11 @@ module_param(queue_size, int, 0644);
> > static struct ec_event_queue *event_queue_new(int capacity)
> > {
> > size_t entries_size = sizeof(struct ec_event *) * capacity;
> > - struct ec_event_queue *q = kzalloc(sizeof(*q) + entries_size,
> > - GFP_KERNEL);
> > + struct ec_event_queue *q;
> > +
> > + q = kzalloc(sizeof(*q) + entries_size, GFP_KERNEL);
> > + if (!q)
> > + return NULL;
>
> We have a new struct_size() macro designed for these allocations.
>
> q = kzalloc(struct_size(q, entries, capacity), GFP_KERNEL);
>
> The advantage is that it checks for integer overflows.
>
> regards,
> dan carpenter
>
Thanks Dan, I like that.
Dmitry Torokhov also had some thoughts on this patch at
https://crrev.com/c/1661053, I'll send a patch that adds this and
fixes his concerns in a bit.
Cheers,
Nick
Powered by blists - more mailing lists