Skip to contentSkip to conversation

selftests/x86/fsgsbase: Check mmap return value

PATCH In review longlong yan 2 participants 2 messages Jul 9 – Jul 13

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/x86/fsgsbase: Check mmap return value

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")
---
 tools/testing/selftests/x86/fsgsbase.c | 2 ++
 1 file changed, 2 insertions(+)
tools/testing/selftests/x86/fsgsbase.c +2 -0
index 0a75252d31b6..6e4df4c2d0e9 100644
@@ -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();
Signature · 1 line
2.43.0
#1 lore raw

Hi, longlong

Quoted 7 lines

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")

Thank you for your patch.
I notice that the fix for this issue has already been addressed by my previous patch [1]. Could you please take a look?

[1] https://lore.kernel.org/all/[email protected]/

Best regards,
Hongfu