2024-01-01 18:12:26 +00:00
|
|
|
/* Copyright (C) 2012-2024 Free Software Foundation, Inc.
|
2017-02-02 10:16:01 +00:00
|
|
|
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
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 05:40:42 +00:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
2017-02-02 10:16:01 +00:00
|
|
|
|
2023-11-06 20:25:37 +00:00
|
|
|
/* Verify that correctly filter out unsafe environment variables defined
|
|
|
|
in unsecvars.h. */
|
2017-02-02 10:16:01 +00:00
|
|
|
|
2023-11-06 20:25:37 +00:00
|
|
|
#include <array_length.h>
|
|
|
|
#include <gnu/lib-names.h>
|
2017-02-02 10:16:01 +00:00
|
|
|
#include <stdio.h>
|
2023-11-06 20:25:37 +00:00
|
|
|
#include <stdlib.h>
|
2017-02-02 10:16:01 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2021-03-16 07:07:53 +00:00
|
|
|
#include <support/check.h>
|
2017-02-02 10:16:01 +00:00
|
|
|
#include <support/support.h>
|
|
|
|
#include <support/test-driver.h>
|
2021-03-16 07:07:53 +00:00
|
|
|
#include <support/capture_subprocess.h>
|
2017-02-02 10:16:01 +00:00
|
|
|
|
|
|
|
static char SETGID_CHILD[] = "setgid-child";
|
|
|
|
|
2023-11-06 20:25:37 +00:00
|
|
|
#define FILTERED_VALUE "some-filtered-value"
|
|
|
|
#define UNFILTERED_VALUE "some-unfiltered-value"
|
2023-11-06 20:25:45 +00:00
|
|
|
/* It assumes no other programs is being profile with a library with same
|
|
|
|
SONAME using the default folder. */
|
2023-12-13 11:44:50 +00:00
|
|
|
#ifndef PROFILE_LIB
|
|
|
|
# define PROFILE_LIB "tst-sonamemove-runmod2.so"
|
|
|
|
#endif
|
2017-02-02 10:16:01 +00:00
|
|
|
|
2023-11-06 20:25:37 +00:00
|
|
|
struct envvar_t
|
|
|
|
{
|
|
|
|
const char *env;
|
|
|
|
const char *value;
|
|
|
|
};
|
2017-03-07 15:22:04 +00:00
|
|
|
|
2023-11-06 20:25:37 +00:00
|
|
|
/* That is not an extensible list of all filtered out environment
|
|
|
|
variables. */
|
|
|
|
static const struct envvar_t filtered_envvars[] =
|
|
|
|
{
|
|
|
|
{ "GLIBC_TUNABLES", FILTERED_VALUE },
|
|
|
|
{ "LD_AUDIT", FILTERED_VALUE },
|
|
|
|
{ "LD_HWCAP_MASK", FILTERED_VALUE },
|
|
|
|
{ "LD_LIBRARY_PATH", FILTERED_VALUE },
|
|
|
|
{ "LD_PRELOAD", FILTERED_VALUE },
|
2023-12-13 11:44:50 +00:00
|
|
|
{ "LD_PROFILE", PROFILE_LIB },
|
2023-11-06 20:25:37 +00:00
|
|
|
{ "MALLOC_ARENA_MAX", FILTERED_VALUE },
|
|
|
|
{ "MALLOC_PERTURB_", FILTERED_VALUE },
|
|
|
|
{ "MALLOC_TRACE", FILTERED_VALUE },
|
|
|
|
{ "MALLOC_TRIM_THRESHOLD_", FILTERED_VALUE },
|
|
|
|
{ "RES_OPTIONS", FILTERED_VALUE },
|
2023-11-22 20:43:23 +00:00
|
|
|
{ "LD_DEBUG", "all" },
|
|
|
|
{ "LD_DEBUG_OUTPUT", "/tmp/some-file" },
|
|
|
|
{ "LD_WARN", FILTERED_VALUE },
|
|
|
|
{ "LD_VERBOSE", FILTERED_VALUE },
|
2023-11-22 20:43:24 +00:00
|
|
|
{ "LD_BIND_NOW", "0" },
|
|
|
|
{ "LD_BIND_NOT", "1" },
|
2023-11-06 20:25:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct envvar_t unfiltered_envvars[] =
|
|
|
|
{
|
|
|
|
/* Non longer supported option. */
|
|
|
|
{ "LD_ASSUME_KERNEL", UNFILTERED_VALUE },
|
|
|
|
};
|
2017-02-02 10:16:01 +00:00
|
|
|
|
|
|
|
static int
|
2023-11-06 20:25:37 +00:00
|
|
|
test_child (void)
|
2017-02-02 10:16:01 +00:00
|
|
|
{
|
2023-11-06 20:25:37 +00:00
|
|
|
int ret = 0;
|
2017-02-02 10:16:01 +00:00
|
|
|
|
2023-11-06 20:25:37 +00:00
|
|
|
for (const struct envvar_t *e = filtered_envvars;
|
|
|
|
e != array_end (filtered_envvars);
|
|
|
|
e++)
|
2017-02-02 10:16:01 +00:00
|
|
|
{
|
2023-11-06 20:25:37 +00:00
|
|
|
const char *env = getenv (e->env);
|
2023-12-13 11:44:50 +00:00
|
|
|
if (env != NULL)
|
|
|
|
{
|
|
|
|
printf ("FAIL: filtered environment variable is not NULL: %s=%s\n",
|
|
|
|
e->env, env);
|
|
|
|
ret = 1;
|
|
|
|
}
|
2017-02-02 10:16:01 +00:00
|
|
|
}
|
|
|
|
|
2023-11-06 20:25:37 +00:00
|
|
|
for (const struct envvar_t *e = unfiltered_envvars;
|
|
|
|
e != array_end (unfiltered_envvars);
|
|
|
|
e++)
|
2017-03-07 15:22:04 +00:00
|
|
|
{
|
2023-11-06 20:25:37 +00:00
|
|
|
const char *env = getenv (e->env);
|
2023-12-13 11:44:50 +00:00
|
|
|
if (!(env != NULL && strcmp (env, e->value) == 0))
|
|
|
|
{
|
|
|
|
if (env == NULL)
|
|
|
|
printf ("FAIL: unfiltered environment variable %s is NULL\n",
|
|
|
|
e->env);
|
|
|
|
else
|
|
|
|
printf ("FAIL: unfiltered environment variable %s=%s != %s\n",
|
|
|
|
e->env, env, e->value);
|
|
|
|
|
|
|
|
ret = 1;
|
|
|
|
}
|
2017-03-07 15:22:04 +00:00
|
|
|
}
|
|
|
|
|
2023-12-13 11:44:50 +00:00
|
|
|
/* Also check if no profile file was created.
|
|
|
|
The parent sets LD_DEBUG_OUTPUT="/tmp/some-file"
|
|
|
|
which should be filtered. Then it falls back to "/var/tmp".
|
|
|
|
Note: LD_PROFILE is not supported for static binaries. */
|
2023-11-06 20:25:45 +00:00
|
|
|
{
|
|
|
|
char *profilepath = xasprintf ("/var/tmp/%s.profile", PROFILE_LIB);
|
2023-12-13 11:44:50 +00:00
|
|
|
if (!access (profilepath, R_OK))
|
|
|
|
{
|
|
|
|
printf ("FAIL: LD_PROFILE file at %s was created!\n", profilepath);
|
|
|
|
ret = 1;
|
|
|
|
}
|
2023-11-06 20:25:45 +00:00
|
|
|
free (profilepath);
|
|
|
|
}
|
|
|
|
|
2023-11-06 20:25:37 +00:00
|
|
|
return ret;
|
2017-02-02 10:16:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2017-02-04 06:32:37 +00:00
|
|
|
do_test (int argc, char **argv)
|
2017-02-02 10:16:01 +00:00
|
|
|
{
|
2023-11-06 20:25:37 +00:00
|
|
|
/* For dynamic loader, the test requires --enable-hardcoded-path-in-tests so
|
|
|
|
the kernel sets the AT_SECURE on process initialization. */
|
|
|
|
if (argc >= 2 && strstr (argv[1], LD_SO) != 0)
|
|
|
|
FAIL_UNSUPPORTED ("dynamic test requires --enable-hardcoded-path-in-tests");
|
|
|
|
|
2017-02-02 10:16:01 +00:00
|
|
|
/* Setgid child process. */
|
|
|
|
if (argc == 2 && strcmp (argv[1], SETGID_CHILD) == 0)
|
|
|
|
{
|
|
|
|
if (getgid () == getegid ())
|
2021-03-16 07:07:53 +00:00
|
|
|
/* This can happen if the file system is mounted nosuid. */
|
|
|
|
FAIL_UNSUPPORTED ("SGID failed: GID and EGID match (%jd)\n",
|
|
|
|
(intmax_t) getgid ());
|
2017-02-02 10:16:01 +00:00
|
|
|
|
|
|
|
int ret = test_child ();
|
|
|
|
|
|
|
|
if (ret != 0)
|
|
|
|
exit (1);
|
|
|
|
|
2023-11-06 20:25:37 +00:00
|
|
|
/* Special return code to make sure that the child executed all the way
|
|
|
|
through. */
|
|
|
|
exit (42);
|
2017-02-02 10:16:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-11-06 20:25:37 +00:00
|
|
|
for (const struct envvar_t *e = filtered_envvars;
|
|
|
|
e != array_end (filtered_envvars);
|
|
|
|
e++)
|
|
|
|
setenv (e->env, e->value, 1);
|
|
|
|
|
|
|
|
for (const struct envvar_t *e = unfiltered_envvars;
|
|
|
|
e != array_end (unfiltered_envvars);
|
|
|
|
e++)
|
|
|
|
setenv (e->env, e->value, 1);
|
2017-02-02 10:16:01 +00:00
|
|
|
|
2023-12-13 11:44:50 +00:00
|
|
|
/* Ensure that the profile output does not exist from a previous run
|
|
|
|
(e.g. if test_dir, which defaults to /tmp, is mounted nosuid.)
|
|
|
|
Note: support_capture_subprogram_self_sgid creates the SGID binary
|
|
|
|
in test_dir. */
|
|
|
|
{
|
|
|
|
char *profilepath = xasprintf ("/var/tmp/%s.profile", PROFILE_LIB);
|
|
|
|
unlink (profilepath);
|
|
|
|
free (profilepath);
|
|
|
|
}
|
|
|
|
|
2021-03-16 07:07:53 +00:00
|
|
|
int status = support_capture_subprogram_self_sgid (SETGID_CHILD);
|
2017-02-02 10:16:01 +00:00
|
|
|
|
2021-03-16 07:07:53 +00:00
|
|
|
if (WEXITSTATUS (status) == EXIT_UNSUPPORTED)
|
2023-11-06 20:25:37 +00:00
|
|
|
exit (EXIT_UNSUPPORTED);
|
|
|
|
|
|
|
|
if (WEXITSTATUS (status) != 42)
|
|
|
|
{
|
|
|
|
printf (" child failed with status %d\n",
|
|
|
|
WEXITSTATUS (status));
|
|
|
|
support_record_failure ();
|
|
|
|
}
|
2017-02-02 10:16:01 +00:00
|
|
|
|
2021-03-16 07:07:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2017-02-02 10:16:01 +00:00
|
|
|
}
|
|
|
|
|
2017-02-04 06:32:37 +00:00
|
|
|
#define TEST_FUNCTION_ARGV do_test
|
2017-02-02 10:16:01 +00:00
|
|
|
#include <support/test-driver.c>
|