diff options
| author | Qasim Ijaz <[email protected]> | 2025-04-22 15:37:37 +0000 |
|---|---|---|
| committer | Xu Yilun <[email protected]> | 2025-05-05 16:37:00 +0000 |
| commit | 6ebf1982038af12f3588417e4fd0417d2551da28 (patch) | |
| tree | 7cc8b61606368f572f08ca22da363f2e20ae34be /drivers/fpga/tests | |
| parent | fpga: m10bmc-sec: change contact for secure update driver (diff) | |
| download | kernel-6ebf1982038af12f3588417e4fd0417d2551da28.tar.gz kernel-6ebf1982038af12f3588417e4fd0417d2551da28.zip | |
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 <[email protected]>
Fixes: ccbc1c302115 ("fpga: add an initial KUnit suite for the FPGA Manager")
Signed-off-by: Qasim Ijaz <[email protected]>
Acked-by: Xu Yilun <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Xu Yilun <[email protected]>
Diffstat (limited to 'drivers/fpga/tests')
| -rw-r--r-- | drivers/fpga/tests/fpga-mgr-test.c | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/drivers/fpga/tests/fpga-mgr-test.c b/drivers/fpga/tests/fpga-mgr-test.c index 9cb37aefbac4..1902ebf5a298 100644 --- a/drivers/fpga/tests/fpga-mgr-test.c +++ b/drivers/fpga/tests/fpga-mgr-test.c @@ -263,6 +263,7 @@ static void fpga_mgr_test_img_load_sgt(struct kunit *test) img_buf = init_test_buffer(test, IMAGE_SIZE); sgt = kunit_kzalloc(test, sizeof(*sgt), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, sgt); ret = sg_alloc_table(sgt, 1, GFP_KERNEL); KUNIT_ASSERT_EQ(test, ret, 0); sg_init_one(sgt->sgl, img_buf, IMAGE_SIZE); |
