mirror of
https://sourceware.org/git/glibc.git
synced 2024-12-25 04:01:10 +00:00
33237fe83d
And make always supported. The configure option was added on glibc 2.25 and some features require it (such as hwcap mask, huge pages support, and lock elisition tuning). It also simplifies the build permutations. Changes from v1: * Remove glibc.rtld.dynamic_sort changes, it is orthogonal and needs more discussion. * Cleanup more code. Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
139 lines
3.9 KiB
C
139 lines
3.9 KiB
C
/* Copyright (C) 2017-2023 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/>. */
|
|
|
|
/* Verify that tunables correctly filter out unsafe tunables like
|
|
glibc.malloc.check and glibc.malloc.mmap_threshold but also retain
|
|
glibc.malloc.mmap_threshold in an unprivileged child. */
|
|
|
|
#define _LIBC 1
|
|
#include "config.h"
|
|
#undef _LIBC
|
|
|
|
#include <errno.h>
|
|
#include <fcntl.h>
|
|
#include <stdlib.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/wait.h>
|
|
#include <unistd.h>
|
|
#include <intprops.h>
|
|
#include <array_length.h>
|
|
|
|
#include <support/check.h>
|
|
#include <support/support.h>
|
|
#include <support/test-driver.h>
|
|
#include <support/capture_subprocess.h>
|
|
|
|
const char *teststrings[] =
|
|
{
|
|
"glibc.malloc.check=2:glibc.malloc.mmap_threshold=4096",
|
|
"glibc.malloc.check=2:glibc.malloc.check=2:glibc.malloc.mmap_threshold=4096",
|
|
"glibc.malloc.check=2:glibc.malloc.mmap_threshold=4096:glibc.malloc.check=2",
|
|
"glibc.malloc.perturb=0x800",
|
|
"glibc.malloc.perturb=0x800:glibc.malloc.mmap_threshold=4096",
|
|
"glibc.malloc.perturb=0x800:not_valid.malloc.check=2:glibc.malloc.mmap_threshold=4096",
|
|
"glibc.not_valid.check=2:glibc.malloc.mmap_threshold=4096",
|
|
"not_valid.malloc.check=2:glibc.malloc.mmap_threshold=4096",
|
|
"glibc.malloc.garbage=2:glibc.maoc.mmap_threshold=4096:glibc.malloc.check=2",
|
|
"glibc.malloc.check=4:glibc.malloc.garbage=2:glibc.maoc.mmap_threshold=4096",
|
|
":glibc.malloc.garbage=2:glibc.malloc.check=1",
|
|
"glibc.malloc.check=1:glibc.malloc.check=2",
|
|
"not_valid.malloc.check=2",
|
|
"glibc.not_valid.check=2",
|
|
};
|
|
|
|
const char *resultstrings[] =
|
|
{
|
|
"glibc.malloc.mmap_threshold=4096",
|
|
"glibc.malloc.mmap_threshold=4096",
|
|
"glibc.malloc.mmap_threshold=4096",
|
|
"glibc.malloc.perturb=0x800",
|
|
"glibc.malloc.perturb=0x800:glibc.malloc.mmap_threshold=4096",
|
|
"glibc.malloc.perturb=0x800:glibc.malloc.mmap_threshold=4096",
|
|
"glibc.malloc.mmap_threshold=4096",
|
|
"glibc.malloc.mmap_threshold=4096",
|
|
"",
|
|
"",
|
|
"",
|
|
"",
|
|
"",
|
|
"",
|
|
};
|
|
|
|
static int
|
|
test_child (int off)
|
|
{
|
|
const char *val = getenv ("GLIBC_TUNABLES");
|
|
|
|
if (val != NULL && strcmp (val, resultstrings[off]) == 0)
|
|
return 0;
|
|
|
|
if (val != NULL)
|
|
printf ("[%d] Unexpected GLIBC_TUNABLES VALUE %s\n", off, val);
|
|
|
|
return 1;
|
|
}
|
|
|
|
static int
|
|
do_test (int argc, char **argv)
|
|
{
|
|
/* Setgid child process. */
|
|
if (argc == 2)
|
|
{
|
|
if (getgid () == getegid ())
|
|
/* This can happen if the file system is mounted nosuid. */
|
|
FAIL_UNSUPPORTED ("SGID failed: GID and EGID match (%jd)\n",
|
|
(intmax_t) getgid ());
|
|
|
|
int ret = test_child (atoi (argv[1]));
|
|
|
|
if (ret != 0)
|
|
exit (1);
|
|
|
|
exit (EXIT_SUCCESS);
|
|
}
|
|
else
|
|
{
|
|
int ret = 0;
|
|
|
|
/* Spawn tests. */
|
|
for (int i = 0; i < array_length (teststrings); i++)
|
|
{
|
|
char buf[INT_BUFSIZE_BOUND (int)];
|
|
|
|
printf ("Spawned test for %s (%d)\n", teststrings[i], i);
|
|
snprintf (buf, sizeof (buf), "%d\n", i);
|
|
if (setenv ("GLIBC_TUNABLES", teststrings[i], 1) != 0)
|
|
exit (1);
|
|
|
|
int status = support_capture_subprogram_self_sgid (buf);
|
|
|
|
/* Bail out early if unsupported. */
|
|
if (WEXITSTATUS (status) == EXIT_UNSUPPORTED)
|
|
return EXIT_UNSUPPORTED;
|
|
|
|
ret |= status;
|
|
}
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
#define TEST_FUNCTION_ARGV do_test
|
|
#include <support/test-driver.c>
|