From: Marco Vanotti <mvanotti@google.com>
To: Brian Geffon <bgeffon@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] mremap: Fix new_addr being used as a hint with MREMAP_DONTUNMAP
Date: Fri, 6 Dec 2024 12:34:43 -0300 [thread overview]
Message-ID: <CADMPHGvA+6A+eRG74Xqx5rnLUvq7CFu=p5+YhEfN6oS=S_g6wQ@mail.gmail.com> (raw)
In-Reply-To: <20241206152032.1222067-2-bgeffon@google.com>
[-- Attachment #1: Type: text/plain, Size: 2817 bytes --]
On Fri, Dec 6, 2024 at 12:20 PM Brian Geffon <bgeffon@google.com> wrote:
>
> Two non-mutually exclusive paths can land in mremap_to, MREMAP_FIXED
> and MREMAP_DONTUNMAP which are called from mremap(). In the case of
> MREMAP_FIXED we must validate the new_addr to ensure that the new
> address is valid. In the case of MREMAP_DONTUNMAP without MREMAP_FIXED
> a new address is specified as a hint, just like it would be in the
> case of mmap. In this second case we don't need to perform any checks
> because get_unmapped_area() will align new_addr, just like it would in
> the case of mmap.
>
> Signed-off-by: Brian Geffon <bgeffon@google.com>
> Reported-by: Marco Vanotti <mvanotti@google.com>
> ---
> mm/mremap.c | 26 +++++++++++++++++++-------
> 1 file changed, 19 insertions(+), 7 deletions(-)
>
> diff --git a/mm/mremap.c b/mm/mremap.c
> index 60473413836b..286ffdb883df 100644
> --- a/mm/mremap.c
> +++ b/mm/mremap.c
> @@ -912,15 +912,27 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
> unsigned long ret;
> unsigned long map_flags = 0;
>
> - if (offset_in_page(new_addr))
> - return -EINVAL;
> + /*
> + * Two non-mutually exclusive paths can land in mremap_to, MREMAP_FIXED
> + * and MREMAP_DONTUNMAP which are called from mremap(). In the case of
> + * MREMAP_FIXED we must validate the new_addr to ensure that the new
> + * address is valid. In the case of MREMAP_DONTUNMAP without MREMAP_FIXED
> + * a new address is specified as a hint, just like it would be in the
> + * case of mmap. In this second case we don't need to perform any checks
> + * because get_unmapped_area() will align new_addr, just like it would in
> + * the case of mmap.
> + */
A few lines below we also check for MREMAP_FIXED before calling
do_unmap, can't we do the validation there?
> + if (flags & MREMAP_FIXED) {
> + if (offset_in_page(new_addr))
> + return -EINVAL;
>
> - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
> - return -EINVAL;
> + if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
> + return -EINVAL;
>
> - /* Ensure the old/new locations do not overlap */
> - if (addr + old_len > new_addr && new_addr + new_len > addr)
> - return -EINVAL;
> + /* Ensure the old/new locations do not overlap */
> + if (addr + old_len > new_addr && new_addr + new_len > addr)
> + return -EINVAL;
> + }
>
> /*
> * move_vma() need us to stay 4 maps below the threshold, otherwise
> --
> 2.47.0.338.g60cca15819-goog
>
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 5294 bytes --]
next prev parent reply other threads:[~2024-12-06 15:35 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-06 15:20 [PATCH 0/2] mremap: Fix newaddr " Brian Geffon
2024-12-06 15:20 ` [PATCH 1/2] mremap: Fix new_addr being used as a " Brian Geffon
2024-12-06 15:34 ` Marco Vanotti [this message]
2024-12-06 15:39 ` Brian Geffon
2024-12-06 15:20 ` [PATCH 2/2] selftests: mm: Add a new MREMAP_DONTUNMAP self test Brian Geffon
2024-12-06 18:42 ` [PATCH 0/2] mremap: Fix newaddr hint with MREMAP_DONTUNMAP Jann Horn
2024-12-06 18:52 ` Lorenzo Stoakes
2024-12-09 2:28 ` Brian Geffon
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='CADMPHGvA+6A+eRG74Xqx5rnLUvq7CFu=p5+YhEfN6oS=S_g6wQ@mail.gmail.com' \
--to=mvanotti@google.com \
--cc=akpm@linux-foundation.org \
--cc=bgeffon@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.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