Additional mremap test cases

Resolves: RHEL-62716
This commit is contained in:
Frédéric Bérat 2025-01-10 18:57:23 +01:00
parent 0c05a36bc6
commit aed55c3eae
3 changed files with 508 additions and 0 deletions

214
glibc-RHEL-62716-1.patch Normal file
View File

@ -0,0 +1,214 @@
commit 8022fc7d5119a22e9e0ac72798f649385b0e167a
Author: Frédéric Bérat <fberat@redhat.com>
Date: Wed Jun 14 10:52:07 2023 +0200
tests: replace system by xsystem
With fortification enabled, system calls return result needs to be checked,
has it gets the __wur macro enabled.
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Conflicts:
nptl/tst-cancel7.c (change not relevant for this version)
diff --git a/elf/tst-stackguard1.c b/elf/tst-stackguard1.c
index 6584740d6aa26f5f..9c4a5ccde0c659a9 100644
--- a/elf/tst-stackguard1.c
+++ b/elf/tst-stackguard1.c
@@ -27,6 +27,8 @@
#include <tls.h>
#include <unistd.h>
+#include <support/xstdlib.h>
+
static const char *command;
static bool child;
static uintptr_t stack_chk_guard_copy;
@@ -109,7 +111,8 @@ do_test (void)
dup2 (fds[1], 2);
close (fds[1]);
- system (command);
+ xsystem (command);
+
exit (0);
}
diff --git a/libio/bug-mmap-fflush.c b/libio/bug-mmap-fflush.c
index d8aa58985aa0790c..3f99222eefa7d4c3 100644
--- a/libio/bug-mmap-fflush.c
+++ b/libio/bug-mmap-fflush.c
@@ -4,6 +4,7 @@
#include <stdlib.h>
#include <string.h>
+#include <support/xstdlib.h>
static char *fname;
@@ -35,14 +36,16 @@ do_test (void)
char buffer[1024];
snprintf (buffer, sizeof (buffer), "echo 'From foo@bar.com' > %s", fname);
- system (buffer);
+ xsystem (buffer);
+
f = fopen (fname, "r");
fseek (f, 0, SEEK_END);
o = ftello (f);
fseek (f, 0, SEEK_SET);
fflush (f);
snprintf (buffer, sizeof (buffer), "echo 'From bar@baz.edu' >> %s", fname);
- system (buffer);
+ xsystem (buffer);
+
fseek (f, o, SEEK_SET);
if (fgets (buffer, 1024, f) == NULL)
exit (1);
diff --git a/nptl/tst-cancel7.c b/nptl/tst-cancel7.c
index 7a1870ac74b23faa..338cecc8293638b0 100644
--- a/nptl/tst-cancel7.c
+++ b/nptl/tst-cancel7.c
@@ -41,6 +41,7 @@ tf (void *arg)
strcpy (stpcpy (stpcpy (cmd, command), args), pidfilename);
system (cmd);
+
/* This call should never return. */
return NULL;
}
diff --git a/nptl/tst-stackguard1.c b/nptl/tst-stackguard1.c
index cac492ec34808617..5b9d57a73327b3c8 100644
--- a/nptl/tst-stackguard1.c
+++ b/nptl/tst-stackguard1.c
@@ -29,6 +29,7 @@
#include <unistd.h>
#include <support/xunistd.h>
+#include <support/xstdlib.h>
static const char *command;
static bool child;
@@ -141,7 +142,8 @@ do_test (void)
dup2 (fds[1], 2);
close (fds[1]);
- system (command);
+ xsystem (command);
+
exit (0);
}
diff --git a/nss/tst-nss-db-endpwent.c b/nss/tst-nss-db-endpwent.c
index 5932a9800f33b717..d25033afabc01c30 100644
--- a/nss/tst-nss-db-endpwent.c
+++ b/nss/tst-nss-db-endpwent.c
@@ -23,6 +23,7 @@
#include <support/support.h>
#include <support/check.h>
+#include <support/xstdlib.h>
/* It is entirely allowed to start with a getpwent call without
resetting the state of the service via a call to setpwent.
@@ -55,7 +56,7 @@ do_test (void)
cmd = xasprintf ("%s/makedb -o /var/db/passwd.db /var/db/passwd.in",
support_bindir_prefix);
- system (cmd);
+ xsystem (cmd);
free (cmd);
try_it ();
diff --git a/support/Makefile b/support/Makefile
index 3b8509c88db4662a..47d5db4629b029d3 100644
--- a/support/Makefile
+++ b/support/Makefile
@@ -221,6 +221,7 @@ libsupport-routines = \
xstrndup \
xsymlink \
xsysconf \
+ xsystem \
xunlink \
xuselocale \
xwaitpid \
diff --git a/support/xstdlib.h b/support/xstdlib.h
new file mode 100644
index 0000000000000000..db5a5b9d4fd1fa71
--- /dev/null
+++ b/support/xstdlib.h
@@ -0,0 +1,31 @@
+/* Error-checking wrappers for stdlib functions.
+ Copyright (C) 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/>. */
+
+#ifndef SUPPORT_XSTDLIB_H
+#define SUPPORT_XSTDLIB_H
+
+#include <stdlib.h>
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+
+void xsystem (const char *cmd);
+
+__END_DECLS
+
+#endif /* SUPPORT_XSTDLIB_H */
diff --git a/support/xsystem.c b/support/xsystem.c
new file mode 100644
index 0000000000000000..1f558953bca8f5b2
--- /dev/null
+++ b/support/xsystem.c
@@ -0,0 +1,37 @@
+/* Error-checking replacement for "system".
+ Copyright (C) 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/>. */
+
+#include <support/support.h>
+#include <support/check.h>
+
+#include <support/xstdlib.h>
+
+void
+xsystem (const char *cmd)
+{
+ int ret = system (cmd);
+
+ if (ret == 0 && cmd == NULL)
+ FAIL_EXIT1 ("Unable to spawn a shell for NULL command");
+
+ if (ret == 127)
+ FAIL_EXIT1 ("Child terminated with status 127");
+
+ if (ret < 0)
+ FAIL_EXIT1 ("system (\"%s\")", cmd);
+}

