All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH][next] platform/chrome: wilco_ec: fix null pointer dereference on failed kzalloc
@ 2019-06-18 15:39 ` Colin King
  0 siblings, 0 replies; 12+ messages in thread
From: Colin King @ 2019-06-18 15:39 UTC (permalink / raw)
  To: Benson Leung, Enric Balletbo i Serra, Nick Crews
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

If the kzalloc of the entries queue q fails a null pointer dereference
occurs when accessing q->capacity and q->lock.  Add a kzalloc failure
check and handle the null return case in the calling function
event_device_add.

Addresses-Coverity: ("Dereference null return")
Fixes: 75589e37d1dc ("platform/chrome: wilco_ec: Add circular buffer as event queue")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/platform/chrome/wilco_ec/event.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

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;
 
 	q->capacity = capacity;
 	spin_lock_init(&q->lock);
@@ -474,6 +477,11 @@ static int event_device_add(struct acpi_device *adev)
 	/* Initialize the device data. */
 	adev->driver_data = dev_data;
 	dev_data->events = event_queue_new(queue_size);
+	if (!dev_data->events) {
+		kfree(dev_data);
+		error = -ENOMEM;
+		goto free_minor;
+	}
 	init_waitqueue_head(&dev_data->wq);
 	dev_data->exist = true;
 	atomic_set(&dev_data->available, 1);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH][next] platform/chrome: wilco_ec: fix null pointer dereference on failed kzalloc
@ 2019-06-18 15:39 ` Colin King
  0 siblings, 0 replies; 12+ messages in thread
From: Colin King @ 2019-06-18 15:39 UTC (permalink / raw)
  To: Benson Leung, Enric Balletbo i Serra, Nick Crews
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

If the kzalloc of the entries queue q fails a null pointer dereference
occurs when accessing q->capacity and q->lock.  Add a kzalloc failure
check and handle the null return case in the calling function
event_device_add.

Addresses-Coverity: ("Dereference null return")
Fixes: 75589e37d1dc ("platform/chrome: wilco_ec: Add circular buffer as event queue")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/platform/chrome/wilco_ec/event.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

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;
 
 	q->capacity = capacity;
 	spin_lock_init(&q->lock);
@@ -474,6 +477,11 @@ static int event_device_add(struct acpi_device *adev)
 	/* Initialize the device data. */
 	adev->driver_data = dev_data;
 	dev_data->events = event_queue_new(queue_size);
+	if (!dev_data->events) {
+		kfree(dev_data);
+		error = -ENOMEM;
+		goto free_minor;
+	}
 	init_waitqueue_head(&dev_data->wq);
 	dev_data->exist = true;
 	atomic_set(&dev_data->available, 1);
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH][next] platform/chrome: wilco_ec: fix null pointer dereference on failed kzalloc
  2019-06-18 15:39 ` Colin King
@ 2019-06-18 17:15   ` Nick Crews
  -1 siblings, 0 replies; 12+ messages in thread
From: Nick Crews @ 2019-06-18 17:15 UTC (permalink / raw)
  To: Colin King
  Cc: Benson Leung, Enric Balletbo i Serra, kernel-janitors, linux-kernel

Thanks Colin, good catch.

Enric, could you squash this into the real commit?

On Tue, Jun 18, 2019 at 9:39 AM Colin King <colin.king@canonical.com> wrote:
>
> From: Colin Ian King <colin.king@canonical.com>
>
> If the kzalloc of the entries queue q fails a null pointer dereference
> occurs when accessing q->capacity and q->lock.  Add a kzalloc failure
> check and handle the null return case in the calling function
> event_device_add.
>
> Addresses-Coverity: ("Dereference null return")
> Fixes: 75589e37d1dc ("platform/chrome: wilco_ec: Add circular buffer as event queue")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/platform/chrome/wilco_ec/event.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
>
> 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;
>
>         q->capacity = capacity;
>         spin_lock_init(&q->lock);
> @@ -474,6 +477,11 @@ static int event_device_add(struct acpi_device *adev)
>         /* Initialize the device data. */
>         adev->driver_data = dev_data;
>         dev_data->events = event_queue_new(queue_size);
> +       if (!dev_data->events) {
> +               kfree(dev_data);
> +               error = -ENOMEM;
> +               goto free_minor;
> +       }
>         init_waitqueue_head(&dev_data->wq);
>         dev_data->exist = true;
>         atomic_set(&dev_data->available, 1);

Signed-off-by: Nick Crews <ncrews@chromium.org>

