lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20250918071316.1035-1-liu.yun@linux.dev>
Date: Thu, 18 Sep 2025 15:13:16 +0800
From: Jackie Liu <liu.yun@...ux.dev>
To: kees@...nel.org
Cc: pmladek@...e.com,
	linux-kernel@...r.kernel.org,
	liu.yun@...ux.dev
Subject: [PATCH] lib: kunit_iov_iter: fix NULL deref in iov_kunit_create_xarray()

From: Jackie Liu <liuyun01@...inos.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@...inos.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


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