291
glibc-RHEL-62716-2.patch Normal file
View File

@ -0,0 +1,291 @@
commit ff0320bec2810192d453c579623482fab87bfa01
Author: H.J. Lu <hjl.tools@gmail.com>
Date: Wed Jul 24 14:05:15 2024 -0700
Add mremap tests
Add tests for MREMAP_MAYMOVE and MREMAP_FIXED. On Linux, also test
MREMAP_DONTUNMAP.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Conflicts:
misc/Makefile (new test added)
sysdeps/unix/sysv/linux/Makefile (new test added)
diff --git a/misc/Makefile b/misc/Makefile
index ae244a72689ffb0a..5d6fc0f6824a734f 100644
--- a/misc/Makefile
+++ b/misc/Makefile
@@ -89,7 +89,9 @@ tests := tst-dirname tst-tsearch tst-fdset tst-mntent tst-hsearch \
tst-preadvwritev2 tst-preadvwritev64v2 tst-warn-wide \
tst-ldbl-warn tst-ldbl-error tst-dbl-efgcvt tst-ldbl-efgcvt \
tst-mntent-autofs tst-syscalls tst-mntent-escape tst-select \
- tst-ioctl
+ tst-ioctl \
+ tst-mremap1 \
+ tst-mremap2 \
tests-time64 := \
tst-select-time64 \
diff --git a/misc/tst-mremap1.c b/misc/tst-mremap1.c
new file mode 100644
index 0000000000000000..0469991a6c1438b6
--- /dev/null
+++ b/misc/tst-mremap1.c
@@ -0,0 +1,46 @@
+/* Test mremap with MREMAP_MAYMOVE.
+ 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 <errno.h>
+#include <sys/mman.h>
+#include <support/xstdlib.h>
+#include <support/xunistd.h>
+#include <support/check.h>
+#include <support/test-driver.h>
+
+static int
+do_test (void)
+{
+ size_t old_size = getpagesize ();
+ char *old_addr = xmmap (NULL, old_size, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1);
+ old_addr[0] = 1;
+ old_addr[old_size - 1] = 2;
+
+ /* Test MREMAP_MAYMOVE. */
+ size_t new_size = old_size + old_size;
+ char *new_addr = mremap (old_addr, old_size, new_size, MREMAP_MAYMOVE);
+ TEST_VERIFY_EXIT (new_addr != MAP_FAILED);
+ new_addr[0] = 1;
+ new_addr[new_size - 1] = 2;
+ xmunmap (new_addr, new_size);
+
+ return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/misc/tst-mremap2.c b/misc/tst-mremap2.c
new file mode 100644
index 0000000000000000..45be7f0369c2571e
--- /dev/null
+++ b/misc/tst-mremap2.c
@@ -0,0 +1,54 @@
+/* Test mremap with MREMAP_FIXED.
+ 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 <errno.h>
+#include <sys/mman.h>
+#include <support/xstdlib.h>
+#include <support/xunistd.h>
+#include <support/test-driver.h>
+#include <mremap-failure.h>
+
+static int
+do_test (void)
+{
+ size_t old_size = getpagesize ();
+ size_t new_size = old_size + old_size;
+ char *old_addr = xmmap (NULL, old_size, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1);
+ old_addr[0] = 1;
+ old_addr[old_size - 1] = 2;
+
+ char *fixed_addr = xmmap (NULL, new_size, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1);
+ fixed_addr[0] = 1;
+ fixed_addr[new_size - 1] = 2;
+
+ /* Test MREMAP_FIXED. */
+ char *new_addr = mremap (old_addr, old_size, new_size,
+ MREMAP_FIXED | MREMAP_MAYMOVE,
+ fixed_addr);
+ if (new_addr == MAP_FAILED)
+ return mremap_failure_exit (errno);
+ new_addr[0] = 1;
+ new_addr[new_size - 1] = 2;
+ xmunmap (new_addr, new_size);
+
+ return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/sysdeps/generic/mremap-failure.h b/sysdeps/generic/mremap-failure.h
new file mode 100644
index 0000000000000000..bc0d476368050c2c
--- /dev/null
+++ b/sysdeps/generic/mremap-failure.h
@@ -0,0 +1,25 @@
+/* mremap failure handling. Generic version.
+ 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/>. */
+
+/* Return exit value on mremap failure with errno ERR. */
+
+static int
+mremap_failure_exit (int err)
+{
+ return EXIT_FAILURE;
+}
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index 74656e56038844aa..8632bfe6eac31ff2 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -126,6 +126,7 @@ tests += tst-clone tst-clone2 tst-clone3 tst-fanotify tst-personality \
tst-scm_rights \
tst-getauxval \
tst-fdopendir-o_path \
+ tst-linux-mremap1 \
# tests
# Test for the symbol version of fcntl that was replaced in glibc 2.28.
diff --git a/sysdeps/unix/sysv/linux/mremap-failure.h b/sysdeps/unix/sysv/linux/mremap-failure.h
new file mode 100644
index 0000000000000000..c99ab30ca9ea796f
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/mremap-failure.h
@@ -0,0 +1,30 @@
+/* mremap failure handling. Linux version.
+ 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/check.h>
+
+/* Return exit value on mremap failure with errno ERR. */
+
+static int
+mremap_failure_exit (int err)
+{
+ if (err != EINVAL)
+ return EXIT_FAILURE;
+
+ return EXIT_UNSUPPORTED;
+}
diff --git a/sysdeps/unix/sysv/linux/tst-linux-mremap1.c b/sysdeps/unix/sysv/linux/tst-linux-mremap1.c
new file mode 100644
index 0000000000000000..408e8af2abe59033
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/tst-linux-mremap1.c
@@ -0,0 +1,63 @@
+/* Test mremap with MREMAP_DONTUNMAP.
+ 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 <errno.h>
+#include <sys/mman.h>
+#include <support/xstdlib.h>
+#include <support/xunistd.h>
+#include <support/check.h>
+#include <support/test-driver.h>
+#include <mremap-failure.h>
+
+static int
+do_test (void)
+{
+ size_t old_size = getpagesize ();
+ size_t new_size = old_size;
+ char *old_addr = xmmap (NULL, old_size, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1);
+ old_addr[0] = 1;
+ old_addr[old_size - 1] = 2;
+
+ /* Create an available 64-page mmap region. */
+ size_t fixed_size = old_size * 64;
+ char *fixed_addr = xmmap (NULL, fixed_size, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1);
+ xmunmap (fixed_addr, fixed_size);
+
+ /* Add 3 * pagesize. */
+ fixed_size += 3 * old_size;
+
+ /* Test MREMAP_DONTUNMAP. It should return FIXED_ADDR created above. */
+ char *new_addr = mremap (old_addr, old_size, new_size,
+ MREMAP_DONTUNMAP | MREMAP_MAYMOVE,
+ fixed_addr);
+ if (new_addr == MAP_FAILED)
+ return mremap_failure_exit (errno);
+ TEST_VERIFY_EXIT (fixed_addr == new_addr);
+ old_addr[0] = 3;
+ old_addr[old_size - 1] = 4;
+ new_addr[0] = 1;
+ new_addr[new_size - 1] = 2;
+ xmunmap (new_addr, new_size);
+ xmunmap (old_addr, old_size);
+
+ return 0;
+}
+
+#include <support/test-driver.c>

View File

@ -1069,6 +1069,8 @@ Patch761: glibc-RHEL-65358-4.patch
Patch762: glibc-RHEL-65358-5.patch
Patch763: glibc-RHEL-58989-1.patch
Patch764: glibc-RHEL-58989-2.patch
Patch765: glibc-RHEL-62716-1.patch
Patch766: glibc-RHEL-62716-2.patch
##############################################################################
# Continued list of core "glibc" package information:
@ -3064,6 +3066,7 @@ update_gconv_modules_cache ()
%changelog
* Fri Jan 10 2025 Frédéric Bérat <fberat@redhat.com> - 2.34-152
- Additional TLS test cases (RHEL-58989)
- Additional mremap test cases (RHEL-62716)
* Fri Jan 10 2025 Frédéric Bérat <fberat@redhat.com> - 2.34-151
- Lock all stdio streams during exit