[PATCH net-next] lib: packing: catch kunit_kzalloc() failure in the pack() test

Subsystems: library code, packing, the rest

STALE703d

5 messages, 4 authors, 2024-10-09 · open the first message on its own page

[PATCH net-next] lib: packing: catch kunit_kzalloc() failure in the pack() test

From: Vladimir Oltean <vladimir.oltean@nxp.com>
Date: 2024-10-04 11:00:32

kunit_kzalloc() may fail. Other call sites verify that this is the case,
either using a direct comparison with the NULL pointer, or the
KUNIT_ASSERT_NOT_NULL() or KUNIT_ASSERT_NOT_ERR_OR_NULL().

Pick KUNIT_ASSERT_NOT_NULL() as the error handling method that made most
sense to me. It's an unlikely thing to happen, but at least we call
__kunit_abort() instead of dereferencing this NULL pointer.

Fixes: e9502ea6db8a ("lib: packing: add KUnit tests adapted from selftests")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 lib/packing_test.c | 1 +
 1 file changed, 1 insertion(+)
diff --git a/lib/packing_test.c b/lib/packing_test.c
index 015ad1180d23..b38ea43c03fd 100644
--- a/lib/packing_test.c
+++ b/lib/packing_test.c
@@ -375,6 +375,7 @@ static void packing_test_pack(struct kunit *test)
 	int err;
 
 	pbuf = kunit_kzalloc(test, params->pbuf_size, GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, pbuf);
 
 	err = pack(pbuf, params->uval, params->start_bit, params->end_bit,
 		   params->pbuf_size, params->quirks);
-- 
2.43.0

RE: [PATCH net-next] lib: packing: catch kunit_kzalloc() failure in the pack() test

From: "Keller, Jacob E" <jacob.e.keller@intel.com>
Date: 2024-10-04 19:20:13

quoted hunk
-----Original Message-----
From: Vladimir Oltean <vladimir.oltean@nxp.com>
Sent: Friday, October 4, 2024 4:00 AM
To: netdev@vger.kernel.org
Cc: David S. Miller <davem@davemloft.net>; Eric Dumazet
[off-list ref]; Jakub Kicinski [off-list ref]; Paolo Abeni
[off-list ref]; Keller, Jacob E [off-list ref]; Kitszel,
Przemyslaw [off-list ref]; linux-kernel@vger.kernel.org
Subject: [PATCH net-next] lib: packing: catch kunit_kzalloc() failure in the pack()
test

kunit_kzalloc() may fail. Other call sites verify that this is the case,
either using a direct comparison with the NULL pointer, or the
KUNIT_ASSERT_NOT_NULL() or KUNIT_ASSERT_NOT_ERR_OR_NULL().

Pick KUNIT_ASSERT_NOT_NULL() as the error handling method that made most
sense to me. It's an unlikely thing to happen, but at least we call
__kunit_abort() instead of dereferencing this NULL pointer.

Fixes: e9502ea6db8a ("lib: packing: add KUnit tests adapted from selftests")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 lib/packing_test.c | 1 +
 1 file changed, 1 insertion(+)
diff --git a/lib/packing_test.c b/lib/packing_test.c
index 015ad1180d23..b38ea43c03fd 100644
--- a/lib/packing_test.c
+++ b/lib/packing_test.c
@@ -375,6 +375,7 @@ static void packing_test_pack(struct kunit *test)
 	int err;

 	pbuf = kunit_kzalloc(test, params->pbuf_size, GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, pbuf);

 	err = pack(pbuf, params->uval, params->start_bit, params->end_bit,
 		   params->pbuf_size, params->quirks);
--
2.43.0
Oh good catch! I guess I had assumed that kunit_kzalloc would itself detect and fail instead of continuing....

Re: [PATCH net-next] lib: packing: catch kunit_kzalloc() failure in the pack() test

From: patchwork-bot+netdevbpf@kernel.org
Date: 2024-10-07 23:40:37

Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski [off-list ref]:

On Fri,  4 Oct 2024 14:00:12 +0300 you wrote:
kunit_kzalloc() may fail. Other call sites verify that this is the case,
either using a direct comparison with the NULL pointer, or the
KUNIT_ASSERT_NOT_NULL() or KUNIT_ASSERT_NOT_ERR_OR_NULL().

Pick KUNIT_ASSERT_NOT_NULL() as the error handling method that made most
sense to me. It's an unlikely thing to happen, but at least we call
__kunit_abort() instead of dereferencing this NULL pointer.

[...]
Here is the summary with links:
  - [net-next] lib: packing: catch kunit_kzalloc() failure in the pack() test
    https://git.kernel.org/netdev/net-next/c/1405981bbba0

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

Re: [PATCH net-next] lib: packing: catch kunit_kzalloc() failure in the pack() test

From: Przemek Kitszel <przemyslaw.kitszel@intel.com>
Date: 2024-10-09 10:21:30

