Skip to contentSkip to conversation

mm/mseal: Fix range_contains_unmapped() ignoring its mm argument

PATCH In review Hongfu Li 2 participants 3 messages Jul 16 – Jul 17

Subsystems (2)
lore
Share & tools
lore

Hongfu Li

author
#0 lore raw

PATCH 1/1 mm/mseal: Fix range_contains_unmapped() ignoring its mm argument

From: Hongfu Li <[email protected]>

range_contains_unmapped() accepts an explicit struct mm_struct *mm argument, yet hardcodes current->mm inside VMA_ITERATOR(), ignoring the passed address space.

Its only caller do_mseal() currently passes current->mm, so the bug does not manifest right now. However this mismatch between prototype and implementation is a latent bug.

Replace current->mm with the passed mm parameter to match the function prototype.

Fixes 530e09096413 ("mm/mseal: simplify and rename VMA gap check")
---
 mm/mseal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/mseal.c +1 -1
index 9781647483d1..8d82e50900ba 100644
@@ -41,7 +41,7 @@ static bool range_contains_unmapped(struct mm_struct *mm,
 {
 	struct vm_area_struct *vma;
 	unsigned long prev_end = start;
-	VMA_ITERATOR(vmi, current->mm, start);
+	VMA_ITERATOR(vmi, mm, start);
 
 	for_each_vma_range(vmi, vma, end) {
 		if (vma->vm_start > prev_end)
Signature · 1 line
2.54.0
#1 lore raw
Quoted 6 lines · Hongfu Li

From: Hongfu Li <[email protected]>

range_contains_unmapped() accepts an explicit struct mm_struct *mm argument, yet hardcodes current->mm inside VMA_ITERATOR(), ignoring the passed address space.

Quoted 8 lines

Its only caller do_mseal() currently passes current->mm, so the bug does not manifest right now. However this mismatch between prototype and implementation is a latent bug.

Replace current->mm with the passed mm parameter to match the function prototype.

Fixes 530e09096413 ("mm/mseal: simplify and rename VMA gap check")

There's no point in a Fixes tag for something that's not a bug.

Quoted 10 lines
---
 mm/mseal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/mseal.c +0 -0
index 9781647483d1..8d82e50900ba 100644

mm/mseal.c static bool range_contains_unmapped(struct mm_struct *mm, · line 44

Quoted 5 lines
mm/mseal.c +1 -1
@@ -41,7 +41,7 @@ static bool range_contains_unmapped(struct mm_struct *mm,
 {
 	struct vm_area_struct *vma;
 	unsigned long prev_end = start;
-	VMA_ITERATOR(vmi, current->mm, start);
+	VMA_ITERATOR(vmi, mm, start);

We're never going to sensibly allow a remote mm here, and even suggesting so is problematic.

Sorry but I think it's just easier if I send a broader cleanup patch to fix things up here more clearly.

Quoted 6 lines
mm/mseal.c +0 -1
 	for_each_vma_range(vmi, vma, end) {
 		if (vma->vm_start > prev_end)
--

2.54.0

Thanks, Lorenzo

author
#2 lore raw

Hi,

Quoted 35 lines · Lorenzo Stoakes (ARM)
Quoted 6 lines · Hongfu Li

From: Hongfu Li <[email protected]>

range_contains_unmapped() accepts an explicit struct mm_struct *mm argument, yet hardcodes current->mm inside VMA_ITERATOR(), ignoring the passed address space.

Quoted 8 lines

Its only caller do_mseal() currently passes current->mm, so the bug does not manifest right now. However this mismatch between prototype and implementation is a latent bug.

Replace current->mm with the passed mm parameter to match the function prototype.

Fixes 530e09096413 ("mm/mseal: simplify and rename VMA gap check")

There's no point in a Fixes tag for something that's not a bug.

Quoted 10 lines
---
  mm/mseal.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
mm/mseal.c +0 -0
index 9781647483d1..8d82e50900ba 100644

mm/mseal.c static bool range_contains_unmapped(struct mm_struct *mm, · line 44

Quoted 5 lines
mm/mseal.c +1 -1
@@ -41,7 +41,7 @@ static bool range_contains_unmapped(struct mm_struct *mm,
  {
  	struct vm_area_struct *vma;
  	unsigned long prev_end = start;
-	VMA_ITERATOR(vmi, current->mm, start);
+	VMA_ITERATOR(vmi, mm, start);

We're never going to sensibly allow a remote mm here, and even suggesting so is problematic.

Quoted 2 lines

Sorry but I think it's just easier if I send a broader cleanup patch to fix things up here more clearly.

Got it, thanks a lot for explaining the issue with remote mm. A unified broad cleanup patch works better for this code path. I will withdraw my patch and follow your series. Feel free to reach out if you need any testing help later. Best regards,
Hongfu