Skip to contentSkip to conversation

mm/nommu: Reject wrapping ranges in access_remote_vm()

PATCH Applied Anastasios Papagiannis 5 participants 9 messages Sep 9 – Sep 28

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/nommu: Reject wrapping ranges in access_remote_vm()

The NOMMU implementation of access_process_vm() rejects address ranges whose end wraps around, but access_remote_vm() bypasses this check even though both functions delegate to __access_remote_vm().

Move the wraparound check into __access_remote_vm() so it applies to both entry points.

This is originally reported in [1].

[1] https://lore.kernel.org/bpf/4ef240a5bea36ff84df9589671367832860795159386a4c8fba546a0fa8b786f@mail.kernel.org/

Fixes f55f199b7d76 ("NOMMU: implement access_remote_vm")
---
 mm/nommu.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
mm/nommu.c +3 -3
index 498e01ee40b0..ed44510e3770 100644
@@ -1674,6 +1674,9 @@ static int __access_remote_vm(struct mm_struct *mm, unsigned long addr,
 	struct vm_area_struct *vma;
 	int write = gup_flags & FOLL_WRITE;
 
+	if (addr + len < addr)
+		return 0;
+
 	if (mmap_read_lock_killable(mm))
 		return 0;
 
@@ -1727,9 +1730,6 @@ int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, in
 {
 	struct mm_struct *mm;
 
-	if (addr + len < addr)
-		return 0;
-
 	mm = get_task_mm(tsk);
 	if (!mm)
 		return 0;

base-commit: 0d9ff90a5422cc7509258aaaba1e7481df4d332a

Signature · 1 line
2.55.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Using vma->vm_file as a proxy to check whether a VMA is anonymous or file-backed. --

commit 35aeff0bf93ec8eeae453b43c1f6540a0d793165
Author: Anastasios Papagiannis <[email protected]>

mm/nommu: Reject wrapping ranges in access_remote_vm()

The NOMMU implementation of access_process_vm() rejects address ranges whose end wraps around, but access_remote_vm() bypasses this check even though both functions delegate to __access_remote_vm().

Move the wraparound check into __access_remote_vm() so it applies to both entry points.

mm/nommu.c

Quoted 4 lines
mm/nommu.c +0 -0
index 498e01ee40b05..ed44510e37707 100644

[ ... ]

This isn't a bug introduced by this patch, but while reviewing mm/nommu.c, I noticed a pre-existing issue regarding VMA classification:

Quoted 6 lines
	/* clear anonymous mappings that don't ask for uninitialized data */
	if (!vma->vm_file &&
	    (!IS_ENABLED(CONFIG_MMAP_ALLOW_UNINITIALIZED) ||
	     !(flags & MAP_UNINITIALIZED)))
		memset((void *)region->vm_start, 0,
		       region->vm_end - region->vm_start);

[Severity: High]
Does this code in do_mmap() rely on vma->vm_file to check if a VMA is anonymous?

If a driver sets the VMA as anonymous (e.g., via vma_set_anonymous()) but leaves vma->vm_file set, the check relying on !vma->vm_file will fail. Could this skip the memset and leave kmalloc'd memory uninitialized, exposing kernel memory to userspace?

The MM VMA guidelines suggest the correct test is vma_is_anonymous(vma).

This same pre-existing pattern appears in split_vma():

Quoted 4 lines
	/* we're only permitted to split anonymous regions (these should have
	 * only a single usage on the region) */
	if (vma->vm_file)
		return -ENOMEM;

[Severity: High]
Could this incorrectly prevent the splitting of anonymous VMAs that happen to have a vm_file set by returning -ENOMEM?

And similarly in do_munmap():

Quoted 5 lines
	/* we're allowed to split an anonymous VMA but not a file-backed one */
	if (vma->vm_file) {
		do {
			if (start > vma->vm_start)
				return -EINVAL;

[Severity: High]
Does this incorrectly classify the VMA during unmap, applying file-backed rules to anonymous VMAs that still have a vm_file, leading to -EINVAL errors?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer
#2 lore raw
In reply to Anastasios Papagiannis
Quoted 6 lines · On Wed, 9 Sep 2026 09:42:31 +0300 Anastasios Papagiannis…

The NOMMU implementation of access_process_vm() rejects address ranges whose end wraps around, but access_remote_vm() bypasses this check even though both functions delegate to __access_remote_vm().

Move the wraparound check into __access_remote_vm() so it applies to both entry points.

lgtm, thanks.

Quoted 3 lines

This is originally reported in [1].

[1] https://lore.kernel.org/bpf/4ef240a5bea36ff84df9589671367832860795159386a4c8fba546a0fa8b786f@mail.kernel.org/

Ah, bpfbot scored one.

Sashiko might have found more issues in there:

	https://sashiko.dev/#/patchset/[email protected]

I'll optimistically cc Hajime Tazaki, who has been doing some NOMMU work recently.

Quoted 31 lines
Fixes f55f199b7d76 ("NOMMU: implement access_remote_vm")
---
 mm/nommu.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
mm/nommu.c +3 -3
index 498e01ee40b0..ed44510e3770 100644
@@ -1674,6 +1674,9 @@ static int __access_remote_vm(struct mm_struct *mm, unsigned long addr,
 	struct vm_area_struct *vma;
 	int write = gup_flags & FOLL_WRITE;
 
+	if (addr + len < addr)
+		return 0;
+
 	if (mmap_read_lock_killable(mm))
 		return 0;
 
@@ -1727,9 +1730,6 @@ int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, in
 {
 	struct mm_struct *mm;
 
-	if (addr + len < addr)
-		return 0;
-
 	mm = get_task_mm(tsk);
 	if (!mm)
 		return 0;
#3 lore raw

Hello,

Quoted 16 lines · Andrew Morton
Quoted 6 lines · On Wed, 9 Sep 2026 09:42:31 +0300 Anastasios Papagiannis…

The NOMMU implementation of access_process_vm() rejects address ranges whose end wraps around, but access_remote_vm() bypasses this check even though both functions delegate to __access_remote_vm().

Move the wraparound check into __access_remote_vm() so it applies to both entry points.

lgtm, thanks.

Quoted 3 lines

This is originally reported in [1].

[1] https://lore.kernel.org/bpf/4ef240a5bea36ff84df9589671367832860795159386a4c8fba546a0fa8b786f@mail.kernel.org/

Quoted 7 lines

Ah, bpfbot scored one.

Sashiko might have found more issues in there:

	https://sashiko.dev/#/patchset/[email protected]

I'll optimistically cc Hajime Tazaki, who has been doing some NOMMU work recently.

I got a similar review (from Sashiko) that current use of !vma->vm_file isn't appropriate and should use vma_set_anonymous(). IIUC that case happens only (I may miss something) with /dev/zero (via mmap_zero_prepare()).

I also had a patch but am currently waiting for Lorenzo's input for his work on /dev/zero, which mentioned in his reply.

https://lore.kernel.org/linux-mm/an8BlTgk7sc5vFJ1@lucifer/

Thus 3 comments of Sashiko (all about vma->vm_file) can be addressed in future, and are not needed an immediate fix.

I wish to ask this to Lorenzo too.

-- Hajime

#4 lore raw
Quoted 26 lines · Hajime Tazaki

Hello,

Quoted 21 lines · Andrew Morton
Quoted 6 lines · On Wed, 9 Sep 2026 09:42:31 +0300 Anastasios Papagiannis…

The NOMMU implementation of access_process_vm() rejects address ranges whose end wraps around, but access_remote_vm() bypasses this check even though both functions delegate to __access_remote_vm().

Move the wraparound check into __access_remote_vm() so it applies to both entry points.

lgtm, thanks.

Quoted 3 lines

This is originally reported in [1].

[1] https://lore.kernel.org/bpf/4ef240a5bea36ff84df9589671367832860795159386a4c8fba546a0fa8b786f@mail.kernel.org/

Ah, bpfbot scored one.

Sashiko might have found more issues in there:

	https://sashiko.dev/#/patchset/[email protected]
Quoted 7 lines
Quoted 2 lines

I'll optimistically cc Hajime Tazaki, who has been doing some NOMMU work recently.

I got a similar review (from Sashiko) that current use of !vma->vm_file isn't appropriate and should use vma_set_anonymous(). IIUC that case happens only (I may miss something) with /dev/zero (via mmap_zero_prepare()).

That's no longer an issue as MAP_PRIVATE-/dev/zero is truly anon now.

Quoted 3 lines

I also had a patch but am currently waiting for Lorenzo's input for his work on /dev/zero, which mentioned in his reply.

Sorry, I just added a script to find call outs in neomutt :)

As above.

Quoted 5 lines

https://lore.kernel.org/linux-mm/an8BlTgk7sc5vFJ1@lucifer/

Thus 3 comments of Sashiko (all about vma->vm_file) can be addressed in future, and are not needed an immediate fix.

You can use vma_is_anonymous() now.

Quoted 4 lines

I wish to ask this to Lorenzo too.

-- Hajime

--
Cheers, Lorenzo

maintainer Reviewed-by on v1 1/1
#5 lore raw
In reply to Anastasios Papagiannis

BTW always feel free to nag if you're not getting review! Something things get missed. (Though I'd say wait at least a couple weeks before doing that!)

Quoted 10 lines · Anastasios Papagiannis

The NOMMU implementation of access_process_vm() rejects address ranges whose end wraps around, but access_remote_vm() bypasses this check even though both functions delegate to __access_remote_vm().

Move the wraparound check into __access_remote_vm() so it applies to both entry points.

This is originally reported in [1].

[1] https://lore.kernel.org/bpf/4ef240a5bea36ff84df9589671367832860795159386a4c8fba546a0fa8b786f@mail.kernel.org/

Probably better to drop this big and make this a Link: tag.

Quoted 2 lines
Fixes f55f199b7d76 ("NOMMU: implement access_remote_vm")
Cc stable I think?
Quoted 1 line

Seems reasonable to me! So:

Quoted 29 lines
---
 mm/nommu.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
mm/nommu.c +3 -3
index 498e01ee40b0..ed44510e3770 100644
@@ -1674,6 +1674,9 @@ static int __access_remote_vm(struct mm_struct *mm, unsigned long addr,
 	struct vm_area_struct *vma;
 	int write = gup_flags & FOLL_WRITE;
 
+	if (addr + len < addr)
+		return 0;
+
 	if (mmap_read_lock_killable(mm))
 		return 0;
 
@@ -1727,9 +1730,6 @@ int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, in
 {
 	struct mm_struct *mm;
 
-	if (addr + len < addr)
-		return 0;
-
 	mm = get_task_mm(tsk);
 	if (!mm)
 		return 0;
Quoted 4 lines

base-commit: 0d9ff90a5422cc7509258aaaba1e7481df4d332a --
2.55.0

--
Cheers, Lorenzo

maintainer
#6 lore raw
Quoted 9 lines · On Fri, 25 Sep 2026 14:20:33 +0100 "Lorenzo Stoakes (ARM)" <[email protected]>…

BTW always feel free to nag if you're not getting review! Something things get missed. (Though I'd say wait at least a couple weeks before doing that!)

Quoted 4 lines · Anastasios Papagiannis

The NOMMU implementation of access_process_vm() rejects address ranges whose end wraps around, but access_remote_vm() bypasses this check even though both functions delegate to __access_remote_vm().

Quoted 8 lines
Quoted 6 lines

Move the wraparound check into __access_remote_vm() so it applies to both entry points.

This is originally reported in [1].

[1] https://lore.kernel.org/bpf/4ef240a5bea36ff84df9589671367832860795159386a4c8fba546a0fa8b786f@mail.kernel.org/

Probably better to drop this big and make this a Link: tag.

My scripts (after much recent LLM-driven fancification) made this change automatically! It became

But scripts didn't figure out how to add a Reported-by: as well.

Quoted 4 lines
Quoted 2 lines
Fixes f55f199b7d76 ("NOMMU: implement access_remote_vm")
Cc stable I think?

Well why.

I see in [1] "causing memory disclosure or a bus fault". OK, we care about that. So the changelog should tell people this very important info and should explain the circumstances which can lead to the failure.

Quoted 5 lines
Quoted 1 line

Seems reasonable to me! So:

Cool.

#7 lore raw
In reply to Lorenzo Stoakes (ARM)
Quoted 3 lines

BTW always feel free to nag if you're not getting review! Something things get missed. (Though I'd say wait at least a couple weeks before doing that!)

Thanks! To be honest, it wasn't clear to me that I should take any futher action after I received an email that this patch was added to mm-new. But after reading that email again, this seems to be the case. The patch is still open for reviews. (Sorry, still learning how the process works..)

[...]

Quoted 3 lines

Seems reasonable to me! So:

Should I now send a v2 with those changes? It seems that these are already applied
in https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git/commit/?id=1b721712d07e831686de53efc667561985897956.

Thanks,
Anastasios

#8 lore raw
Quoted 9 lines · Anastasios Papagiannis
Quoted 3 lines

BTW always feel free to nag if you're not getting review! Something things get missed. (Though I'd say wait at least a couple weeks before doing that!)

Thanks! To be honest, it wasn't clear to me that I should take any futher action after I received an email that this patch was added to mm-new. But after reading that email again, this seems to be the case. The patch is still open for reviews. (Sorry, still learning how the process works..)

Quoted 8 lines

[...]

Quoted 3 lines

Seems reasonable to me! So:

Should I now send a v2 with those changes? It seems that these are already applied
in https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git/commit/?id=1b721712d07e831686de53efc667561985897956.

No need, Andrew['s scripts] already fixed up thanks! :)

Quoted 3 lines

Thanks,
Anastasios

--
Cheers, Lorenzo