Skip to content

Commit 03808ab

Browse files
committed
accel/amdxdna: Prevent ubuf size overflow
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: bd72d4a ("accel/amdxdna: Support user space allocated buffer") Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org> Signed-off-by: Lizhi Hou <lizhi.hou@amd.com> Link: https://patch.msgid.link/20260217192815.1784689-1-lizhi.hou@amd.com
1 parent 1110a94 commit 03808ab

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

drivers/accel/amdxdna/amdxdna_ubuf.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <drm/drm_device.h>
88
#include <drm/drm_print.h>
99
#include <linux/dma-buf.h>
10+
#include <linux/overflow.h>
1011
#include <linux/pagemap.h>
1112
#include <linux/vmalloc.h>
1213

@@ -176,7 +177,10 @@ struct dma_buf *amdxdna_get_ubuf(struct drm_device *dev,
176177
goto free_ent;
177178
}
178179

179-
exp_info.size += va_ent[i].len;
180+
if (check_add_overflow(exp_info.size, va_ent[i].len, &exp_info.size)) {
181+
ret = -EINVAL;
182+
goto free_ent;
183+
}
180184
}
181185

182186
ubuf->nr_pages = exp_info.size >> PAGE_SHIFT;

0 commit comments

Comments
 (0)