From b273bbed7139ad9c5e56aa51fe254d229cca9863 Mon Sep 17 00:00:00 2001 From: Zichen Xie Date: Wed, 12 Mar 2025 22:51:00 +0900 Subject: [PATCH] kunit: Fix potential null dereference in kunit_device_driver_test() BugLink: https://bugs.launchpad.net/bugs/2102118 commit 435c20eed572a95709b1536ff78832836b2f91b1 upstream. kunit_kzalloc() may return a NULL pointer, dereferencing it without NULL check may lead to NULL dereference. Add a NULL check for test_state. Link: https://lore.kernel.org/r/20241115054335.21673-1-zichenxie0106@gmail.com Fixes: d03c720e03bd ("kunit: Add APIs for managing devices") Signed-off-by: Zichen Xie Cc: stable@vger.kernel.org Reviewed-by: David Gow Signed-off-by: Shuah Khan Signed-off-by: Greg Kroah-Hartman CVE-2024-56773 Signed-off-by: Koichiro Den Signed-off-by: Stefan Bader --- 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 f7980ef236a3..73e86733e68d 100644 --- a/lib/kunit/kunit-test.c +++ b/lib/kunit/kunit-test.c @@ -763,6 +763,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");