From: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
To: Carlos Llamas <cmllamas@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
Vlastimil Babka <vbabka@suse.cz>, Jann Horn <jannh@google.com>,
Pedro Falcato <pfalcato@suse.de>,
kernel-team@android.com, linux-kernel@vger.kernel.org,
"open list:MEMORY MAPPING" <linux-mm@kvack.org>
Subject: Re: [PATCH] mm/mremap: fix regression in vrm->new_addr check
Date: Thu, 28 Aug 2025 06:38:09 +0100 [thread overview]
Message-ID: <8a4dc910-5237-48aa-8abb-a6d5044bc290@lucifer.local> (raw)
In-Reply-To: <20250828032653.521314-1-cmllamas@google.com>
On Thu, Aug 28, 2025 at 03:26:52AM +0000, Carlos Llamas wrote:
> Commit 3215eaceca87 ("mm/mremap: refactor initial parameter sanity
> checks") moved the sanity check for vrm->new_addr from mremap_to() to
> check_mremap_params().
>
> However, this caused a regression as vrm->new_addr is now checked even
> when MREMAP_FIXED and MREMAP_DONTUNMAP flags are not specified. In this
> case, vrm->new_addr can be garbage and create unexpected failures.
Yikes, sorry my mistake.
>
> Fix this by moving the new_addr check after the vrm_implies_new_addr()
> guard. This ensures that the new_addr is only checked when the user has
> specified one explicitly.
>
> Fixes: 3215eaceca87 ("mm/mremap: refactor initial parameter sanity checks")
> Signed-off-by: Carlos Llamas <cmllamas@google.com>
You need a Cc: Stable.
> ---
> mm/mremap.c | 11 +++++------
> 1 file changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/mm/mremap.c b/mm/mremap.c
> index e618a706aff5..692acb0f9ea2 100644
> --- a/mm/mremap.c
> +++ b/mm/mremap.c
> @@ -1771,18 +1771,17 @@ static unsigned long check_mremap_params(struct vma_remap_struct *vrm)
> * for DOS-emu "duplicate shm area" thing. But
> * a zero new-len is nonsensical.
> */
> - if (!vrm->new_len)
> - return -EINVAL;
Please don't refactor code at the same time, especially as this is a hotfix.
This line is associated with the above comment.
> -
> - /* Is the new length or address silly? */
> - if (vrm->new_len > TASK_SIZE ||
> - vrm->new_addr > TASK_SIZE - vrm->new_len)
> + if (!vrm->new_len || vrm->new_len > TASK_SIZE)
> return -EINVAL;
Yeah, it's cute but by removing the 'silly' comment you're making this
associated with the comment above and... yeah.
This should be:
/*
* We allow a zero old-len as a special case
* for DOS-emu "duplicate shm area" thing. But
* a zero new-len is nonsensical.
*/
if (!vrm->new_len)
return -EINVAL;
/* Is the new length silly? */
if (vrm->new_len > TASK_SIZE)
return -EINVAL;
>
> /* Remainder of checks are for cases with specific new_addr. */
> if (!vrm_implies_new_addr(vrm))
> return 0;
>
> + /* Is the new address silly? */
> + if (vrm->new_addr > TASK_SIZE - vrm->new_len)
> + return -EINVAL;
> +
Obviously this bit is fine :)
Sorry again, this was just a mistake on my part.
> /* The new address must be page-aligned. */
> if (offset_in_page(vrm->new_addr))
> return -EINVAL;
> --
> 2.51.0.268.g9569e192d0-goog
>
I'm curious why only you guys have seen it, a theory is bionic is sending random
stuff to this parameter when unspecified, and glibc is not.
But obviously this fix is correct, and the original code needs fixing.
Please respin a v2 as per above.
Cheers, Lorenzo
next prev parent reply other threads:[~2025-08-28 5:38 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-28 3:26 Carlos Llamas
2025-08-28 3:43 ` Liam R. Howlett
2025-08-28 4:06 ` Carlos Llamas
2025-08-28 4:16 ` Carlos Llamas
2025-08-28 5:38 ` Lorenzo Stoakes [this message]
2025-08-28 14:13 ` Carlos Llamas
2025-08-28 14:21 ` Vlastimil Babka
2025-08-28 14:22 ` Lorenzo Stoakes
2025-08-28 14:29 ` Carlos Llamas
2025-08-28 14:31 ` Vlastimil Babka
2025-08-28 14:26 ` [PATCH v2] " Carlos Llamas
2025-08-28 14:30 ` Vlastimil Babka
2025-08-28 14:34 ` Lorenzo Stoakes
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=8a4dc910-5237-48aa-8abb-a6d5044bc290@lucifer.local \
--to=lorenzo.stoakes@oracle.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=cmllamas@google.com \
--cc=jannh@google.com \
--cc=kernel-team@android.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=pfalcato@suse.de \
--cc=vbabka@suse.cz \
/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