Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Sarthak Sharma <sarthak.sharma@arm.com>
To: Anshuman <anshumantewari123@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	David Hildenbrand <david@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>,
	linux-mm@kvack.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] selftests/mm: fix unchecked ftruncate return value in soft-dirty test
Date: Wed, 19 Aug 2026 09:34:39 +0530	[thread overview]
Message-ID: <9efc3c26-61fd-4bf4-bc0a-cb3e4b6120cc@arm.com> (raw)
In-Reply-To: <20260818133206.39503-1-anshumantewari123@gmail.com>



On 8/18/26 7:02 PM, Anshuman wrote:
> test_mprotect() calls ftruncate() to resize the backing file
> before mmap()'ing it, but never checks the return value. If
> ftruncate() fails, the file may remain shorter than the requested
> mapping size. The subsequent mmap() with MAP_SHARED can still
> succeed in this case, but the very next line writes directly into
> the mapped memory (*map = 1), which can trigger SIGBUS if the
> mapping extends beyond the actual file size.
> 
> Check the return value and fail cleanly with ksft_exit_fail_msg() if
> ftruncate() fails, matching the error-handling style already used
> for the mmap() call immediately below it.
> 
> Signed-off-by: Anshuman <anshumantewari123@gmail.com>
> ---

Looks good to me.

Reviewed-by: Sarthak Sharma <sarthak.sharma@arm.com>

>  tools/testing/selftests/mm/soft-dirty.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/mm/soft-dirty.c b/tools/testing/selftests/mm/soft-dirty.c
> index fb1864a68..a52ef79dd 100644
> --- a/tools/testing/selftests/mm/soft-dirty.c
> +++ b/tools/testing/selftests/mm/soft-dirty.c
> @@ -152,7 +152,8 @@ static void test_mprotect(int pagemap_fd, int pagesize, bool anon)
>  			return;
>  		}
>  		unlink(fname);
> -		ftruncate(test_fd, pagesize);
> +		if (ftruncate(test_fd, pagesize) != 0)
> +			ksft_exit_fail_msg("ftruncate failed\n");
>  		map = mmap(NULL, pagesize, PROT_READ|PROT_WRITE,
>  			   MAP_SHARED, test_fd, 0);
>  		if (map == MAP_FAILED)



  reply	other threads:[~2026-08-19  4:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-18 13:32 [PATCH] selftests/mm: fix unchecked ftruncate return value in soft-dirty test Anshuman
2026-08-19  4:04 ` Sarthak Sharma [this message]
2026-08-19 10:37   ` Anshuman Tewari

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=9efc3c26-61fd-4bf4-bc0a-cb3e4b6120cc@arm.com \
    --to=sarthak.sharma@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=anshumantewari123@gmail.com \
    --cc=david@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=shuah@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