mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] selftests: i915: Use struct_size() helper in kmalloc()
@ 2025-02-08  1:35 l1138897701
  2025-02-10 17:08 ` Andi Shyti
  2025-02-11  0:12 ` Andi Shyti
  0 siblings, 2 replies; 3+ messages in thread
From: l1138897701 @ 2025-02-08  1:35 UTC (permalink / raw)
  To: jani.nikula; +Cc: luoqing, linux-kernel

From: luoqing <luoqing@kylinos.cn>

Make use of the struct_size() helper instead of an open-coded version,
in order to avoid any potential type mistakes or integer overflows that,
in the worst scenario, could lead to heap overflows.

Signed-off-by: luoqing <luoqing@kylinos.cn>
---
 drivers/gpu/drm/i915/gem/selftests/mock_dmabuf.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/i915/gem/selftests/mock_dmabuf.c b/drivers/gpu/drm/i915/gem/selftests/mock_dmabuf.c
index 075657018739..5cd58e0f0dcf 100644
--- a/drivers/gpu/drm/i915/gem/selftests/mock_dmabuf.c
+++ b/drivers/gpu/drm/i915/gem/selftests/mock_dmabuf.c
@@ -103,8 +103,7 @@ static struct dma_buf *mock_dmabuf(int npages)
 	struct dma_buf *dmabuf;
 	int i;
 
-	mock = kmalloc(sizeof(*mock) + npages * sizeof(struct page *),
-		       GFP_KERNEL);
+	mock = kmalloc(struct_size(mock, pages, npages), GFP_KERNEL);
 	if (!mock)
 		return ERR_PTR(-ENOMEM);
 
-- 
2.27.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] selftests: i915: Use struct_size() helper in kmalloc()
  2025-02-08  1:35 [PATCH] selftests: i915: Use struct_size() helper in kmalloc() l1138897701
@ 2025-02-10 17:08 ` Andi Shyti
  2025-02-11  0:12 ` Andi Shyti
  1 sibling, 0 replies; 3+ messages in thread
From: Andi Shyti @ 2025-02-10 17:08 UTC (permalink / raw)
  To: l1138897701; +Cc: jani.nikula, luoqing, linux-kernel

Hi luoqing,

On Sat, Feb 08, 2025 at 09:35:39AM +0800, l1138897701@163.com wrote:
> From: luoqing <luoqing@kylinos.cn>
> 
> Make use of the struct_size() helper instead of an open-coded version,
> in order to avoid any potential type mistakes or integer overflows that,
> in the worst scenario, could lead to heap overflows.
> 
> Signed-off-by: luoqing <luoqing@kylinos.cn>

Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com>

Thanks,
Andi

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] selftests: i915: Use struct_size() helper in kmalloc()
  2025-02-08  1:35 [PATCH] selftests: i915: Use struct_size() helper in kmalloc() l1138897701
  2025-02-10 17:08 ` Andi Shyti
@ 2025-02-11  0:12 ` Andi Shyti
  1 sibling, 0 replies; 3+ messages in thread
From: Andi Shyti @ 2025-02-11  0:12 UTC (permalink / raw)
  To: l1138897701; +Cc: jani.nikula, luoqing, linux-kernel

Hi,

On Sat, Feb 08, 2025 at 09:35:39AM +0800, l1138897701@163.com wrote:
> From: luoqing <luoqing@kylinos.cn>
> 
> Make use of the struct_size() helper instead of an open-coded version,
> in order to avoid any potential type mistakes or integer overflows that,
> in the worst scenario, could lead to heap overflows.
> 
> Signed-off-by: luoqing <luoqing@kylinos.cn>

merged to drm-intel-gt-next.

Thanks,
Andi

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-02-11  0:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-08  1:35 [PATCH] selftests: i915: Use struct_size() helper in kmalloc() l1138897701
2025-02-10 17:08 ` Andi Shyti
2025-02-11  0:12 ` Andi Shyti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®