Re: [PATCH v2] kunit: Fix potential null dereference in kunit_device_driver_test()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 15 Nov 2024 at 13:43, Gax-c <zichenxie0106@xxxxxxxxx> wrote:
>
> From: Zichen Xie <zichenxie0106@xxxxxxxxx>
>
> kunit_kzalloc() may return a NULL pointer, dereferencing it without
> NULL check may lead to NULL dereference.
> Add a NULL check for test_state.
>
> Fixes: d03c720e03bd ("kunit: Add APIs for managing devices")
> Signed-off-by: Zichen Xie <zichenxie0106@xxxxxxxxx>
> Cc: stable@xxxxxxxxxxxxxxx
> ---
> v2: Add Cc tag.
> ---

Nice catch. This looks good to me.

Reviewed-by: David Gow <davidgow@xxxxxxxxxx>

Cheers,
-- David

>  lib/kunit/kunit-test.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/lib/kunit/kunit-test.c b/lib/kunit/kunit-test.c
> index 37e02be1e710..d9c781c859fd 100644
> --- a/lib/kunit/kunit-test.c
> +++ b/lib/kunit/kunit-test.c
> @@ -805,6 +805,8 @@ static void kunit_device_driver_test(struct kunit *test)
>         struct device *test_device;
>         struct driver_test_state *test_state = kunit_kzalloc(test, sizeof(*test_state), GFP_KERNEL);
>
> +       KUNIT_ASSERT_NOT_ERR_OR_NULL(test, test_state);
> +
>         test->priv = test_state;
>         test_driver = kunit_driver_create(test, "my_driver");
>
> --
> 2.34.1
>

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux