[PATCH 0/9] mcheck implementation for U-Boot

Eugene Uriev
2024-03-31T21:00:18Z

There was no "mcheck" for U-Boot before.

Since U-Boot has only 1 thread, and normally makes 4000+ - 6000+
mallocs, it's better to use havier canaries to protect heap-chunks.
My variant uses 2x8 = 16byte-long protector. And
the multiplier could be changed to tune speed/protection tradeoff.
This protects not only against memset()-s, but against "near" wild
pointers too, and makes more probable to catch "distant" ones.

The core file of the set is included into the C-file, not complied
separately in order to enable (potential) coexisting of
mcheck-protectors, e.g. malloc_simple(.) and dlmalloc simultaneously.

My tests were for ARM SoC, 64bit, so the patch is
aware of alignment.

Primary this patch is for using by developers: to verify,
if a change doesn't break the heap integrity.
By default the mcheck is disabled and wouldn't affect the boot.

I used pedantic mode, canary=16byte, registry-size=6608.
For my system the overhead was 230ms.

I assume, the merge window coming. So I send it now.

Eugene Uriev (9):
mcheck: prepare +1 tier for mcheck-wrappers, in dl-*alloc commands
mcheck: Use memset/memcpy instead of MALLOC_ZERO/MALLOC_COPY for
mcheck.
mcheck: introduce essentials of mcheck
mcheck: integrate mcheck into dlmalloc.c
mcheck: support memalign
mcheck: add pedantic mode support
mcheck: introduce mcheck_on_ramrelocation(.)
mcheck: add stats, add a comment with test results
mcheck: let mcheck_abortfunc_t print the pointer

common/board_f.c | 4 +
common/dlmalloc.c | 154 ++++++++++++++++----
common/mcheck_core.inc.h | 304 +++++++++++++++++++++++++++++++++++++++
include/mcheck.h | 51 +++++++
4 files changed, 488 insertions(+), 25 deletions(-)
create mode 100644 common/mcheck_core.inc.h
create mode 100644 include/mcheck.h

--
2.25.1