]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
vmalloc: fix buffer overflow in vrealloc_node_align()
authorMarco Elver <elver@google.com>
Mon, 20 Apr 2026 11:47:26 +0000 (13:47 +0200)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 27 Apr 2026 12:54:23 +0000 (05:54 -0700)
commit82d1f01292d3f09bf063f829f8ab8de12b4280a1
tree583dc8103fa1a24b53b7a05f1404e4911da4e1c2
parent254f49634ee16a731174d2ae34bc50bd5f45e731
vmalloc: fix buffer overflow in vrealloc_node_align()

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.

Link: https://lore.kernel.org/20260420114805.3572606-2-elver@google.com
Fixes: 4c5d3365882d ("mm/vmalloc: allow to set node and align in vrealloc")
Signed-off-by: Marco Elver <elver@google.com>
Reported-by: Harry Yoo (Oracle) <harry@kernel.org>
Reviewed-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
Acked-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
Reviewed-by: Harry Yoo (Oracle) <harry@kernel.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/vmalloc.c