From 9b7da2e3c3a7127d39e6ba94be9dadc9ac3f273e Mon Sep 17 00:00:00 2001 From: Nick Bofferding Date: Thu, 25 Oct 2018 16:59:50 -0500 Subject: Support for putting fences around mallocs This commit implements a compile time feature (set MALLOC_FENCING to y in the src/lib/HBconfig file) which puts check bytes around each malloc. Whenever an allocation is freed, if the check bytes have changed, the memory manager immediate crashes Hostboot. It also fixes a heap corruption in the SBE get capabilities command. Change-Id: I3df96d5fce43c34d3574c47f3c674076842d90e1 CQ: SW442980 Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/68214 Tested-by: Jenkins Server Tested-by: Jenkins OP Build CI Tested-by: Jenkins OP HW Tested-by: FSP CI Jenkins Reviewed-by: Ilya Smirnov Reviewed-by: Roland Veloz Reviewed-by: Daniel M. Crowell --- src/lib/HBconfig | 5 +++++ src/lib/stdlib.C | 15 ++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 src/lib/HBconfig (limited to 'src/lib') diff --git a/src/lib/HBconfig b/src/lib/HBconfig new file mode 100644 index 000000000..05added71 --- /dev/null +++ b/src/lib/HBconfig @@ -0,0 +1,5 @@ +config MALLOC_FENCING + default n + help + Enable generating check bytes around each malloc and + enforcing that those bytes are undisturbed on every matching free diff --git a/src/lib/stdlib.C b/src/lib/stdlib.C index 610a045a3..a7c694f9d 100644 --- a/src/lib/stdlib.C +++ b/src/lib/stdlib.C @@ -5,7 +5,7 @@ /* */ /* OpenPOWER HostBoot Project */ /* */ -/* Contributors Listed Below - COPYRIGHT 2010,2014 */ +/* Contributors Listed Below - COPYRIGHT 2010,2018 */ /* [+] International Business Machines Corp. */ /* */ /* */ @@ -28,6 +28,7 @@ #include #include #include +#include #ifdef HOSTBOOT_MEMORY_LEAKS #include @@ -114,10 +115,12 @@ void* malloc(size_t s) return result; } - void free(void* p) { - if (NULL == p) return; + if (nullptr == p) + { + return; + } #ifdef HOSTBOOT_MEMORY_LEAKS memoryleak_magic_instruction(MEMORYLEAK_FREE, 0, p, NULL); @@ -126,10 +129,12 @@ void free(void* p) HeapManager::free(p); } - void* realloc(void* p, size_t s) { - if (NULL == p) return malloc(s); + if (nullptr == p) + { + return malloc(s); + } void* result = HeapManager::realloc(p,s); -- cgit v1.2.1