Skip to content

Commit 7b0141d

Browse files
peaktocreekakpm00
authored andcommitted
selftests: x86: test_mremap_vdso: skip if vdso is msealed
Add code to detect if the vdso is memory sealed, skip the test if it is. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Jeff Xu <[email protected]> Reviewed-by: Kees Cook <[email protected]> Reviewed-by: Lorenzo Stoakes <[email protected]> Reviewed-by: Liam R. Howlett <[email protected]> Cc: Adhemerval Zanella <[email protected]> Cc: Alexander Mikhalitsyn <[email protected]> Cc: Alexey Dobriyan <[email protected]> Cc: Andrei Vagin <[email protected]> Cc: Anna-Maria Behnsen <[email protected]> Cc: Ard Biesheuvel <[email protected]> Cc: Benjamin Berg <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Dave Hansen <[email protected]> Cc: David Rientjes <[email protected]> Cc: David S. Miller <[email protected]> Cc: Elliot Hughes <[email protected]> Cc: Florian Faineli <[email protected]> Cc: Greg Ungerer <[email protected]> Cc: Guenter Roeck <[email protected]> Cc: Heiko Carstens <[email protected]> Cc: Helge Deller <[email protected]> Cc: Hyeonggon Yoo <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jann Horn <[email protected]> Cc: Jason A. Donenfeld <[email protected]> Cc: Johannes Berg <[email protected]> Cc: Jorge Lucangeli Obes <[email protected]> Cc: Linus Waleij <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Matthew Wilcow (Oracle) <[email protected]> Cc: Michael Ellerman <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Miguel Ojeda <[email protected]> Cc: Mike Rapoport <[email protected]> Cc: Oleg Nesterov <[email protected]> Cc: Pedro Falcato <[email protected]> Cc: Peter Xu <[email protected]> Cc: Randy Dunlap <[email protected]> Cc: Stephen Röttger <[email protected]> Cc: Thomas Weißschuh <[email protected]> Cc: Vlastimil Babka <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 5796d39 commit 7b0141d

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tools/testing/selftests/x86/test_mremap_vdso.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <errno.h>
1515
#include <unistd.h>
1616
#include <string.h>
17+
#include <stdbool.h>
1718

1819
#include <sys/mman.h>
1920
#include <sys/auxv.h>
@@ -55,13 +56,55 @@ static int try_to_remap(void *vdso_addr, unsigned long size)
5556

5657
}
5758

59+
#define VDSO_NAME "[vdso]"
60+
#define VMFLAGS "VmFlags:"
61+
#define MSEAL_FLAGS "sl"
62+
#define MAX_LINE_LEN 512
63+
64+
bool vdso_sealed(FILE *maps)
65+
{
66+
char line[MAX_LINE_LEN];
67+
bool has_vdso = false;
68+
69+
while (fgets(line, sizeof(line), maps)) {
70+
if (strstr(line, VDSO_NAME))
71+
has_vdso = true;
72+
73+
if (has_vdso && !strncmp(line, VMFLAGS, strlen(VMFLAGS))) {
74+
if (strstr(line, MSEAL_FLAGS))
75+
return true;
76+
77+
return false;
78+
}
79+
}
80+
81+
return false;
82+
}
83+
5884
int main(int argc, char **argv, char **envp)
5985
{
6086
pid_t child;
87+
FILE *maps;
6188

6289
ksft_print_header();
6390
ksft_set_plan(1);
6491

92+
maps = fopen("/proc/self/smaps", "r");
93+
if (!maps) {
94+
ksft_test_result_skip(
95+
"Could not open /proc/self/smaps, errno=%d\n",
96+
errno);
97+
98+
return 0;
99+
}
100+
101+
if (vdso_sealed(maps)) {
102+
ksft_test_result_skip("vdso is sealed\n");
103+
return 0;
104+
}
105+
106+
fclose(maps);
107+
65108
child = fork();
66109
if (child == -1)
67110
ksft_exit_fail_msg("failed to fork (%d): %m\n", errno);

0 commit comments

Comments
 (0)