|
From: Paul F. <pj...@wa...> - 2023-03-12 15:56:06
|
Hi
I'm starting to look at adding alignment checks for the various aligned
allocators in memcheck.
That will give us errors like ASAN:
==89579==ERROR: AddressSanitizer: invalid alignment requested in
posix_memalign: -1, alignment must be a power of two and a multiple of
sizeof(void*) == 8 (thread T0)
#0 0x28e487 in posix_memalign
/usr/src/contrib/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:210:3
#1 0x2b7c00 in main
/usr/home/paulf/scratch/valgrind/memcheck/tests/posix_memalign.c:39:10
#2 0x23542f in _start /usr/src/lib/csu/amd64/crt1_c.c:75:7
#3 0x8002dd007 (<unknown module>)
There are two problems. Firstly we map 4 C aligned allocation functions
(memalign, posix_memalign, aligned_alloc and valloc) to our one wrapper
interface, tl_memalign. So we don't know which function to check for.
Secondly we do argument checking / fixup in vg_replace_malloc. That
means that at the moment invalid args often cause a fail before getting
to memcheck.
To discriminate between the functions, the easiest thing will probably
be to add an enum tag (splitting tl_memalign into 3 will be a lot of
effort).
I see two possible solutions for the checks.
1/ move all the checking later so that memcheck can see the arguments.
2/ use a client req before all of the argument twiddling
I'm leaning more to using a client req as it has less impact on the
existing flow.
Any thoughts?
A+
Paul
|