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/20250305021711.3867874-3-jeffxu@google.com Signed-off-by: Jeff Xu <jeffxu@chromium.org> Reviewed-by: Kees Cook <kees@kernel.org> Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com> Cc: Adhemerval Zanella <adhemerval.zanella@linaro.org> Cc: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com> Cc: Alexey Dobriyan <adobriyan@gmail.com> Cc: Andrei Vagin <avagin@gmail.com> Cc: Anna-Maria Behnsen <anna-maria@linutronix.de> Cc: Ard Biesheuvel <ardb@kernel.org> Cc: Benjamin Berg <benjamin@sipsolutions.net> Cc: Christoph Hellwig <hch@lst.de> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: David Rientjes <rientjes@google.com> Cc: David S. Miller <davem@davemloft.net> Cc: Elliot Hughes <enh@google.com> Cc: Florian Faineli <f.fainelli@gmail.com> Cc: Greg Ungerer <gerg@kernel.org> Cc: Guenter Roeck <groeck@chromium.org> Cc: Heiko Carstens <hca@linux.ibm.com> Cc: Helge Deller <deller@gmx.de> Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jann Horn <jannh@google.com> Cc: Jason A. Donenfeld <jason@zx2c4.com> Cc: Johannes Berg <johannes@sipsolutions.net> Cc: Jorge Lucangeli Obes <jorgelo@chromium.org> Cc: Linus Waleij <linus.walleij@linaro.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Matthew Wilcow (Oracle) <willy@infradead.org> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Michal Hocko <mhocko@suse.com> Cc: Miguel Ojeda <ojeda@kernel.org> Cc: Mike Rapoport <mike.rapoport@gmail.com> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Pedro Falcato <pedro.falcato@gmail.com> Cc: Peter Xu <peterx@redhat.com> Cc: Randy Dunlap <rdunlap@infradead.org> Cc: Stephen Röttger <sroettger@google.com> Cc: Thomas Weißschuh <thomas.weissschuh@linutronix.de> Cc: Vlastimil Babka <vbabka@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 5796d39 commit 7b0141d

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

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)