On 10/4/24 21:20, Keller, Jacob E wrote:
quoted
-----Original Message-----
From: Vladimir Oltean <vladimir.oltean@nxp.com>
Sent: Friday, October 4, 2024 4:00 AM
To: netdev@vger.kernel.org
Cc: David S. Miller <davem@davemloft.net>; Eric Dumazet
[off-list ref]; Jakub Kicinski [off-list ref]; Paolo Abeni
[off-list ref]; Keller, Jacob E [off-list ref]; Kitszel,
Przemyslaw [off-list ref]; linux-kernel@vger.kernel.org
Subject: [PATCH net-next] lib: packing: catch kunit_kzalloc() failure in the pack()
test

kunit_kzalloc() may fail. Other call sites verify that this is the case,
either using a direct comparison with the NULL pointer, or the
KUNIT_ASSERT_NOT_NULL() or KUNIT_ASSERT_NOT_ERR_OR_NULL().

Pick KUNIT_ASSERT_NOT_NULL() as the error handling method that made most
sense to me. It's an unlikely thing to happen, but at least we call
__kunit_abort() instead of dereferencing this NULL pointer.

Fixes: e9502ea6db8a ("lib: packing: add KUnit tests adapted from selftests")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
  lib/packing_test.c | 1 +
  1 file changed, 1 insertion(+)
diff --git a/lib/packing_test.c b/lib/packing_test.c
index 015ad1180d23..b38ea43c03fd 100644
--- a/lib/packing_test.c
+++ b/lib/packing_test.c
@@ -375,6 +375,7 @@ static void packing_test_pack(struct kunit *test)
  	int err;

  	pbuf = kunit_kzalloc(test, params->pbuf_size, GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, pbuf);

  	err = pack(pbuf, params->uval, params->start_bit, params->end_bit,
  		   params->pbuf_size, params->quirks);
--
2.43.0
Oh good catch! I guess I had assumed that kunit_kzalloc would itself detect and fail instead of continuing....
that would be great

kunit_*alloc gives kunit-managed resources though

RE: [PATCH net-next] lib: packing: catch kunit_kzalloc() failure in the pack() test

From: "Keller, Jacob E" <jacob.e.keller@intel.com>
Date: 2024-10-09 20:52:15

-----Original Message-----
From: Kitszel, Przemyslaw <przemyslaw.kitszel@intel.com>
Sent: Wednesday, October 9, 2024 3:21 AM
To: Keller, Jacob E <jacob.e.keller@intel.com>; Vladimir Oltean
[off-list ref]
Cc: David S. Miller <davem@davemloft.net>; Eric Dumazet
[off-list ref]; Jakub Kicinski [off-list ref]; Paolo Abeni
[off-list ref]; linux-kernel@vger.kernel.org; netdev@vger.kernel.org
Subject: Re: [PATCH net-next] lib: packing: catch kunit_kzalloc() failure in the pack()
test

On 10/4/24 21:20, Keller, Jacob E wrote:
quoted
quoted
-----Original Message-----
From: Vladimir Oltean <vladimir.oltean@nxp.com>
Sent: Friday, October 4, 2024 4:00 AM
To: netdev@vger.kernel.org
Cc: David S. Miller <davem@davemloft.net>; Eric Dumazet
[off-list ref]; Jakub Kicinski [off-list ref]; Paolo Abeni
[off-list ref]; Keller, Jacob E [off-list ref]; Kitszel,
Przemyslaw [off-list ref]; linux-kernel@vger.kernel.org
Subject: [PATCH net-next] lib: packing: catch kunit_kzalloc() failure in the pack()
test

kunit_kzalloc() may fail. Other call sites verify that this is the case,
either using a direct comparison with the NULL pointer, or the
KUNIT_ASSERT_NOT_NULL() or KUNIT_ASSERT_NOT_ERR_OR_NULL().

Pick KUNIT_ASSERT_NOT_NULL() as the error handling method that made most
sense to me. It's an unlikely thing to happen, but at least we call
__kunit_abort() instead of dereferencing this NULL pointer.

Fixes: e9502ea6db8a ("lib: packing: add KUnit tests adapted from selftests")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
  lib/packing_test.c | 1 +
  1 file changed, 1 insertion(+)
diff --git a/lib/packing_test.c b/lib/packing_test.c
index 015ad1180d23..b38ea43c03fd 100644
--- a/lib/packing_test.c
+++ b/lib/packing_test.c
@@ -375,6 +375,7 @@ static void packing_test_pack(struct kunit *test)
  	int err;

  	pbuf = kunit_kzalloc(test, params->pbuf_size, GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, pbuf);

  	err = pack(pbuf, params->uval, params->start_bit, params->end_bit,
  		   params->pbuf_size, params->quirks);
--
2.43.0
Oh good catch! I guess I had assumed that kunit_kzalloc would itself detect and
fail instead of continuing....

that would be great

kunit_*alloc gives kunit-managed resources though
Yep, just a misunderstanding on my part 😊
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help