Skip to contentSkip to conversation

x86/mpx: pass 'mm' to kernel_managing_mpx_tables() in mpx_notify_unmap()

PATCH In review Jarkko Sakkinen 2 participants 3 messages Dec 3, 2018 – Dec 4, 2018

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

PATCH 1/1 x86/mpx: pass 'mm' to kernel_managing_mpx_tables() in mpx_notify_unmap()

If mm is not the same as current->mm, mpx_notify_unmap() will yield invalid results and at worst will lead to a crash if it gets called by a kthread.

Cc Dave Hansen <[email protected]>
Fixes 1de4fa14ee25 ("x86, mpx: Cleanup unused bound tables")
---
 arch/x86/mm/mpx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/mm/mpx.c +2 -2
index 2385538e8065..15fb62657ee9 100644
@@ -882,7 +882,7 @@ static int mpx_unmap_tables(struct mm_struct *mm,
  * necessary, and the 'vma' is the first vma in this range (start -> end).
  */
 void mpx_notify_unmap(struct mm_struct *mm, struct vm_area_struct *vma,
-		unsigned long start, unsigned long end)
+		      unsigned long start, unsigned long end)
 {
 	int ret;
 
@@ -890,7 +890,7 @@ void mpx_notify_unmap(struct mm_struct *mm, struct vm_area_struct *vma,
 	 * Refuse to do anything unless userspace has asked
 	 * the kernel to help manage the bounds tables,
 	 */
-	if (!kernel_managing_mpx_tables(current->mm))
+	if (!kernel_managing_mpx_tables(mm))
 		return;
 	/*
 	 * This will look across the entire 'start -> end' range,
Signature · 1 line
2.19.1
#1 lore raw
Quoted 3 lines · Jarkko Sakkinen

If mm is not the same as current->mm, mpx_notify_unmap() will yield invalid results and at worst will lead to a crash if it gets called by a kthread.

It's also worth noting that this does not fix any actual, end-user-visible bug today. It really only prepares the code for the case where it is called for a different mm than current->mm.

arch/x86/mm/mpx.c static int mpx_unmap_tables(struct mm_struct *mm, · line 887

Quoted 10 lines
arch/x86/mm/mpx.c +1 -1
@@ -882,7 +882,7 @@ static int mpx_unmap_tables(struct mm_struct *mm,
  * necessary, and the 'vma' is the first vma in this range (start -> end).
  */
 void mpx_notify_unmap(struct mm_struct *mm, struct vm_area_struct *vma,
-		unsigned long start, unsigned long end)
+		      unsigned long start, unsigned long end)
 {
 	int ret;

Please leave superfluous whitespace changes out of these things.

But, otherwise, this looks fine.

arch/x86/mm/mpx.c static int mpx_unmap_tables(struct mm_struct *mm, · line 888

Quoted 1 line
arch/x86/mm/mpx.c +0 -0
 Fixes: 1de4fa14ee25 ("x86, mpx: Cleanup unused bound tables")

FWIW, I'm not sure you should be submitting this separately from your SGX series. The deferred unmapping is really the thing that requires the code to be changed.

#2 lore raw
Quoted 22 lines · Dave Hansen
Quoted 3 lines · Jarkko Sakkinen

If mm is not the same as current->mm, mpx_notify_unmap() will yield invalid results and at worst will lead to a crash if it gets called by a kthread.

It's also worth noting that this does not fix any actual, end-user-visible bug today. It really only prepares the code for the case where it is called for a different mm than current->mm.

arch/x86/mm/mpx.c static int mpx_unmap_tables(struct mm_struct *mm, · line 887

Quoted 10 lines
arch/x86/mm/mpx.c +1 -1
@@ -882,7 +882,7 @@ static int mpx_unmap_tables(struct mm_struct *mm,
  * necessary, and the 'vma' is the first vma in this range (start -> end).
  */
 void mpx_notify_unmap(struct mm_struct *mm, struct vm_area_struct *vma,
-		unsigned long start, unsigned long end)
+		      unsigned long start, unsigned long end)
 {
 	int ret;

Please leave superfluous whitespace changes out of these things.

Quoted 7 lines

But, otherwise, this looks fine.

arch/x86/mm/mpx.c static int mpx_unmap_tables(struct mm_struct *mm, · line 888

Quoted 1 line
arch/x86/mm/mpx.c +0 -0
 Fixes: 1de4fa14ee25 ("x86, mpx: Cleanup unused bound tables")

FWIW, I'm not sure you should be submitting this separately from your SGX series. The deferred unmapping is really the thing that requires the code to be changed.

Thank you for the feedback. I'll include this to the next revision of the SGX patch set and explain why the change is needed.

/Jarkko