Marco Elver
unread,Apr 20, 2026, 7:49:17 AM (10 days ago) Apr 20Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to el...@google.com, Vlastimil Babka, Andrew Morton, Uladzislau Rezki, linu...@kvack.org, linux-...@vger.kernel.org, kasa...@googlegroups.com, Vitaly Wool, sta...@vger.kernel.org, Harry Yoo (Oracle)
Commit 4c5d3365882d ("mm/vmalloc: allow to set node and align in
vrealloc") added the ability to force a new allocation if the current
pointer is on the wrong NUMA node, or if an alignment constraint is not
met, even if the user is shrinking the allocation.
On this path (need_realloc), the code allocates a new object of 'size'
bytes and then memcpy()s 'old_size' bytes into it. If the request is to
shrink the object (size < old_size), this results in an out-of-bounds
write on the new buffer.
Fix this by bounding the copy length by the new allocation size.
Fixes: 4c5d3365882d ("mm/vmalloc: allow to set node and align in vrealloc")
Cc: <
sta...@vger.kernel.org>
Reported-by: Harry Yoo (Oracle) <
ha...@kernel.org>
Signed-off-by: Marco Elver <
el...@google.com>
---
mm/vmalloc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 61caa55a4402..8b1124158f54 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -4361,7 +4361,7 @@ void *vrealloc_node_align_noprof(const void *p, size_t size, unsigned long align
return NULL;
if (p) {
- memcpy(n, p, old_size);
+ memcpy(n, p, min(size, old_size));
vfree(p);
}
--
2.54.0.rc1.513.gad8abe7a5a-goog