Skip to content

Commit 6ebf198

Browse files
qasim-ijazXu Yilun
authored andcommitted
fpga: fix potential null pointer deref in fpga_mgr_test_img_load_sgt()
fpga_mgr_test_img_load_sgt() allocates memory for sgt using kunit_kzalloc() however it does not check if the allocation failed. It then passes sgt to sg_alloc_table(), which passes it to __sg_alloc_table(). This function calls memset() on sgt in an attempt to zero it out. If the allocation fails then sgt will be NULL and the memset will trigger a NULL pointer dereference. Fix this by checking the allocation with KUNIT_ASSERT_NOT_ERR_OR_NULL(). Reviewed-by: Marco Pagani <marco.pagani@linux.dev> Fixes: ccbc1c3 ("fpga: add an initial KUnit suite for the FPGA Manager") Signed-off-by: Qasim Ijaz <qasdev00@gmail.com> Acked-by: Xu Yilun <yilun.xu@intel.com> Link: https://lore.kernel.org/r/20250422153737.5264-1-qasdev00@gmail.com Signed-off-by: Xu Yilun <yilun.xu@linux.intel.com>
1 parent 99b1185 commit 6ebf198

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

drivers/fpga/tests/fpga-mgr-test.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ static void fpga_mgr_test_img_load_sgt(struct kunit *test)
263263
img_buf = init_test_buffer(test, IMAGE_SIZE);
264264

265265
sgt = kunit_kzalloc(test, sizeof(*sgt), GFP_KERNEL);
266+
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, sgt);
266267
ret = sg_alloc_table(sgt, 1, GFP_KERNEL);
267268
KUNIT_ASSERT_EQ(test, ret, 0);
268269
sg_init_one(sgt->sgl, img_buf, IMAGE_SIZE);

0 commit comments

Comments
 (0)