[Libguestfs] [PATCH nbdkit v2 1/2] tests: Invoke MALLOC_CHECK_ correctly and only for glibc

Eric Blake eblake at redhat.com
Mon Aug 23 14:36:44 UTC 2021


On Sun, Aug 22, 2021 at 01:57:15PM +0100, Richard W.M. Jones wrote:
> MALLOC_CHECK_ and MALLOC_PERTURB_ environment variables have been
> replaced in glibc 2.34 by GLIBC_TUNABLES settings[1][2].  In addition
> the new glibc requires that you preload a new library called
> libc_malloc_debug.so.0 to get these features.

Do we actually require the soname .so.0, or can we get by with the
more generic version-less .so (and thus continue to work when glibc
bumps to .so.1, provided that bump is backwards compatible for our
usage)?

> 
> These features never worked in non-glibc (but the environment
> variables are ignored).
> 
> Only define MALLOC_* environment variables when we detect glibc < 2.34,
> using the ordinary glibc macros[3].
> 
> For glibc >= 2.34, use the new library and GLIBC_TUNABLES.  Note this
> relies on LD_PRELOAD warning but otherwise not breaking if a preload
> library does not exist.
> 
> [1] https://www.gnu.org/software/libc/manual/html_node/Memory-Allocation-Tunables.html
> [2] https://sourceware.org/pipermail/libc-alpha/2021-August/129718.html
> [3] https://sourceforge.net/p/predef/wiki/Libraries/
> 
> Thanks: Eric Blake
> ---
> +# Enable malloc-check as a cheap way to find some use-after-free and
> +# uninitialized read problems when using glibc, and doesn't affect
> +# normal operation or other libc.
> +random = $(shell bash -c 'echo $$(( 1 + (RANDOM & 255) ))')
> +if HAVE_GLIBC_234
> +TESTS_ENVIRONMENT += \
> +	LD_PRELOAD="$${LD_PRELOAD:+"$$LD_PRELOAD:"}$(libdir)/libc_malloc_debug.so.0" \
> +	GLIBC_TUNABLES=glibc.malloc.check=1:glibc.malloc.perturb=$(random) \
> +	$(NULL)

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org




More information about the Libguestfs mailing list