x86: Move CET infrastructure to x86_64
[glibc.git] / sysdeps / unix / sysv / linux / x86_64 / tst-cet-vfork-1.c
blob56d77530aecb16869430b9daa245cafde29537a5
1 /* Verify that child of the vfork-calling function can't return when
2 shadow stack is in use.
3 Copyright (C) 2020-2024 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
20 #include <stdio.h>
21 #include <unistd.h>
22 #include <errno.h>
23 #include <sys/types.h>
24 #include <sys/wait.h>
25 #include <x86intrin.h>
26 #include <support/test-driver.h>
28 __attribute__ ((noclone, noinline))
29 static void
30 do_test_1 (void)
32 pid_t p1;
34 /* NB: Since child return pops shadow stack which is shared with
35 parent, child must not return after vfork. */
37 if ((p1 = vfork ()) == 0)
39 /* Child return should trigger SIGSEGV due to shadow stack
40 mismatch. */
41 return;
43 else if (p1 == -1)
45 puts ("vfork failed");
46 _exit (EXIT_FAILURE);
49 int r;
50 if (TEMP_FAILURE_RETRY (waitpid (p1, &r, 0)) != p1)
52 puts ("waitpid failed");
53 _exit (EXIT_FAILURE);
56 if (!WIFSIGNALED (r) || WTERMSIG (r) != SIGSEGV)
58 puts ("Child not terminated with SIGSEGV");
59 _exit (EXIT_FAILURE);
62 /* Parent exits immediately so that parent returns without triggering
63 SIGSEGV when shadow stack is in use. */
64 _exit (EXIT_SUCCESS);
67 static int
68 do_test (void)
70 /* NB: This test should trigger SIGSEGV with shadow stack enabled. */
71 if (_get_ssp () == 0)
72 return EXIT_UNSUPPORTED;
73 do_test_1 ();
74 /* Child exits immediately so that child returns without triggering
75 SIGSEGV when shadow stack is in use. */
76 _exit (EXIT_FAILURE);
79 #include <support/test-driver.c>