mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net-next] lib: packing: catch kunit_kzalloc() failure in the pack() test
@ 2024-10-04 11:00 Vladimir Oltean
  2024-10-04 19:20 ` Keller, Jacob E
  2024-10-07 23:40 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 5+ messages in thread
From: Vladimir Oltean @ 2024-10-04 11:00 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Jacob Keller, Przemek Kitszel, linux-kernel

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


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

* RE: [PATCH net-next] lib: packing: catch kunit_kzalloc() failure in the pack() test
  2024-10-04 11:00 [PATCH net-next] lib: packing: catch kunit_kzalloc() failure in the pack() test Vladimir Oltean
@ 2024-10-04 19:20 ` Keller, Jacob E
  2024-10-09 10:21   ` Przemek Kitszel
  2024-10-07 23:40 ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 5+ messages in thread
From: Keller, Jacob E @ 2024-10-04 19:20 UTC (permalink / raw)
  To: Vladimir Oltean, netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Kitszel, Przemyslaw, linux-kernel



> -----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
> <edumazet@google.com>; Jakub Kicinski <kuba@kernel.org>; Paolo Abeni
> <pabeni@redhat.com>; Keller, Jacob E <jacob.e.keller@intel.com>; Kitszel,
> Przemyslaw <przemyslaw.kitszel@intel.com>; 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....


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

* Re: [PATCH net-next] lib: packing: catch kunit_kzalloc() failure in the pack() test
  2024-10-04 11:00 [PATCH net-next] lib: packing: catch kunit_kzalloc() failure in the pack() test Vladimir Oltean
  2024-10-04 19:20 ` Keller, Jacob E
@ 2024-10-07 23:40 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-10-07 23:40 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: netdev, davem, edumazet, kuba, pabeni, jacob.e.keller,
	przemyslaw.kitszel, linux-kernel

Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

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



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

* Re: [PATCH net-next] lib: packing: catch kunit_kzalloc() failure in the pack() test
  2024-10-04 19:20 ` Keller, Jacob E
@ 2024-10-09 10:21   ` Przemek Kitszel
  2024-10-09 20:52     ` Keller, Jacob E
  0 siblings, 1 reply; 5+ messages in thread
From: Przemek Kitszel @ 2024-10-09 10:21 UTC (permalink / raw)
  To: Keller, Jacob E, Vladimir Oltean
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	linux-kernel, netdev

On 10/4/24 21:20, Keller, Jacob E wrote:
> 
> 
>> -----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
>> <edumazet@google.com>; Jakub Kicinski <kuba@kernel.org>; Paolo Abeni
>> <pabeni@redhat.com>; Keller, Jacob E <jacob.e.keller@intel.com>; Kitszel,
>> Przemyslaw <przemyslaw.kitszel@intel.com>; 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

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

* RE: [PATCH net-next] lib: packing: catch kunit_kzalloc() failure in the pack() test
  2024-10-09 10:21   ` Przemek Kitszel
@ 2024-10-09 20:52     ` Keller, Jacob E
  0 siblings, 0 replies; 5+ messages in thread
From: Keller, Jacob E @ 2024-10-09 20:52 UTC (permalink / raw)
  To: Kitszel, Przemyslaw, Vladimir Oltean
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	linux-kernel, netdev



> -----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
> <vladimir.oltean@nxp.com>
> Cc: David S. Miller <davem@davemloft.net>; Eric Dumazet
> <edumazet@google.com>; Jakub Kicinski <kuba@kernel.org>; Paolo Abeni
> <pabeni@redhat.com>; 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:
> >
> >
> >> -----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
> >> <edumazet@google.com>; Jakub Kicinski <kuba@kernel.org>; Paolo Abeni
> >> <pabeni@redhat.com>; Keller, Jacob E <jacob.e.keller@intel.com>; Kitszel,
> >> Przemyslaw <przemyslaw.kitszel@intel.com>; 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 😊

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

end of thread, other threads:[~2024-10-09 20:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-04 11:00 [PATCH net-next] lib: packing: catch kunit_kzalloc() failure in the pack() test Vladimir Oltean
2024-10-04 19:20 ` Keller, Jacob E
2024-10-09 10:21   ` Przemek Kitszel
2024-10-09 20:52     ` Keller, Jacob E
2024-10-07 23:40 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®