Re: [PATCH] selftests/prctl: Fix non-anonymous VMA mapping in set-anon-vma-name test

Andrew Morton <[email protected]> Mon, 3 Aug 2026 14:09:24 -0700
Newsgroups org.kernel.vger.linux-kselftest,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
On Mon,  3 Aug 2026 18:30:46 +0800 Hongfu Li <[email protected]> wrote:

> The test creates a non-anonymous VMA (ptr_not_anon) via mmap() with
> MAP_PRIVATE but without MAP_ANONYMOUS, using fd=0 (stdin) as the file
> descriptor.  This always fails because fd=0 is not a regular file,
> and the failure was hidden because ASSERT_NE() incorrectly checked
> for NULL instead of MAP_FAILED.

It's remarkable how often code assumes that mmap(...)==NULL is the
error return.

> Fix by using mkstemp() + ftruncate() to create a real temporary file,
> then mapping it with MAP_PRIVATE to obtain a genuine file-backed VMA.
> Also fix the mmap() error checks to use MAP_FAILED instead of NULL,
> and pass fd=-1 for the anonymous mapping for clarity.  The temp file
> is unlinked immediately so it does not persist on disk.

Thanks.

AI review found one glitch which I don't think we need to care about:
	https://sashiko.dev/#/patchset/[email protected]

and one possible pre-existing issue which is kinda related and which
you may choose to address.  Please take a look and let us know?