* [PATCH] fpga: fix potential null pointer deref in fpga_mgr_test_img_load_sgt()
@ 2025-03-11 23:45 Qasim Ijaz
2025-03-12 13:01 ` Markus Elfring
2025-03-16 22:00 ` Marco Pagani
0 siblings, 2 replies; 4+ messages in thread
From: Qasim Ijaz @ 2025-03-11 23:45 UTC (permalink / raw)
To: mdf, hao.wu, yilun.xu, trix, marpagan, russ.weight
Cc: linux-fpga, linux-kernel, stable
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().
Fixes: ccbc1c302115 ("fpga: add an initial KUnit suite for the FPGA Manager")
Cc: stable@vger.kernel.org
Signed-off-by: Qasim Ijaz <qasdev00@gmail.com>
---
drivers/fpga/tests/fpga-mgr-test.c | 1 +
1 file changed, 1 insertion(+)
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);
--
2.39.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] fpga: fix potential null pointer deref in fpga_mgr_test_img_load_sgt()
2025-03-11 23:45 [PATCH] fpga: fix potential null pointer deref in fpga_mgr_test_img_load_sgt() Qasim Ijaz
@ 2025-03-12 13:01 ` Markus Elfring
2025-03-12 15:07 ` Greg KH
2025-03-16 22:00 ` Marco Pagani
1 sibling, 1 reply; 4+ messages in thread
From: Markus Elfring @ 2025-03-12 13:01 UTC (permalink / raw)
To: Qasim Ijaz, linux-fpga
Cc: stable, LKML, Marco Pagani, Moritz Fischer, Russ Weight, Tom Rix,
Wu Hao, Xu Yilun
…
> zero it out. If the allocation fails then sgt will be NULL and the
…
failed?
Can a summary phrase like “Prevent null pointer dereference
in fpga_mgr_test_img_load_sgt()” be nicer?
Regards,
Markus
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] fpga: fix potential null pointer deref in fpga_mgr_test_img_load_sgt()
2025-03-12 13:01 ` Markus Elfring
@ 2025-03-12 15:07 ` Greg KH
0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2025-03-12 15:07 UTC (permalink / raw)
To: Markus Elfring
Cc: Qasim Ijaz, linux-fpga, stable, LKML, Marco Pagani,
Moritz Fischer, Russ Weight, Tom Rix, Wu Hao, Xu Yilun
On Wed, Mar 12, 2025 at 02:01:48PM +0100, Markus Elfring wrote:
> …
> > zero it out. If the allocation fails then sgt will be NULL and the
> …
> failed?
>
>
> Can a summary phrase like “Prevent null pointer dereference
> in fpga_mgr_test_img_load_sgt()” be nicer?
>
> Regards,
> Markus
>
Hi,
This is the semi-friendly patch-bot of Greg Kroah-Hartman.
Markus, you seem to have sent a nonsensical or otherwise pointless
review comment to a patch submission on a Linux kernel developer mailing
list. I strongly suggest that you not do this anymore. Please do not
bother developers who are actively working to produce patches and
features with comments that, in the end, are a waste of time.
Patch submitter, please ignore Markus's suggestion; you do not need to
follow it at all. The person/bot/AI that sent it is being ignored by
almost all Linux kernel maintainers for having a persistent pattern of
behavior of producing distracting and pointless commentary, and
inability to adapt to feedback. Please feel free to also ignore emails
from them.
thanks,
greg k-h's patch email bot
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] fpga: fix potential null pointer deref in fpga_mgr_test_img_load_sgt()
2025-03-11 23:45 [PATCH] fpga: fix potential null pointer deref in fpga_mgr_test_img_load_sgt() Qasim Ijaz
2025-03-12 13:01 ` Markus Elfring
@ 2025-03-16 22:00 ` Marco Pagani
1 sibling, 0 replies; 4+ messages in thread
From: Marco Pagani @ 2025-03-16 22:00 UTC (permalink / raw)
To: Qasim Ijaz, mdf, hao.wu, yilun.xu, trix, marpagan, russ.weight
Cc: linux-fpga, linux-kernel, stable
On 2025-03-12 00:45, Qasim Ijaz wrote:
> 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().
>
> Fixes: ccbc1c302115 ("fpga: add an initial KUnit suite for the FPGA Manager")
> Cc: stable@vger.kernel.org
> Signed-off-by: Qasim Ijaz <qasdev00@gmail.com>
Reviewed-by: Marco Pagani <marco.pagani@linux.dev>
> ---
> drivers/fpga/tests/fpga-mgr-test.c | 1 +
> 1 file changed, 1 insertion(+)
>
> 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);
Thanks,
Marco
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-03-16 22:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-11 23:45 [PATCH] fpga: fix potential null pointer deref in fpga_mgr_test_img_load_sgt() Qasim Ijaz
2025-03-12 13:01 ` Markus Elfring
2025-03-12 15:07 ` Greg KH
2025-03-16 22:00 ` Marco Pagani
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).