Skip to contentSkip to conversation

selftests/x86: test_shadow_stack: Check mmap return value

PATCH New longlong yan 1 participant 1 message Jun 29

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

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

The return value of mmap() in test_32bit() is not checked. On failure mmap() returns MAP_FAILED, not NULL. If mmap() fails, the subsequent dereference of sa32->sa_flags causes a segfault.

Add a check for MAP_FAILED after mmap() and return 1 on failure, consistent with the existing error handling in the function.

Fixes 81f30337ef4f ("selftests/x86: Add shadow stack test")
---
 tools/testing/selftests/x86/test_shadow_stack.c | 3 +++
 1 file changed, 3 insertions(+)
tools/testing/selftests/x86/test_shadow_stack.c +3 -0
index 21af54d5f4ea..d56b0165b540 100644
@@ -706,6 +706,9 @@ int test_32bit(void)
 	/* Create sigaction in 32 bit address range */
 	sa32 = mmap(0, 4096, PROT_READ | PROT_WRITE,
 		    MAP_32BIT | MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+	if (sa32 == MAP_FAILED)
+		return 1;
+
 	sa32->sa_flags = SA_SIGINFO;
 
 	sa.sa_sigaction = segv_gp_handler;
Signature · 1 line
2.43.0