glibc/elf/tst-auditmod21a.c
Adhemerval Zanella 254d3d5aef elf: Fix initial-exec TLS access on audit modules (BZ #28096)
For audit modules and dependencies with initial-exec TLS, we can not
set the initial TLS image on default loader initialization because it
would already be set by the audit setup.  However, subsequent thread
creation would need to follow the default behaviour.

This patch fixes it by setting l_auditing link_map field not only
for the audit modules, but also for all its dependencies.  This is
used on _dl_allocate_tls_init to avoid the static TLS initialization
at load time.

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

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
2022-02-01 14:49:46 -03:00

81 lines
1.8 KiB
C

/* Check LD_AUDIT with static TLS.
Copyright (C) 2022 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
#include <ctype.h>
#include <stdlib.h>
#include <link.h>
#define tls_ie __attribute__ ((tls_model ("initial-exec")))
__thread int tls_var0 tls_ie;
__thread int tls_var1 tls_ie = 0x10;
/* Defined at tst-auditmod21b.so */
extern __thread int tls_var2;
extern __thread int tls_var3;
static volatile int out;
static void
call_libc (void)
{
/* isspace accesses the initial-exec glibc TLS variables, which are
setup in glibc initialization. */
out = isspace (' ');
}
unsigned int
la_version (unsigned int v)
{
tls_var0 = 0x1;
if (tls_var1 != 0x10)
abort ();
tls_var1 = 0x20;
tls_var2 = 0x2;
if (tls_var3 != 0x20)
abort ();
tls_var3 = 0x40;
call_libc ();
return LAV_CURRENT;
}
unsigned int
la_objopen (struct link_map* map, Lmid_t lmid, uintptr_t* cookie)
{
call_libc ();
*cookie = (uintptr_t) map;
return 0;
}
void
la_activity (uintptr_t* cookie, unsigned int flag)
{
if (tls_var0 != 0x1 || tls_var1 != 0x20)
abort ();
call_libc ();
}
void
la_preinit (uintptr_t* cookie)
{
call_libc ();
}