> --
> 2.20.1
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH][next] platform/chrome: wilco_ec: fix null pointer dereference on failed kzalloc
@ 2019-06-18 17:15   ` Nick Crews
  0 siblings, 0 replies; 12+ messages in thread
From: Nick Crews @ 2019-06-18 17:15 UTC (permalink / raw)
  To: Colin King
  Cc: Benson Leung, Enric Balletbo i Serra, kernel-janitors, linux-kernel

Thanks Colin, good catch.

Enric, could you squash this into the real commit?

On Tue, Jun 18, 2019 at 9:39 AM Colin King <colin.king@canonical.com> wrote:
>
> From: Colin Ian King <colin.king@canonical.com>
>
> If the kzalloc of the entries queue q fails a null pointer dereference
> occurs when accessing q->capacity and q->lock.  Add a kzalloc failure
> check and handle the null return case in the calling function
> event_device_add.
>
> Addresses-Coverity: ("Dereference null return")
> Fixes: 75589e37d1dc ("platform/chrome: wilco_ec: Add circular buffer as event queue")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/platform/chrome/wilco_ec/event.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
>
> 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;
>
>         q->capacity = capacity;
>         spin_lock_init(&q->lock);
> @@ -474,6 +477,11 @@ static int event_device_add(struct acpi_device *adev)
>         /* Initialize the device data. */
>         adev->driver_data = dev_data;
>         dev_data->events = event_queue_new(queue_size);
> +       if (!dev_data->events) {
> +               kfree(dev_data);
> +               error = -ENOMEM;
> +               goto free_minor;
> +       }
>         init_waitqueue_head(&dev_data->wq);
>         dev_data->exist = true;
>         atomic_set(&dev_data->available, 1);

Signed-off-by: Nick Crews <ncrews@chromium.org>

> --
> 2.20.1
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH][next] platform/chrome: wilco_ec: fix null pointer dereference on failed kzalloc
  2019-06-18 17:15   ` Nick Crews
@ 2019-06-18 19:49     ` Benson Leung
  -1 siblings, 0 replies; 12+ messages in thread
From: Benson Leung @ 2019-06-18 19:49 UTC (permalink / raw)
  To: Nick Crews
  Cc: Colin King, Benson Leung, Enric Balletbo i Serra,
	kernel-janitors, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 387 bytes --]

Hi Nick,

On Tue, Jun 18, 2019 at 11:15:03AM -0600, Nick Crews wrote:
> Thanks Colin, good catch.
> 
> Enric, could you squash this into the real commit?

I've applied this to for-next and for-kernelci in chrome-platform.

Thanks,
Benson

-- 
Benson Leung
Staff Software Engineer
Chrome OS Kernel
Google Inc.
bleung@google.com
Chromium OS Project
bleung@chromium.org

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH][next] platform/chrome: wilco_ec: fix null pointer dereference on failed kzalloc
@ 2019-06-18 19:49     ` Benson Leung
  0 siblings, 0 replies; 12+ messages in thread
From: Benson Leung @ 2019-06-18 19:49 UTC (permalink / raw)
  To: Nick Crews
  Cc: Colin King, Benson Leung, Enric Balletbo i Serra,
	kernel-janitors, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 387 bytes --]

Hi Nick,

On Tue, Jun 18, 2019 at 11:15:03AM -0600, Nick Crews wrote:
> Thanks Colin, good catch.
> 
> Enric, could you squash this into the real commit?

I've applied this to for-next and for-kernelci in chrome-platform.

Thanks,
Benson

-- 
Benson Leung
Staff Software Engineer
Chrome OS Kernel
Google Inc.
bleung@google.com
Chromium OS Project
bleung@chromium.org

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH][next] platform/chrome: wilco_ec: fix null pointer dereference on failed kzalloc
  2019-06-18 15:39 ` Colin King
@ 2019-06-18 19:50   ` Benson Leung
  -1 siblings, 0 replies; 12+ messages in thread
From: Benson Leung @ 2019-06-18 19:50 UTC (permalink / raw)
  To: Colin King
  Cc: Benson Leung, Enric Balletbo i Serra, Nick Crews,
	kernel-janitors, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2028 bytes --]

Hi Colin,

On Tue, Jun 18, 2019 at 04:39:24PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> If the kzalloc of the entries queue q fails a null pointer dereference
> occurs when accessing q->capacity and q->lock.  Add a kzalloc failure
> check and handle the null return case in the calling function
> event_device_add.
> 
> Addresses-Coverity: ("Dereference null return")
> Fixes: 75589e37d1dc ("platform/chrome: wilco_ec: Add circular buffer as event queue")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Applied. Thanks.

Benson

> ---
>  drivers/platform/chrome/wilco_ec/event.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> 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;
>  
>  	q->capacity = capacity;
>  	spin_lock_init(&q->lock);
> @@ -474,6 +477,11 @@ static int event_device_add(struct acpi_device *adev)
>  	/* Initialize the device data. */
>  	adev->driver_data = dev_data;
>  	dev_data->events = event_queue_new(queue_size);
> +	if (!dev_data->events) {
> +		kfree(dev_data);
> +		error = -ENOMEM;
> +		goto free_minor;
> +	}
>  	init_waitqueue_head(&dev_data->wq);
>  	dev_data->exist = true;
>  	atomic_set(&dev_data->available, 1);
> -- 
> 2.20.1
> 

