lkml.org 
[lkml]   [2019]   [Jun]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [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@oracle.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

\
 
 \ /
  Last update: 2019-06-19 17:45    [W:0.053 / U:1.188 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site