Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Jeff Xu and committed by
Andrew Morton
7b0141da 5796d396

+43
+43
tools/testing/selftests/x86/test_mremap_vdso.c
··· 14 14 #include <errno.h> 15 15 #include <unistd.h> 16 16 #include <string.h> 17 + #include <stdbool.h> 17 18 18 19 #include <sys/mman.h> 19 20 #include <sys/auxv.h> ··· 56 55 57 56 } 58 57 58 + #define VDSO_NAME "[vdso]" 59 + #define VMFLAGS "VmFlags:" 60 + #define MSEAL_FLAGS "sl" 61 + #define MAX_LINE_LEN 512 62 + 63 + bool vdso_sealed(FILE *maps) 64 + { 65 + char line[MAX_LINE_LEN]; 66 + bool has_vdso = false; 67 + 68 + while (fgets(line, sizeof(line), maps)) { 69 + if (strstr(line, VDSO_NAME)) 70 + has_vdso = true; 71 + 72 + if (has_vdso && !strncmp(line, VMFLAGS, strlen(VMFLAGS))) { 73 + if (strstr(line, MSEAL_FLAGS)) 74 + return true; 75 + 76 + return false; 77 + } 78 + } 79 + 80 + return false; 81 + } 82 + 59 83 int main(int argc, char **argv, char **envp) 60 84 { 61 85 pid_t child; 86 + FILE *maps; 62 87 63 88 ksft_print_header(); 64 89 ksft_set_plan(1); 90 + 91 + maps = fopen("/proc/self/smaps", "r"); 92 + if (!maps) { 93 + ksft_test_result_skip( 94 + "Could not open /proc/self/smaps, errno=%d\n", 95 + errno); 96 + 97 + return 0; 98 + } 99 + 100 + if (vdso_sealed(maps)) { 101 + ksft_test_result_skip("vdso is sealed\n"); 102 + return 0; 103 + } 104 + 105 + fclose(maps); 65 106 66 107 child = fork(); 67 108 if (child == -1)