selftests/x86: test_shadow_stack: Check mmap return value
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")
Signed-off-by longlong yan <[email protected]>
--- tools/testing/selftests/x86/test_shadow_stack.c | 3 +++ 1 file changed, 3 insertions(+)
tools/testing/selftests/x86/test_shadow_stack.c +3 -0
@@ -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