Module Name: src Committed By: maxv Date: Tue Aug 21 07:56:53 UTC 2018
Modified Files: src/sys/kern: kern_malloc.c Log Message: Need to keep track of the requested size, when realloc is used under kASan. Maybe we could use mh_rqsz by default. To generate a diff of this commit: cvs rdiff -u -r1.149 -r1.150 src/sys/kern/kern_malloc.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/kern_malloc.c diff -u src/sys/kern/kern_malloc.c:1.149 src/sys/kern/kern_malloc.c:1.150 --- src/sys/kern/kern_malloc.c:1.149 Tue Aug 21 01:25:57 2018 +++ src/sys/kern/kern_malloc.c Tue Aug 21 07:56:53 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_malloc.c,v 1.149 2018/08/21 01:25:57 pgoyette Exp $ */ +/* $NetBSD: kern_malloc.c,v 1.150 2018/08/21 07:56:53 maxv Exp $ */ /* * Copyright (c) 1987, 1991, 1993 @@ -70,7 +70,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: kern_malloc.c,v 1.149 2018/08/21 01:25:57 pgoyette Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_malloc.c,v 1.150 2018/08/21 07:56:53 maxv Exp $"); #ifdef _KERNEL_OPT #include "opt_kasan.h" @@ -101,7 +101,10 @@ MALLOC_DEFINE(M_MRTABLE, "mrt", "multica * Header contains total size, including the header itself. */ struct malloc_header { - size_t mh_size; + size_t mh_size; +#ifdef KASAN + size_t mh_rqsz; +#endif } __aligned(ALIGNBYTES + 1); void * @@ -139,6 +142,9 @@ kern_malloc(unsigned long size, int flag } mh = (void *)((char *)p + hdroffset); mh->mh_size = allocsize - hdroffset; +#ifdef KASAN + mh->mh_rqsz = origsize; +#endif mh++; #ifdef KASAN @@ -195,7 +201,11 @@ kern_realloc(void *curaddr, unsigned lon mh = curaddr; mh--; +#ifdef KASAN + cursize = mh->mh_rqsz; +#else cursize = mh->mh_size - sizeof(struct malloc_header); +#endif /* * If we already actually have as much as they want, we're done.