-- 
Benson Leung
Staff Software Engineer
Chrome OS Kernel
Google Inc.
bleung@google.com
Chromium OS Project
bleung@chromium.org

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH][next] platform/chrome: wilco_ec: fix null pointer dereference on failed kzalloc
@ 2019-06-18 19:50   ` Benson Leung
  0 siblings, 0 replies; 12+ messages in thread
From: Benson Leung @ 2019-06-18 19:50 UTC (permalink / raw)
  To: Colin King
  Cc: Benson Leung, Enric Balletbo i Serra, Nick Crews,
	kernel-janitors, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2028 bytes --]

Hi Colin,

On Tue, Jun 18, 2019 at 04:39:24PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> If the kzalloc of the entries queue q fails a null pointer dereference
> occurs when accessing q->capacity and q->lock.  Add a kzalloc failure
> check and handle the null return case in the calling function
> event_device_add.
> 
> Addresses-Coverity: ("Dereference null return")
> Fixes: 75589e37d1dc ("platform/chrome: wilco_ec: Add circular buffer as event queue")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Applied. Thanks.

Benson

> ---
>  drivers/platform/chrome/wilco_ec/event.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> 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;
>  
>  	q->capacity = capacity;
>  	spin_lock_init(&q->lock);
> @@ -474,6 +477,11 @@ static int event_device_add(struct acpi_device *adev)
>  	/* Initialize the device data. */
>  	adev->driver_data = dev_data;
>  	dev_data->events = event_queue_new(queue_size);
> +	if (!dev_data->events) {
> +		kfree(dev_data);
> +		error = -ENOMEM;
> +		goto free_minor;
> +	}
>  	init_waitqueue_head(&dev_data->wq);
>  	dev_data->exist = true;
>  	atomic_set(&dev_data->available, 1);
> -- 
> 2.20.1
> 

-- 
Benson Leung
Staff Software Engineer
Chrome OS Kernel
Google Inc.
bleung@google.com
Chromium OS Project
bleung@chromium.org

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH][next] platform/chrome: wilco_ec: fix null pointer dereference on failed kzalloc
  2019-06-18 15:39 ` Colin King
@ 2019-06-19  5:30   ` Dan Carpenter
  -1 siblings, 0 replies; 12+ messages in thread
From: Dan Carpenter @ 2019-06-19  5:30 UTC (permalink / raw)
  To: Colin King
  Cc: Benson Leung, Enric Balletbo i Serra, Nick Crews,
	kernel-janitors, linux-kernel

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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH][next] platform/chrome: wilco_ec: fix null pointer dereference on failed kzalloc
@ 2019-06-19  5:30   ` Dan Carpenter
  0 siblings, 0 replies; 12+ messages in thread
From: Dan Carpenter @ 2019-06-19  5:30 UTC (permalink / raw)
  To: Colin King
  Cc: Benson Leung, Enric Balletbo i Serra, Nick Crews,
	kernel-janitors, linux-kernel

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH][next] platform/chrome: wilco_ec: fix null pointer dereference on failed kzalloc
  2019-06-19  5:30   ` Dan Carpenter
@ 2019-06-19 15:44     ` Nick Crews
  -1 siblings, 0 replies; 12+ messages in thread
From: Nick Crews @ 2019-06-19 15:44 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Colin King, Benson Leung, Enric Balletbo i Serra,
	kernel-janitors, linux-kernel, Dmitry Torokhov

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH][next] platform/chrome: wilco_ec: fix null pointer dereference on failed kzalloc
@ 2019-06-19 15:44     ` Nick Crews
  0 siblings, 0 replies; 12+ messages in thread
From: Nick Crews @ 2019-06-19 15:44 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Colin King, Benson Leung, Enric Balletbo i Serra,
	kernel-janitors, linux-kernel, Dmitry Torokhov

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2019-06-19 15:45 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-18 15:39 [PATCH][next] platform/chrome: wilco_ec: fix null pointer dereference on failed kzalloc Colin King
2019-06-18 15:39 ` Colin King
2019-06-18 17:15 ` Nick Crews
2019-06-18 17:15   ` Nick Crews
2019-06-18 19:49   ` Benson Leung
2019-06-18 19:49     ` Benson Leung
2019-06-18 19:50 ` Benson Leung
2019-06-18 19:50   ` Benson Leung
2019-06-19  5:30 ` Dan Carpenter
2019-06-19  5:30   ` Dan Carpenter
2019-06-19 15:44   ` Nick Crews
2019-06-19 15:44     ` Nick Crews

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.