linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm: amdgpu: Use the correct size when allocating memory
@ 2020-08-09 20:34 Christophe JAILLET
  2020-08-10  9:36 ` Christian König
  2020-08-10 15:42 ` Dan Carpenter
  0 siblings, 2 replies; 7+ messages in thread
From: Christophe JAILLET @ 2020-08-09 20:34 UTC (permalink / raw)
  To: alexander.deucher, christian.koenig, airlied, daniel,
	sumit.semwal, colton.w.lewis, Ori.Messinger, m.szyprowski,
	bernard, dri-devel
  Cc: amd-gfx, linux-kernel, kernel-janitors, Christophe JAILLET

When '*sgt' is allocated, we must allocated 'sizeof(**sgt)' bytes instead
of 'sizeof(*sg)'. 'sg' (i.e. struct scatterlist) is smaller than
'sgt' (i.e struct sg_table), so this could lead to memory corruption.

Fixes: f44ffd677fb3 ("drm/amdgpu: add support for exporting VRAM using DMA-buf v3")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
index 134cc36e30c5..0739e259bf91 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
@@ -462,7 +462,7 @@ int amdgpu_vram_mgr_alloc_sgt(struct amdgpu_device *adev,
 	unsigned int pages;
 	int i, r;
 
-	*sgt = kmalloc(sizeof(*sg), GFP_KERNEL);
+	*sgt = kmalloc(sizeof(**sgt), GFP_KERNEL);
 	if (!*sgt)
 		return -ENOMEM;
 
-- 
2.25.1


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

end of thread, other threads:[~2020-08-11  8:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-09 20:34 [PATCH] drm: amdgpu: Use the correct size when allocating memory Christophe JAILLET
2020-08-10  9:36 ` Christian König
2020-08-10 15:42 ` Dan Carpenter
2020-08-10 18:41   ` Marion & Christophe JAILLET
2020-08-10 21:15     ` Alex Deucher
2020-08-11  7:57     ` Dan Carpenter
2020-08-11  8:00       ` Dan Carpenter

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).