Re: [PATCH] mm/gup: fault in ranges that start at address 0

From: David Hildenbrand (Arm)

Date: Wed Nov 25 2026 - 17:51:31 EST


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@xxxxxxxxxxxxxxx # v6.16
> Signed-off-by: Hengyu Liang <hengyul@xxxxxxxxxx>
> ---
> 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