Skip to contentSkip to conversation

lib: packing: catch kunit_kzalloc() failure in the pack() test

PATCH Applied Vladimir Oltean 4 participants 5 messages Oct 4, 2024 – Oct 9, 2024

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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")
---
 lib/packing_test.c | 1 +
 1 file changed, 1 insertion(+)
lib/packing_test.c +1 -0
index 015ad1180d23..b38ea43c03fd 100644
@@ -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);
Signature · 1 line
2.43.0
#1 lore raw
Quoted 40 lines

-----Original Message-----
From: Vladimir Oltean <[email protected]>
Sent: Friday, October 4, 2024 4:00 AM
To: [email protected]
Cc: David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Keller, Jacob E <[email protected]>; Kitszel, Przemyslaw <[email protected]>; [email protected]
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")
---
 lib/packing_test.c | 1 +
 1 file changed, 1 insertion(+)
lib/packing_test.c +1 -1
index 015ad1180d23..b38ea43c03fd 100644
@@ -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);
--
Quoted 1 line

2.43.0

Oh good catch! I guess I had assumed that kunit_kzalloc would itself detect and fail instead of continuing....

#2 lore raw
Quoted 37 lines · Jacob E
Quoted 37 lines

-----Original Message-----
From: Vladimir Oltean <[email protected]>
Sent: Friday, October 4, 2024 4:00 AM
To: [email protected]
Cc: David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Keller, Jacob E <[email protected]>; Kitszel, Przemyslaw <[email protected]>; [email protected]
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")
---
  lib/packing_test.c | 1 +
  1 file changed, 1 insertion(+)
lib/packing_test.c +1 -0
index 015ad1180d23..b38ea43c03fd 100644
@@ -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);
 
Quoted 6 lines
Quoted 4 lines
lib/packing_test.c +0 -1
  	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

#3 lore raw
Quoted 57 lines

-----Original Message-----
From: Kitszel, Przemyslaw <[email protected]>
Sent: Wednesday, October 9, 2024 3:21 AM
To: Keller, Jacob E <[email protected]>; Vladimir Oltean <[email protected]>
Cc: David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH net-next] lib: packing: catch kunit_kzalloc() failure in the pack() test

Quoted 37 lines · Jacob E
Quoted 37 lines

-----Original Message-----
From: Vladimir Oltean <[email protected]>
Sent: Friday, October 4, 2024 4:00 AM
To: [email protected]
Cc: David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Keller, Jacob E <[email protected]>; Kitszel, Przemyslaw <[email protected]>; [email protected]
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")
---
  lib/packing_test.c | 1 +
  1 file changed, 1 insertion(+)
lib/packing_test.c +1 -0
index 015ad1180d23..b38ea43c03fd 100644
@@ -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);
 
Quoted 6 lines
Quoted 4 lines
lib/packing_test.c +0 -1
  	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

Quoted 5 lines

fail instead of continuing....

that would be great

kunit_*alloc gives kunit-managed resources though

Yep, just a misunderstanding on my part 😊

#4 lore raw
In reply to Vladimir Oltean
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 9 lines · 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!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html