mmap() in main() returns MAP_FAILED on error, but the return value is
not checked. Subsequent dereferences of shared_scratch (e.g. in
test_ptrace_write_gsbase) would segfault. Add a MAP_FAILED check using
err(), consistent with the rest of the file.
Fixes: 697096b14444 ("selftests/x86/fsgsbase: Fix some test case bugs")
Signed-off-by: longlong yan <[email protected]>
---
tools/testing/selftests/x86/fsgsbase.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tools/testing/selftests/x86/fsgsbase.c
b/tools/testing/selftests/x86/fsgsbase.c
index 0a75252d31b6..6e4df4c2d0e9 100644
--- a/tools/testing/selftests/x86/fsgsbase.c
+++ b/tools/testing/selftests/x86/fsgsbase.c
@@ -572,6 +572,8 @@ int main()
shared_scratch = mmap(NULL, 4096, PROT_READ | PROT_WRITE,
MAP_ANONYMOUS | MAP_SHARED, -1, 0);
+ if (shared_scratch == MAP_FAILED)
+ err(1, "mmap");
/* Do these tests before we have an LDT. */
test_ptrace_write_gs_read_base();
--
2.43.0