mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Wei Yang <richard.weiyang@gmail.com>
To: Hongfu Li <lihongfu@kylinos.cn>
Cc: shuah@kernel.org, akpm@linux-foundation.org,
	reddybalavignesh9979@gmail.com, richard.weiyang@gmail.com,
	mic@digikod.net, sj@kernel.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] selftests/perf_events: Fix mmap() error check in sigtrap_threads
Date: Wed, 13 May 2026 08:55:01 +0000	[thread overview]
Message-ID: <20260513085501.lzljqdgzwanbqtr4@master> (raw)
In-Reply-To: <20260513025838.594945-1-lihongfu@kylinos.cn>

On Wed, May 13, 2026 at 10:58:38AM +0800, Hongfu Li wrote:
>In sigtrap_threads(), the return value of mmap() is checked against
>NULL.  mmap() returns MAP_FAILED, which is (void *)-1, not NULL, when
>it fails.  Since MAP_FAILED is non-zero and non-NULL, the condition
>"p == NULL" will never be true on failure, causing the program to
>proceed with an invalid pointer and segfault if mmap() actually fails
>under memory pressure.
>
>Signed-off-by: Hongfu Li <lihongfu@kylinos.cn>

Ah, looks you are right.

Reviewed-by: Wei Yang <richard.weiyang@gmail.com>

>---
> tools/testing/selftests/perf_events/watermark_signal.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/tools/testing/selftests/perf_events/watermark_signal.c b/tools/testing/selftests/perf_events/watermark_signal.c
>index 0f64b9b17081..a84709cabd8b 100644
>--- a/tools/testing/selftests/perf_events/watermark_signal.c
>+++ b/tools/testing/selftests/perf_events/watermark_signal.c
>@@ -102,7 +102,7 @@ TEST(watermark_signal)
> 	}
> 
> 	p = mmap(NULL, 2 * page_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
>-	if (p == NULL) {
>+	if (p == MAP_FAILED) {
> 		perror("mmap");
> 		goto cleanup;
> 	}
>-- 
>2.25.1

-- 
Wei Yang
Help you, Help me

      reply	other threads:[~2026-05-13  8:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-13  2:58 Hongfu Li
2026-05-13  8:55 ` Wei Yang [this message]

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=20260513085501.lzljqdgzwanbqtr4@master \
    --to=richard.weiyang@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=lihongfu@kylinos.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mic@digikod.net \
    --cc=reddybalavignesh9979@gmail.com \
    --cc=shuah@kernel.org \
    --cc=sj@kernel.org \
    /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

all inboxes | Powered by JetHome®