[PATCH v5 4/4] Add system-wide tunables: Filters
Florian Weimer
fweimer@redhat.com
Thu Feb 26 13:47:04 GMT 2026
* DJ Delorie:
> @@ -340,9 +349,58 @@ __tunables_init (char **envp)
> if (tid == -1)
> continue;
> }
> - /* At this point, TID is valid for the tunable we want. See
> - if the parsed type matches the desired type. */
> -
> + /* At this point, TID is valid for the tunable we want. */
> +
> + /* Apply selected filter, if any. */
> + switch (tec->flags & TUNCONF_FLAG_FILTER) {
> + case TUNCONF_FILTER_PERPROC:
> + /* Perform one-time calculations that aren't needed if we
> + don't use this filter. */
> + if (prog_name_len == -1)
> + {
> + ssize_t n = readlink ("/proc/self/exe",
> + exebuf, sizeof (exebuf) - 1);
> + if (n > 0 && n < sizeof(exebuf)-1)
> + {
> + /* If /proc/self/exe exists and we can read it,
> + it's more reliable than argv[] so use it. */
> + exebuf[n] = '\0';
> + prog_name = exebuf;
> + }
> + if (prog_name != NULL)
> + {
> + const char *slash = NULL, *cp;
> + for (cp = prog_name; *cp; ++ cp)
> + if (*cp == '/')
> + slash = cp;
> + if (slash)
> + base_name = slash + 1;
> + else
> + base_name = prog_name;
> + prog_name_len = strlen (prog_name);
> + base_name_len = strlen (base_name);
> + }
Ideally this would be consolidated with the l_origin computation for the
main map. The logic seems a bit backwards to me.
I think we need two matching modes here:
* The path is deemed trusted by the system administrator. The tunable
is used for all binaries (including when __libc_enable_secure is
active).
* The path is not trusted. The tunable is not used in AT_SECURE mode.
All argv[0] comparisons are not trusted (not used for AT_SECURE mode).
In any case, this needs more documentation about the syntax.
> diff --git a/elf/tst-tunconf1.root/etc/tunables.conf b/elf/tst-tunconf1.root/etc/tunables.conf
> new file mode 100644
> index 0000000000..3c7b33c399
> --- /dev/null
> +++ b/elf/tst-tunconf1.root/etc/tunables.conf
> @@ -0,0 +1,6 @@
> +glibc.malloc.tcache_max=6
> +glibc.malloc.tcache_count=3
> +[proc:/bin/ls]
> +glibc.malloc.tcache_max=7
> +[proc:tst-tunconf1]
> +glibc.malloc.tcache_max=4
I'm still a bit on the fence regarding the separate tunables.conf file.
I think deployment (through tools like Ansible) is easier if integrated
with the existing ld.so.conf framework. I would recommend a more
keyword-oriented syntax that allows future introduction of additional
directives. So perhaps something like:
match-executable-path "/usr/bin/ls"
set-tunable glibc.malloc.tcache_max=7
We should have a proper way for quoting strings from the beginning.
Thanks,
Florian
More information about the Libc-alpha
mailing list