linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: Waiman Long <llong@redhat.com>
Cc: "André Almeida" <andrealmeid@igalia.com>,
	linux-kernel@vger.kernel.org,
	"Darren Hart" <dvhart@infradead.org>,
	"Davidlohr Bueso" <dave@stgolabs.net>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Juri Lelli" <juri.lelli@redhat.com>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Valentin Schneider" <vschneid@redhat.com>,
	"Borislav Petkov" <bp@alien8.de>,
	kernel-dev@igalia.com
Subject: Re: [PATCH] selftests/futex: Fix futex_numa_mpol's memory out of range subtest
Date: Thu, 28 Aug 2025 08:32:11 +0200	[thread overview]
Message-ID: <20250828063211.h-gpZAEb@linutronix.de> (raw)
In-Reply-To: <9d4c0d27-0ebd-4c6d-af38-d32ef420fde4@redhat.com>

On 2025-08-27 13:58:50 [-0400], Waiman Long wrote:
> On 8/27/25 11:44 AM, André Almeida wrote:
> > --- a/tools/testing/selftests/futex/functional/futex_numa_mpol.c
> > +++ b/tools/testing/selftests/futex/functional/futex_numa_mpol.c
> > @@ -168,6 +168,17 @@ int main(int argc, char *argv[])
> >   	ksft_set_plan(1);
> >   	mem_size = sysconf(_SC_PAGE_SIZE);
> > +
> > +	/*
> > +	 * The "Memory out of range" test depends on having a pointer to an
> > +	 * invalid address. To make this test deterministic, and to not depend
> > +	 * on the memory layout of the process, create a "buffer zone" with
> > +	 * PROT_NONE just before the valid memory (*futex_ptr).
> > +	 */
> > +	buffer_zone = mmap(NULL, mem_size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
> > +	if (buffer_zone == MAP_FAILED)
> > +		ksft_exit_fail_msg("mmap() for %d bytes failed\n", mem_size);
> > +
> >   	futex_ptr = mmap(NULL, mem_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
> >   	if (futex_ptr == MAP_FAILED)
> >   		ksft_exit_fail_msg("mmap() for %d bytes failed\n", mem_size);
> 
> This patch makes the assumption that consecutive mmap() calls will allocate
> pages consecutively downward from a certain address. I don't know if this
> assumption will be valid in all cases. I think it will be safer to just
> allocate the 2-page memory block and then change the 2nd page protection to
> PROT_NONE to make it a guard page.

You shouldn't make any assumption about mmap()'s returned pointer unless
you pass it as the addr argument and expect it to be followed.
Using two pages and making the second a guard page sounds sane.

> Cheers,
> Longman

Sebastian

  reply	other threads:[~2025-08-28  6:32 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-27 15:44 [PATCH] selftests/futex: Fix futex_numa_mpol's memory out of range subtest André Almeida
2025-08-27 17:58 ` Waiman Long
2025-08-28  6:32   ` Sebastian Andrzej Siewior [this message]
2025-08-28 18:06   ` André Almeida
2025-08-28 18:20     ` Sebastian Andrzej Siewior
2025-08-28 18:47       ` Waiman Long
2025-08-29  2:22       ` André Almeida
2025-08-29  6:16         ` Sebastian Andrzej Siewior
2025-08-29 10:07           ` Borislav Petkov
2025-09-01 12:49             ` André Almeida
2025-09-01 13:57               ` Borislav Petkov

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=20250828063211.h-gpZAEb@linutronix.de \
    --to=bigeasy@linutronix.de \
    --cc=andrealmeid@igalia.com \
    --cc=bp@alien8.de \
    --cc=dave@stgolabs.net \
    --cc=dvhart@infradead.org \
    --cc=juri.lelli@redhat.com \
    --cc=kernel-dev@igalia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llong@redhat.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=vschneid@redhat.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;
as well as URLs for NNTP newsgroup(s).