aboutsummaryrefslogtreecommitdiff
path: root/sys/kern/kern_malloc.c
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2021-05-05 21:05:46 +0000
committerMark Johnston <markj@FreeBSD.org>2021-11-01 14:05:22 +0000
commit28c338b3426330b5c9668651e4e91b2dfafde6cf (patch)
treecfb0297eadcde13551cb38aca7b476ee193da3e9 /sys/kern/kern_malloc.c
parent9710b74dd0f46c58a603c0bee7fad7f5bc71a80f (diff)
downloadsrc-28c338b3426330b5c9668651e4e91b2dfafde6cf.tar.gz
src-28c338b3426330b5c9668651e4e91b2dfafde6cf.zip
realloc: Fix KASAN(9) shadow map updates
When copying from the old buffer to the new buffer, we don't know the requested size of the old allocation, but only the size of the allocation provided by UMA. This value is "alloc". Because the copy may access bytes in the old allocation's red zone, we must mark the full allocation valid in the shadow map. Do so using the correct size. Reported by: kp Tested by: kp Sponsored by: The FreeBSD Foundation (cherry picked from commit 9a7c2de36460cdb916734a6969aac666707a639b)
Diffstat (limited to 'sys/kern/kern_malloc.c')
-rw-r--r--sys/kern/kern_malloc.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c
index 6adb16c95528..3061cb91568f 100644
--- a/sys/kern/kern_malloc.c
+++ b/sys/kern/kern_malloc.c
@@ -1033,7 +1033,7 @@ realloc(void *addr, size_t size, struct malloc_type *mtp, int flags)
* Copy over original contents. For KASAN, the redzone must be marked
* valid before performing the copy.
*/
- kasan_mark(addr, size, size, 0);
+ kasan_mark(addr, alloc, alloc, 0);
bcopy(addr, newaddr, min(size, alloc));
free(addr, mtp);
return (newaddr);