mmap() in test_ra_error() is not checked for MAP_FAILED. On failure,
the subsequent write *paste_addr = 1 dereferences an invalid pointer
and segfaults. Add a FAIL_IF() check, consistent with the rest of the
function.

Fixes: 0f4ef8a3bf78 ("selftests/powerpc: Add test for real address error 
handling")
Signed-off-by: longlong yan <[email protected]>
---
 tools/testing/selftests/powerpc/mce/inject-ra-err.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/testing/selftests/powerpc/mce/inject-ra-err.c 
b/tools/testing/selftests/powerpc/mce/inject-ra-err.c
index 94323c34d9a6..0622fd814114 100644
--- a/tools/testing/selftests/powerpc/mce/inject-ra-err.c
+++ b/tools/testing/selftests/powerpc/mce/inject-ra-err.c
@@ -47,6 +47,7 @@ static int test_ra_error(void)
        FAIL_IF(sigaction(SIGBUS, &act, NULL) != 0);
 
        paste_addr = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 
0ULL);
+       FAIL_IF(paste_addr == MAP_FAILED);
 
        /* The following assignment triggers exception */
        mb();
-- 
2.43.0


Reply via email to