tst-leaks1 \
tst-stringtable \
tst-tls9 \
+ tst-tunables-enable_secure-env \
# tests
tests-internal := \
$(objpfx)tst-trace3.out \
$(objpfx)tst-trace4.out \
$(objpfx)tst-trace5.out \
+ $(objpfx)tst-tunables-enable_secure-env.out \
$(objpfx)tst-unused-dep-cmp.out \
$(objpfx)tst-unused-dep.out \
# tests-special
cmp $< /dev/null > $@; \
$(evaluate-test)
+$(objpfx)tst-tunables-enable_secure-env.out: $(objpfx)tst-tunables-enable_secure-env
+ $(test-wrapper-env) \
+ GLIBC_TUNABLES=glibc.rtld.enable_secure=1 \
+ $(rtld-prefix) \
+ $< > $@; \
+ $(evaluate-test)
+
+
$(objpfx)tst-audit11.out: $(objpfx)tst-auditmod11.so $(objpfx)tst-audit11mod1.so
tst-audit11-ENV = LD_AUDIT=$(objpfx)tst-auditmod11.so
$(objpfx)tst-audit11mod1.so: $(objpfx)tst-audit11mod2.so
Since all of them start with `LD_' we are a bit smarter while finding
all the entries. */
extern char **_environ attribute_hidden;
-static void process_envvars (struct dl_main_state *state);
+static int process_envvars (struct dl_main_state *state);
int _dl_argc attribute_relro attribute_hidden;
char **_dl_argv attribute_relro = NULL;
_dl_argv and _dl_argc accordingly. Those arguments are removed from
argv here. */
static void
-_dl_start_args_adjust (int skip_args)
+_dl_start_args_adjust (int skip_args, int skip_env)
{
void **sp = (void **) (_dl_argv - skip_args - 1);
void **p = sp + skip_args;
while (*p != NULL);
#ifdef HAVE_AUX_VECTOR
- void **auxv = (void **) GLRO(dl_auxv) - skip_args;
+ void **auxv = (void **) GLRO(dl_auxv) - skip_args - skip_env;
GLRO(dl_auxv) = (ElfW(auxv_t) *) auxv; /* Aliasing violation. */
assert (auxv == sp + 1);
unsigned int i;
bool rtld_is_main = false;
void *tcbp = NULL;
+ int skip_env = 0;
struct dl_main_state state;
dl_main_state_init (&state);
#endif
/* Process the environment variable which control the behaviour. */
- process_envvars (&state);
+ skip_env = process_envvars (&state);
#ifndef HAVE_INLINED_SYSCALLS
/* Set up a flag which tells we are just starting. */
_dl_argv[0] = argv0;
/* Adjust arguments for the application entry point. */
- _dl_start_args_adjust (_dl_argv - orig_argv);
+ _dl_start_args_adjust (_dl_argv - orig_argv, skip_env);
}
else
{
}
}
\f
-static void
+static int
process_envvars_secure (struct dl_main_state *state)
{
char **runp = _environ;
char *envline;
+ int skip_env = 0;
while ((envline = _dl_next_ld_env_entry (&runp)) != NULL)
{
const char *nextp = UNSECURE_ENVVARS;
do
{
+ /* Keep track of the number of environment variables that were set in
+ the environment and are unset below. Use getenv() which returns
+ non-NULL if the variable is set in the environment. This count is
+ needed if we need to adjust the location of the AUX vector on the
+ stack when running ld.so directly. */
+ if (getenv (nextp) != NULL)
+ skip_env++;
+
unsetenv (nextp);
nextp = strchr (nextp, '\0') + 1;
}
|| state->mode != rtld_mode_normal
|| state->version_info)
_exit (5);
+
+ return skip_env;
}
static void
}
}
-static void
+static int
process_envvars (struct dl_main_state *state)
{
+ int skip_env = 0;
if (__glibc_unlikely (__libc_enable_secure))
- process_envvars_secure (state);
+ skip_env += process_envvars_secure (state);
else
process_envvars_default (state);
+
+ return skip_env;
}
#if HP_TIMING_INLINE
--- /dev/null
+/* Check enable_secure tunable handles removed ENV variables without
+ assertions.
+ Copyright (C) 2024 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 <support/capture_subprocess.h>
+#include <support/check.h>
+
+static int
+do_test (int argc, char *argv[])
+{
+ /* Ensure that no assertions are hit when a dynamically linked application
+ runs. This test requires that GLIBC_TUNABLES=glibc.rtld.enable_secure=1
+ is set. */
+ return 0;
+}
+
+#define TEST_FUNCTION_ARGV do_test
+#include <support/test-driver.c>