]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: pools: report a replaced memory allocator instead of just malloc_trim()
authorWilly Tarreau <w@1wt.eu>
Wed, 22 Mar 2023 17:01:41 +0000 (18:01 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 22 Mar 2023 17:05:02 +0000 (18:05 +0100)
Instead of reporting the inaccurate "malloc_trim() support" on -vv, let's
report the case where the memory allocator was actively replaced from the
one used at build time, as this is the corner case we want to be cautious
about. We also put a tainted bit when this happens so that it's possible
to detect it at run time (e.g. the user might have inherited it from an
environment variable during a reload operation).

The now unused is_trim_enabled() function was finally dropped.

include/haproxy/bug.h
include/haproxy/pool.h
src/pool.c

index 54536ff8605c59b446811be2124cce4c90b07de9..a5c1341968034839e4034cb3648761720469627c 100644 (file)
@@ -221,6 +221,7 @@ enum tainted_flags {
        TAINTED_BUG                    = 0x00000020, /* a BUG_ON triggered */
        TAINTED_SHARED_LIBS            = 0x00000040, /* a shared library was loaded */
        TAINTED_REDEFINITION           = 0x00000080, /* symbol redefinition detected */
+       TAINTED_REPLACED_MEM_ALLOCATOR = 0x00000100, /* memory allocator was replaced using LD_PRELOAD */
 };
 
 /* this is a bit field made of TAINTED_*, and is declared in haproxy.c */
index d034feaff5872ab1851e8a192baa43581e9f4ed9..19ead23798d10059b30acdca466fb1c2fe80bce3 100644 (file)
@@ -101,7 +101,6 @@ extern int mem_poison_byte;
 /* set of POOL_DBG_* flags */
 extern uint pool_debugging;
 
-int is_trim_enabled(void);
 int malloc_trim(size_t pad);
 void trim_all_pools(void);
 
index 07b122a61a27a6f70f68799bc6c87f932fe610a2..292b27d13375d3c46cc76c87fa3aace99220b662 100644 (file)
@@ -188,11 +188,6 @@ static void detect_allocator(void)
        _malloc_trim = get_sym_next_addr("malloc_trim");
 }
 
-int is_trim_enabled(void)
-{
-       return !disable_trim && using_default_allocator;
-}
-
 /* replace the libc's malloc_trim() so that we can also intercept the calls
  * from child libraries when the allocator is not the default one.
  */
@@ -1221,10 +1216,11 @@ INITCALL0(STG_PREPARE, init_pools);
 /* Report in build options if trim is supported */
 static void pools_register_build_options(void)
 {
-       if (is_trim_enabled() && _malloc_trim) {
+       if (!using_default_allocator) {
                char *ptr = NULL;
-               memprintf(&ptr, "Support for malloc_trim() is enabled.");
+               memprintf(&ptr, "Running with a replaced memory allocator (e.g. via LD_PRELOAD).");
                hap_register_build_opts(ptr, 1);
+               mark_tainted(TAINTED_REPLACED_MEM_ALLOCATOR);
        }
 }
 INITCALL0(STG_REGISTER, pools_register_build_options);