* [PATCH] lib: kunit_iov_iter: fix NULL deref in iov_kunit_create_xarray()
@ 2025-09-18 7:13 Jackie Liu
0 siblings, 0 replies; only message in thread
From: Jackie Liu @ 2025-09-18 7:13 UTC (permalink / raw)
To: kees; +Cc: pmladek, linux-kernel, liu.yun
From: Jackie Liu <liuyun01@kylinos.cn>
iov_kunit_create_xarray() allocates memory for an xarray using kzalloc()
and then calls xa_init() on the result. However, xa_init() was invoked
before checking the return value of kzalloc(). If kzalloc() fails, this
would lead to a NULL pointer dereference.
Move the KUNIT_ASSERT_NOT_ERR_OR_NULL() check before xa_init() to ensure
the pointer is valid before initialization.
Fixes: 2d71340ff1d4 ("iov_iter: Kunit tests for copying to/from an iterator")
Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
---
lib/tests/kunit_iov_iter.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/tests/kunit_iov_iter.c b/lib/tests/kunit_iov_iter.c
index 48342736d016..a9d6db89247d 100644
--- a/lib/tests/kunit_iov_iter.c
+++ b/lib/tests/kunit_iov_iter.c
@@ -566,8 +566,8 @@ static struct xarray *iov_kunit_create_xarray(struct kunit *test)
struct xarray *xarray;
xarray = kzalloc(sizeof(struct xarray), GFP_KERNEL);
- xa_init(xarray);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xarray);
+ xa_init(xarray);
kunit_add_action_or_reset(test, iov_kunit_destroy_xarray, xarray);
return xarray;
}
--
2.51.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2025-09-18 7:14 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-18 7:13 [PATCH] lib: kunit_iov_iter: fix NULL deref in iov_kunit_create_xarray() Jackie Liu
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.