From: Gax-c <zichenxie0106@gmail.com>
To: brendan.higgins@linux.dev, davidgow@google.com, rmoar@google.com,
mripard@kernel.org, skhan@linuxfoundation.org,
mazziesaccount@gmail.com, gregkh@linuxfoundation.org
Cc: linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com,
chenyuan0y@gmail.com, zzjas98@gmail.com,
Zichen Xie <zichenxie0106@gmail.com>
Subject: [PATCH] kunit: Fix potential null dereference in kunit_device_driver_test()
Date: Thu, 14 Nov 2024 23:17:46 -0600 [thread overview]
Message-ID: <20241115051745.14404-1-zichenxie0106@gmail.com> (raw)
From: Zichen Xie <zichenxie0106@gmail.com>
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@gmail.com>
---
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
next reply other threads:[~2024-11-15 5:18 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-15 5:17 Gax-c [this message]
2024-11-15 5:35 ` [PATCH] kunit: Fix potential null dereference in kunit_device_driver_test() Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241115051745.14404-1-zichenxie0106@gmail.com \
--to=zichenxie0106@gmail.com \
--cc=brendan.higgins@linux.dev \
--cc=chenyuan0y@gmail.com \
--cc=davidgow@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=kunit-dev@googlegroups.com \
--cc=linux-kselftest@vger.kernel.org \
--cc=mazziesaccount@gmail.com \
--cc=mripard@kernel.org \
--cc=rmoar@google.com \
--cc=skhan@linuxfoundation.org \
--cc=zzjas98@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox