Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>
To: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Shakeel Butt <shakeel.butt@linux.dev>,
	Pedro Falcato <pfalcato@suse.de>,
	David Hildenbrand <david@kernel.org>,
	Jann Horn <jannh@google.com>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, Wupeng Ma <mawupeng1@huawei.com>,
	Ding Feng <dingf3ng@gmail.com>,
	Linux API <linux-api@vger.kernel.org>
Subject: Re: [PATCH] mm/msync: return -ENOMEM if page-aligned length overflows
Date: Fri, 20 Nov 2026 12:09:07 +0100	[thread overview]
Message-ID: <5b916aaa-cc04-4ad2-8008-04a57d8e83a7@kernel.org> (raw)
In-Reply-To: <20261120-msync-enomem-fix-v1-1-80282c8c5beb@kernel.org>

+cc linux-api

On 11/20/26 11:59, Lorenzo Stoakes (ARM) wrote:
> Currently the msync() system call will simply return 0 if you provide a
> length parameter which, when page-aligned (rounding up) overflows (i.e.
> SIZE_MAX - n, where n is in the range [0, PAGE_SIZE - 1).)

Weird, as if it was intended, but seems to be pre-git, so who knows why.

> This requires broken input, and nobody has complained about this, but for
> correctness this should really return -ENOMEM, so do so.

Right.

> Also, since error is assigned within the following loop, remove the
> unnecessary assignments prior to it.
> 
> Link: https://lore.kernel.org/linux-mm/20230321074035.1526157-5-mawupeng1@huawei.com/
> Reported-by: Ding Feng <dingf3ng@gmail.com>
> Closes: https://lore.kernel.org/linux-mm/20261120051413.46167-1-dingf3ng@gmail.com/
> Signed-off-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>

Acked-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>

> ---
>  mm/msync.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/mm/msync.c b/mm/msync.c
> index 90b491a27a14..ced41d3c2903 100644
> --- a/mm/msync.c
> +++ b/mm/msync.c
> @@ -46,14 +46,12 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags)
>  		goto out;
>  	if ((flags & MS_ASYNC) && (flags & MS_SYNC))
>  		goto out;
> -	error = -ENOMEM;
> +	if (!len)
> +		return 0;
>  	len = (len + ~PAGE_MASK) & PAGE_MASK;

ALIGN(PAGE_SIZE) or something?
But fair if out of scope.

>  	end = start + len;
> -	if (end < start)
> -		goto out;
> -	error = 0;
> -	if (end == start)
> -		goto out;
> +	if (end <= start)
> +		return -ENOMEM;
>  	/*
>  	 * If the interval [start,end) covers some unmapped address ranges,
>  	 * just ignore them, but return -ENOMEM at the end. Besides, if the
> 
> ---
> base-commit: d12eccbcb79a4fa35c3aa588eb79056af62eb859
> change-id: 20261120-msync-enomem-fix-95f830e305dd
> 
> Cheers,



      parent reply	other threads:[~2026-11-20 11:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 10:59 [PATCH] mm/msync: return -ENOMEM if page-aligned length overflows Lorenzo Stoakes (ARM)
2026-11-20 11:06 ` David Hildenbrand (Arm)
2026-11-20 11:09 ` Vlastimil Babka (SUSE) [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=5b916aaa-cc04-4ad2-8008-04a57d8e83a7@kernel.org \
    --to=vbabka@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=david@kernel.org \
    --cc=dingf3ng@gmail.com \
    --cc=jannh@google.com \
    --cc=liam@infradead.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mawupeng1@huawei.com \
    --cc=pfalcato@suse.de \
    --cc=shakeel.butt@linux.dev \
    --cc=surenb@google.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