From ed19b7c5259d293e42ca4fc7c9eaa29cfcdcfbf3 Mon Sep 17 00:00:00 2001 From: "Simon J. Gerraty" Date: Sat, 29 Aug 2020 21:05:43 +0000 Subject: zalloc_malloc:Free hexdump preceeding buffer when we detect overflow Move hexdump from stand/common/misc.c to stand/libsa/hexdump.c (svn cp) Disable use of pager - causes linking issue for boot1 can be re-enabled by defining HEXDUMP_PAGER. Reviewed by: stevek, imp MFC after: 1 week Sponsored by: Juniper Networks Differential Revision: https://reviews.freebsd.org/D26235 --- stand/libsa/zalloc_malloc.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'stand/libsa/zalloc_malloc.c') diff --git a/stand/libsa/zalloc_malloc.c b/stand/libsa/zalloc_malloc.c index 98e28b8ef7f5..215e07d34a84 100644 --- a/stand/libsa/zalloc_malloc.c +++ b/stand/libsa/zalloc_malloc.c @@ -52,6 +52,10 @@ void mallocstats(void); static void *Malloc_align(size_t, size_t); +#ifndef MIN +# define MIN(a,b) ((a) <= (b)) ? (a) : (b) +#endif + void * Malloc(size_t bytes, const char *file __unused, int line __unused) { @@ -119,9 +123,14 @@ Free(void *ptr, const char *file, int line) ptr, file, line); return; } - if (res->ga_Magic != GAMAGIC) + if (res->ga_Magic != GAMAGIC) { + size_t dump_bytes; + + dump_bytes = MIN((ptr - MallocPool.mp_Base), 512); + hexdump(ptr - dump_bytes, dump_bytes); panic("free: guard1 fail @ %p from %s:%d", ptr, file, line); + } res->ga_Magic = GAFREE; #endif #ifdef USEENDGUARD -- cgit v1.3