LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: longlong yan <yanlonglong@kylinos.cn>
To: maddy@linux.ibm.com, mpe@ellerman.id.au
Cc: npiggin@gmail.com, chleroy@kernel.org, ganeshgr@linux.ibm.com,
	linuxppc-dev@lists.ozlabs.org, linux-kselftest@vger.kernel.org,
	longlong yan <yanlonglong@kylinos.cn>
Subject: [PATCH] selftests/powerpc: Check mmap return value in inject-ra-err
Date: Thu,  9 Jul 2026 20:49:18 +0800	[thread overview]
Message-ID: <20260709124919.616-1-yanlonglong@kylinos.cn> (raw)

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 <yanlonglong@kylinos.cn>
---
 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	other threads:[~2026-07-10  0:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260709124919.616-1-yanlonglong@kylinos.cn \
    --to=yanlonglong@kylinos.cn \
    --cc=chleroy@kernel.org \
    --cc=ganeshgr@linux.ibm.com \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox