]> git.ipfire.org Git - thirdparty/glibc.git/commit
elf: Only process multiple tunable once (BZ 31686)
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Mon, 6 May 2024 16:18:45 +0000 (13:18 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Tue, 7 May 2024 15:16:36 +0000 (12:16 -0300)
commitbcae44ea8536b30a7119c0986ff5692bddacb672
tree3ad07f5e12524dda7c6ce8ef971baae455eeca50
parent143ef68b2aded7c794956beddad495af8c7d3251
elf: Only process multiple tunable once (BZ 31686)

The 680c597e9c3 commit made loader reject ill-formatted strings by
first tracking all set tunables and then applying them. However, it does
not take into consideration if the same tunable is set multiple times,
where parse_tunables_string appends the found tunable without checking
if it was already in the list. It leads to a stack-based buffer overflow
if the tunable is specified more than the total number of tunables.  For
instance:

  GLIBC_TUNABLES=glibc.malloc.check=2:... (repeat over the number of
  total support for different tunable).

Instead, use the index of the tunable list to get the expected tunable
entry.  Since now the initial list is zero-initialized, the compiler
might emit an extra memset and this requires some minor adjustment
on some ports.

Checked on x86_64-linux-gnu and aarch64-linux-gnu.

Reported-by: Yuto Maeda <maeda@cyberdefense.jp>
Reported-by: Yutaro Shimizu <shimizu@cyberdefense.jp>
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
elf/dl-tunables.c
elf/tst-tunables.c
sysdeps/aarch64/multiarch/memset_generic.S
sysdeps/sparc/sparc64/rtld-memset.c