linux/drivers/fpga/tests
Qasim Ijaz 8b2230ac7f fpga: fix potential null pointer deref in fpga_mgr_test_img_load_sgt()
[ Upstream commit 6ebf198203 ]

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: ccbc1c3021 ("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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
History 2025-06-19 15:32:13 +02:00
..
.kunitconfig fpga: add configuration for the FPGA KUnit test suites. 2023-07-23 14:04:50 +08:00
fpga-bridge-test.c fpga: Simplify and improve fpga bridge test using deferred actions 2024-08-14 23:51:03 +08:00
fpga-mgr-test.c fpga: fix potential null pointer deref in fpga_mgr_test_img_load_sgt() 2025-06-19 15:32:13 +02:00
fpga-region-test.c fpga: Simplify and improve fpga region test using deferred actions 2024-08-14 23:51:04 +08:00
Kconfig Revert "fpga: disable KUnit test suites when module support is enabled" 2024-06-11 17:56:12 +08:00
Makefile fpga: add configuration for the FPGA KUnit test suites. 2023-07-23 14:04:50 +08:00