From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Hengyu Liang <hengyul@cs.unc.edu>,
Andrew Morton <akpm@linux-foundation.org>
Cc: Baoquan He <baoquan.he@linux.dev>, Jason Gunthorpe <jgg@ziepe.ca>,
John Hubbard <jhubbard@nvidia.com>, Peter Xu <peterx@redhat.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH] mm/gup: fault in ranges that start at address 0
Date: Wed, 25 Nov 2026 23:51:21 +0100 [thread overview]
Message-ID: <f5ff8f43-c75c-4b19-b683-fdff0c6dd7ae@kernel.org> (raw)
In-Reply-To: <20261125173202.3636133-1-hengyul@cs.unc.edu>
On 11/25/26 18:32, Hengyu Liang wrote:
> Commit a7797e74bd39 ("mm/gup: clean up codes in fault_in_xxx()
> functions") made the loops of fault_in_readable(), fault_in_writeable()
> and fault_in_safe_writeable() stop when the current address is 0, to
> detect an overflow.
>
> However, the loops then do not run at all for a range that starts at
> address 0, and the functions report that nothing was faulted in. As of
> now, a write() from a buffer at address 0 fails with EFAULT when the
> page is mapped but not present yet.
>
> The issue can be reproduced with this program, run as root:
>
> #include <fcntl.h>
> #include <stdio.h>
> #include <sys/mman.h>
> #include <unistd.h>
>
> int main(void)
> {
> int fd = open("file", O_WRONLY | O_CREAT, 0644);
>
> mmap(NULL, 4096, PROT_READ | PROT_WRITE,
> MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
> printf("%zd\n", write(fd, NULL, 7));
> return 0;
> }
Thanks for the report.
Ah, so we require root, because usually we have vm.mmap_min_addr limits in place.
Where we disallow mapping to address 0 for good reasons ;)
>
> Before commit a7797e74bd39 ("mm/gup: clean up codes in fault_in_xxx()
> functions"), the result is:
>
> 7
>
> After that commit, the result is:
>
> -1
>
> With this patch, the result is the same as before that commit.
>
> This patch will stop the loops when the current address is below the
> start address instead, which is only the case after an overflow.
>
> Fixes: a7797e74bd39 ("mm/gup: clean up codes in fault_in_xxx() functions")
> Cc: stable@vger.kernel.org # v6.16
> Signed-off-by: Hengyu Liang <hengyul@cs.unc.edu>
> ---
> I found this while comparing the behavior of different kernel versions.
> I used an LLM to analyze the problem and to draft the patch and this
> message, and I analyzed the result myself.
Okay, but you did not actually run into this yourself, right?
Doing some research, mapping to address 0 should not really have any users.
There are some legacy dosem and wine emulators, but looks like that's only a
problem for 32bit and all legacy.
Likely this is "nobody cares" and we don't need CC stable.
>
> Tested on v7.4-rc3 with KASAN and lockdep: with the buffer at address 0
> and at 0x10000, on ext4, tmpfs and xfs, write(), pwritev() and O_DIRECT
> reads and writes give the same results as before commit a7797e74bd39.
>
> mm/gup.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/mm/gup.c b/mm/gup.c
> index 2b405cce2ca5..a174e93327e9 100644
> --- a/mm/gup.c
> +++ b/mm/gup.c
> @@ -2074,7 +2074,7 @@ size_t fault_in_writeable(char __user *uaddr, size_t size)
> return size;
>
> /* Stop once we overflow to 0. */
These comments are not really correct anymore. We don't stop once we overflow to
0 anymore.
Likely we want to be more careful when calcualting+handling end instead.
--
Cheers,
David
prev parent reply other threads:[~2026-11-25 22:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 17:32 [PATCH] mm/gup: fault in ranges that start at address 0 Hengyu Liang
2026-11-25 22:51 ` David Hildenbrand (Arm) [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=f5ff8f43-c75c-4b19-b683-fdff0c6dd7ae@kernel.org \
--to=david@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=baoquan.he@linux.dev \
--cc=hengyul@cs.unc.edu \
--cc=jgg@ziepe.ca \
--cc=jhubbard@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=peterx@redhat.com \
--cc=stable@vger.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