Skip to contentSkip to conversation

mm/mprotect: Fix do_mprotect_pkey() limit check

PATCH Applied Liam R. Howlett 4 participants 4 messages Jun 6, 2023 – Jun 7, 2023

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

PATCH 1/1 mm/mprotect: Fix do_mprotect_pkey() limit check

The return of do_mprotect_pkey() can still be incorrectly returned as success if there is a gap that spans to or beyond the end address passed in. Update the check to ensure that the end address has indeed been seen.

---
 mm/mprotect.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/mprotect.c +1 -1
index 92d3d3ca390a..c59e7561698c 100644
@@ -867,7 +867,7 @@ static int do_mprotect_pkey(unsigned long start, size_t len,
 	}
 	tlb_finish_mmu(&tlb);
 
-	if (!error && vma_iter_end(&vmi) < end)
+	if (!error && tmp < end)
 		error = -ENOMEM;
 
 out:
Signature · 1 line
2.39.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 28 lines · Liam R. Howlett

The return of do_mprotect_pkey() can still be incorrectly returned as success if there is a gap that spans to or beyond the end address passed in. Update the check to ensure that the end address has indeed been seen.

---
 mm/mprotect.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/mprotect.c +1 -2
index 92d3d3ca390a..c59e7561698c 100644
@@ -867,7 +867,7 @@ static int do_mprotect_pkey(unsigned long start, size_t len,
 	}
 	tlb_finish_mmu(&tlb);
 
-	if (!error && vma_iter_end(&vmi) < end)
+	if (!error && tmp < end)
 		error = -ENOMEM;
 
 out:
--
Quoted 2 lines

2.39.2

As discussed via irc, was able to confirm locally this fixes the reported issue, so have a quick:-

Acked-by on v1 1/1
#2 lore raw
In reply to Liam R. Howlett
Quoted 19 lines · Liam R. Howlett

The return of do_mprotect_pkey() can still be incorrectly returned as success if there is a gap that spans to or beyond the end address passed in. Update the check to ensure that the end address has indeed been seen.

---
  mm/mprotect.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
mm/mprotect.c +0 -0
index 92d3d3ca390a..c59e7561698c 100644

mm/mprotect.c static int do_mprotect_pkey(unsigned long start, size_t len, · line 873

Quoted 8 lines
mm/mprotect.c +1 -1
@@ -867,7 +867,7 @@ static int do_mprotect_pkey(unsigned long start, size_t len,
  	}
  	tlb_finish_mmu(&tlb);
 
-	if (!error && vma_iter_end(&vmi) < end)
+	if (!error && tmp < end)
  		error = -ENOMEM;
 
  out:
Signature · 3 lines
Cheers,

David / dhildenb
Acked-by on v1 1/1
#3 lore raw
In reply to Liam R. Howlett
Quoted 10 lines · Liam R. Howlett

The return of do_mprotect_pkey() can still be incorrectly returned as success if there is a gap that spans to or beyond the end address passed in. Update the check to ensure that the end address has indeed been seen.

Quoted 17 lines
---
 mm/mprotect.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/mprotect.c +1 -1
index 92d3d3ca390a..c59e7561698c 100644
@@ -867,7 +867,7 @@ static int do_mprotect_pkey(unsigned long start, size_t len,
 	}
 	tlb_finish_mmu(&tlb);
 
-	if (!error && vma_iter_end(&vmi) < end)
+	if (!error && tmp < end)
 		error = -ENOMEM;
 
 out: