All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] thunderbolt: Check for null pointer after calling kmemdup in icm_handle_event
@ 2022-01-05  8:26 Jiasheng Jiang
  2022-01-05 10:17 ` Mika Westerberg
  2022-01-05 10:21 ` Greg KH
  0 siblings, 2 replies; 3+ messages in thread
From: Jiasheng Jiang @ 2022-01-05  8:26 UTC (permalink / raw)
  To: mika.westerberg
  Cc: andreas.noever, michael.jamet, YehezkelShB, linux-usb,
	linux-kernel, Jiasheng Jiang

As the possible failure of the allocation, kmemdup() may return NULL
pointer.
Like alloc_switch(), it might be better to check it.
Therefore, icm_handle_event() should also check the return value of
kmemdup().
If fails, just free 'n' and directly return is enough, same as the way
to handle the failure of kmalloc().

Fixes: f67cf491175a ("thunderbolt: Add support for Internal Connection Manager (ICM)")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
 drivers/thunderbolt/icm.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/thunderbolt/icm.c b/drivers/thunderbolt/icm.c
index 2f30b816705a..514a77a02985 100644
--- a/drivers/thunderbolt/icm.c
+++ b/drivers/thunderbolt/icm.c
@@ -1739,6 +1739,11 @@ static void icm_handle_event(struct tb *tb, enum tb_cfg_pkg_type type,
 
 	INIT_WORK(&n->work, icm_handle_notification);
 	n->pkg = kmemdup(buf, size, GFP_KERNEL);
+	if (!n->pkg) {
+		kfree(n);
+		return;
+	}
+
 	n->tb = tb;
 
 	queue_work(tb->wq, &n->work);
-- 
2.25.1


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

* Re: [PATCH] thunderbolt: Check for null pointer after calling kmemdup in icm_handle_event
  2022-01-05  8:26 [PATCH] thunderbolt: Check for null pointer after calling kmemdup in icm_handle_event Jiasheng Jiang
@ 2022-01-05 10:17 ` Mika Westerberg
  2022-01-05 10:21 ` Greg KH
  1 sibling, 0 replies; 3+ messages in thread
From: Mika Westerberg @ 2022-01-05 10:17 UTC (permalink / raw)
  To: Jiasheng Jiang
  Cc: andreas.noever, michael.jamet, YehezkelShB, linux-usb, linux-kernel

Hi,

On Wed, Jan 05, 2022 at 04:26:34PM +0800, Jiasheng Jiang wrote:
> As the possible failure of the allocation, kmemdup() may return NULL
> pointer.
> Like alloc_switch(), it might be better to check it.
> Therefore, icm_handle_event() should also check the return value of
> kmemdup().
> If fails, just free 'n' and directly return is enough, same as the way
> to handle the failure of kmalloc().
> 
> Fixes: f67cf491175a ("thunderbolt: Add support for Internal Connection Manager (ICM)")
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>

Thanks for the patch but I realized that this has been fixed already:

https://git.kernel.org/pub/scm/linux/kernel/git/westeri/thunderbolt.git/commit/?h=next&id=3cc1c6de458e0e58c413c3c35802ca96e55bbdbe

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

* Re: [PATCH] thunderbolt: Check for null pointer after calling kmemdup in icm_handle_event
  2022-01-05  8:26 [PATCH] thunderbolt: Check for null pointer after calling kmemdup in icm_handle_event Jiasheng Jiang
  2022-01-05 10:17 ` Mika Westerberg
@ 2022-01-05 10:21 ` Greg KH
  1 sibling, 0 replies; 3+ messages in thread
From: Greg KH @ 2022-01-05 10:21 UTC (permalink / raw)
  To: Jiasheng Jiang
  Cc: mika.westerberg, andreas.noever, michael.jamet, YehezkelShB,
	linux-usb, linux-kernel

On Wed, Jan 05, 2022 at 04:26:34PM +0800, Jiasheng Jiang wrote:
> As the possible failure of the allocation, kmemdup() may return NULL
> pointer.
> Like alloc_switch(), it might be better to check it.
> Therefore, icm_handle_event() should also check the return value of
> kmemdup().
> If fails, just free 'n' and directly return is enough, same as the way
> to handle the failure of kmalloc().

I can not understand this changelog text at all, sorry.  Please read the
documentation for how to write a good changelog text.

And most importantly, how did you test this change?

thanks,

greg k-h

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

end of thread, other threads:[~2022-01-05 10:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-05  8:26 [PATCH] thunderbolt: Check for null pointer after calling kmemdup in icm_handle_event Jiasheng Jiang
2022-01-05 10:17 ` Mika Westerberg
2022-01-05 10:21 ` Greg KH

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.