mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH V1] accel/amdxdna: Prevent ubuf size overflow
@ 2026-02-17 19:28 Lizhi Hou
  2026-02-17 19:54 ` Mario Limonciello
  0 siblings, 1 reply; 2+ messages in thread
From: Lizhi Hou @ 2026-02-17 19:28 UTC (permalink / raw)
  To: ogabbay, quic_jhugo, dri-devel, maciej.falkowski
  Cc: Lizhi Hou, linux-kernel, max.zhen, sonal.santan, mario.limonciello

The ubuf size calculation may overflow, resulting in an undersized
allocation and possible memory corruption.

Use check_add_overflow() helpers to validate the size calculation before
allocation.

Fixes: bd72d4acda10 ("accel/amdxdna: Support user space allocated buffer")
Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
---
 drivers/accel/amdxdna/amdxdna_ubuf.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/accel/amdxdna/amdxdna_ubuf.c b/drivers/accel/amdxdna/amdxdna_ubuf.c
index 9e3b3b055caa..62a478f6b45f 100644
--- a/drivers/accel/amdxdna/amdxdna_ubuf.c
+++ b/drivers/accel/amdxdna/amdxdna_ubuf.c
@@ -7,6 +7,7 @@
 #include <drm/drm_device.h>
 #include <drm/drm_print.h>
 #include <linux/dma-buf.h>
+#include <linux/overflow.h>
 #include <linux/pagemap.h>
 #include <linux/vmalloc.h>
 
@@ -176,7 +177,10 @@ struct dma_buf *amdxdna_get_ubuf(struct drm_device *dev,
 			goto free_ent;
 		}
 
-		exp_info.size += va_ent[i].len;
+		if (check_add_overflow(exp_info.size, va_ent[i].len, &exp_info.size)) {
+			ret = -EINVAL;
+			goto free_ent;
+		}
 	}
 
 	ubuf->nr_pages = exp_info.size >> PAGE_SHIFT;
-- 
2.34.1


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

* Re: [PATCH V1] accel/amdxdna: Prevent ubuf size overflow
  2026-02-17 19:28 [PATCH V1] accel/amdxdna: Prevent ubuf size overflow Lizhi Hou
@ 2026-02-17 19:54 ` Mario Limonciello
  0 siblings, 0 replies; 2+ messages in thread
From: Mario Limonciello @ 2026-02-17 19:54 UTC (permalink / raw)
  To: Lizhi Hou, ogabbay, quic_jhugo, dri-devel, maciej.falkowski
  Cc: linux-kernel, max.zhen, sonal.santan

On 2/17/26 1:28 PM, Lizhi Hou wrote:
> The ubuf size calculation may overflow, resulting in an undersized
> allocation and possible memory corruption.
> 
> Use check_add_overflow() helpers to validate the size calculation before
> allocation.
> 
> Fixes: bd72d4acda10 ("accel/amdxdna: Support user space allocated buffer")
> Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>
> ---
>   drivers/accel/amdxdna/amdxdna_ubuf.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/accel/amdxdna/amdxdna_ubuf.c b/drivers/accel/amdxdna/amdxdna_ubuf.c
> index 9e3b3b055caa..62a478f6b45f 100644
> --- a/drivers/accel/amdxdna/amdxdna_ubuf.c
> +++ b/drivers/accel/amdxdna/amdxdna_ubuf.c
> @@ -7,6 +7,7 @@
>   #include <drm/drm_device.h>
>   #include <drm/drm_print.h>
>   #include <linux/dma-buf.h>
> +#include <linux/overflow.h>
>   #include <linux/pagemap.h>
>   #include <linux/vmalloc.h>
>   
> @@ -176,7 +177,10 @@ struct dma_buf *amdxdna_get_ubuf(struct drm_device *dev,
>   			goto free_ent;
>   		}
>   
> -		exp_info.size += va_ent[i].len;
> +		if (check_add_overflow(exp_info.size, va_ent[i].len, &exp_info.size)) {
> +			ret = -EINVAL;
> +			goto free_ent;
> +		}
>   	}
>   
>   	ubuf->nr_pages = exp_info.size >> PAGE_SHIFT;


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

end of thread, other threads:[~2026-02-17 19:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-17 19:28 [PATCH V1] accel/amdxdna: Prevent ubuf size overflow Lizhi Hou
2026-02-17 19:54 ` Mario Limonciello

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®