* [PATCH] mm/msync: return -ENOMEM if page-aligned length overflows @ 2026-11-20 10:59 Lorenzo Stoakes (ARM) 2026-11-20 11:06 ` David Hildenbrand (Arm) 2026-11-20 11:09 ` Vlastimil Babka (SUSE) 0 siblings, 2 replies; 4+ messages in thread From: Lorenzo Stoakes (ARM) @ 2026-11-20 10:59 UTC (permalink / raw) To: Liam R. Howlett, Suren Baghdasaryan, Vlastimil Babka, Shakeel Butt, Pedro Falcato, David Hildenbrand, Jann Horn, Andrew Morton Cc: linux-mm, Wupeng Ma, Ding Feng, ljs 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).) This requires broken input, and nobody has complained about this, but for correctness this should really return -ENOMEM, so do so. 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> --- 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; 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, -- Lorenzo Stoakes (ARM) <ljs@kernel.org> ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/msync: return -ENOMEM if page-aligned length overflows 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) 1 sibling, 0 replies; 4+ messages in thread From: David Hildenbrand (Arm) @ 2026-11-20 11:06 UTC (permalink / raw) To: Lorenzo Stoakes (ARM), Liam R. Howlett, Suren Baghdasaryan, Vlastimil Babka, Shakeel Butt, Pedro Falcato, Jann Horn, Andrew Morton Cc: linux-mm, Wupeng Ma, Ding Feng 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).) > > This requires broken input, and nobody has complained about this, but for > correctness this should really return -ENOMEM, so do so. > > 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> Reviewed-by: David Hildenbrand (Arm) <david@kernel.org> -- Cheers, David ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/msync: return -ENOMEM if page-aligned length overflows 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) 2026-11-20 11:15 ` Lorenzo Stoakes (ARM) 1 sibling, 1 reply; 4+ messages in thread From: Vlastimil Babka (SUSE) @ 2026-11-20 11:09 UTC (permalink / raw) To: Lorenzo Stoakes (ARM), Liam R. Howlett, Suren Baghdasaryan, Shakeel Butt, Pedro Falcato, David Hildenbrand, Jann Horn, Andrew Morton Cc: linux-mm, Wupeng Ma, Ding Feng, Linux API +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, ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/msync: return -ENOMEM if page-aligned length overflows 2026-11-20 11:09 ` Vlastimil Babka (SUSE) @ 2026-11-20 11:15 ` Lorenzo Stoakes (ARM) 0 siblings, 0 replies; 4+ messages in thread From: Lorenzo Stoakes (ARM) @ 2026-11-20 11:15 UTC (permalink / raw) To: Vlastimil Babka (SUSE) Cc: Liam R. Howlett, Suren Baghdasaryan, Shakeel Butt, Pedro Falcato, David Hildenbrand, Jann Horn, Andrew Morton, linux-mm, Wupeng Ma, Ding Feng, Linux API On Fri, Nov 20, 2026 at 12:09:07PM +0100, Vlastimil Babka (SUSE) wrote: > +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. Yeah, likely unintended but doesn't really matter. I'd like us to completely centralise these kinds of checks for mm syscalls but on the laterbase... > > > 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> Thanks! > > > --- > > 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. Yeah can do on respin if needed, but right now I have more deletions than insertions which is rare for me so :P (maybe not the best reasoning, but still ;) > > > 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, > -- Cheers, Lorenzo ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-20 11:15 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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) 2026-11-20 11:15 ` Lorenzo Stoakes (ARM)
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox