c/r: prctl: less paranoid prctl_set_mm_exe_file()
PATCH 1/1 c/r: prctl: less paranoid prctl_set_mm_exe_file()
"no other files mapped" requirement from my previous patch
(c/r: prctl: update prctl_set_mm_exe_file() after mm->num_exe_file_vmas removal) is too paranoid, it forbids operation even if there mapped one shared-anon vma.
Let's check that current mm->exe_file already unmapped, in this case exe_file symlink already outdated and its changing is reasonable.
Plus, this patch fixes exit code in case operation success.
--- kernel/sys.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
kernel/sys.c +10 -6
@@ -1788,7 +1788,6 @@ SYSCALL_DEFINE1(umask, int, mask)#ifdef CONFIG_CHECKPOINT_RESTORE static int prctl_set_mm_exe_file (struct mm_struct *mm,unsigned int fd) { -struct vm_area_struct *vma;struct file *exe_file;struct dentry *dentry;int err;
@@ -1816,13 +1815,17 @@ static int prctl_set_mm_exe_file(struct mm_struct *mm, unsigned int fd)down_write (&mm->mmap_sem);/* -* Forbid mm->exe_file change if there are mapped other files. +* Forbid mm->exe_file change if old file still mapped. */ err = -EBUSY ; -for (vma = mm->mmap; vma; vma = vma->vm_next) { -if (vma->vm_file && !path_equal (&vma->vm_file->f_path, - &exe_file->f_path)) - goto exit_unlock; +if (mm->exe_file) { +struct vm_area_struct *vma; + +for (vma = mm->mmap; vma; vma = vma->vm_next) +if (vma->vm_file && +path_equal (&vma->vm_file->f_path, + &mm->exe_file->f_path)) + goto exit_unlock; }/*
@@ -1835,6 +1838,7 @@ static int prctl_set_mm_exe_file(struct mm_struct *mm, unsigned int fd)if (test_and_set_bit (MMF_EXE_FILE_CHANGED , &mm->flags)) goto exit_unlock; + err =0 ;set_mm_exe_file (mm, exe_file); exit_unlock:up_write (&mm->mmap_sem);
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 11 lines · Konstantin Khlebnikov
"no other files mapped" requirement from my previous patch
(c/r: prctl: updateprctl_set_mm_exe_file()aftermm->num_exe_file_vmasremoval) is too paranoid, it forbids operation even if there mapped one shared-anon vma.Let's check that current
mm->exe_filealready unmapped, in this caseexe_filesymlink already outdated and its changing is reasonable.Plus, this patch fixes exit code in case operation success.
Signed-off-by Konstantin Khlebnikov <[email protected]>Reported-by Cyrill Gorcunov <[email protected]>
Thanks, Konstantin, letme test it out...
Cyrill
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 17 lines · Konstantin Khlebnikov
"no other files mapped" requirement from my previous patch
(c/r: prctl: updateprctl_set_mm_exe_file()aftermm->num_exe_file_vmasremoval) is too paranoid, it forbids operation even if there mapped one shared-anon vma.Let's check that current
mm->exe_filealready unmapped, in this caseexe_filesymlink already outdated and its changing is reasonable.Plus, this patch fixes exit code in case operation success.
Signed-off-by Konstantin Khlebnikov <[email protected]>Reported-by Cyrill Gorcunov <[email protected]>Cc Oleg Nesterov <[email protected]>Cc Matt Helsley <[email protected]>Cc Kees Cook <[email protected]>Cc KOSAKI Motohiro <[email protected]>Cc Tejun Heo <[email protected]>Cc Pavel Emelyanov <[email protected]>
Quoted 1 line
---
Ack! Thanks again, Konstantin!
Cyrill
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 20 lines · Cyrill Gorcunov
Quoted 17 lines · Konstantin Khlebnikov
"no other files mapped" requirement from my previous patch
(c/r: prctl: updateprctl_set_mm_exe_file()aftermm->num_exe_file_vmasremoval) is too paranoid, it forbids operation even if there mapped one shared-anon vma.Let's check that current
mm->exe_filealready unmapped, in this caseexe_filesymlink already outdated and its changing is reasonable.Plus, this patch fixes exit code in case operation success.
Signed-off-by Konstantin Khlebnikov <[email protected]>Reported-by Cyrill Gorcunov <[email protected]>Cc Oleg Nesterov <[email protected]>Cc Matt Helsley <[email protected]>Cc Kees Cook <[email protected]>Cc KOSAKI Motohiro <[email protected]>Cc Tejun Heo <[email protected]>Cc Pavel Emelyanov <[email protected]>Quoted 1 line
---
Quoted 1 line
Ack! Thanks again, Konstantin!
Side note: there is a little nit with this patch actually, because while when we do c/r we do "right things" and unmap all vm-executable mappings before we set up new exe_file. But we can't guarantee that some brave soul would not setup new exe-file just for it's own, then what we migh have
- mm::exe_file set up and points to some file, moreover num_exe_file_vmas might be > 1
- application calls for prctl_set_mm_exe_file
- set_mm_exe_file(mm, exe_file) called, and it drops num_exe_file_vmas to 0
- finally application might call for removed_exe_file_vma
void removed_exe_file_vma(struct mm_struct *mm)
{
mm->num_exe_file_vmas--;
if ((mm->num_exe_file_vmas == 0) && mm->exe_file) {
fput(mm->exe_file);
mm->exe_file = NULL;
}}
and it does _not_ test for num_exe_file_vmas being 0 before doing decrement, thus we get inconsistency in counter.
Cyrill
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 42 lines · Cyrill Gorcunov
Quoted 20 lines · Cyrill Gorcunov
Quoted 17 lines · Konstantin Khlebnikov
"no other files mapped" requirement from my previous patch
(c/r: prctl: updateprctl_set_mm_exe_file()aftermm->num_exe_file_vmasremoval) is too paranoid, it forbids operation even if there mapped one shared-anon vma.Let's check that current
mm->exe_filealready unmapped, in this caseexe_filesymlink already outdated and its changing is reasonable.Plus, this patch fixes exit code in case operation success.
Signed-off-by Konstantin Khlebnikov<[email protected]>Reported-by Cyrill Gorcunov<[email protected]>Cc Oleg Nesterov<[email protected]>Cc Matt Helsley<[email protected]>Cc Kees Cook<[email protected]>Cc KOSAKI Motohiro<[email protected]>Cc Tejun Heo<[email protected]>Cc Pavel Emelyanov<[email protected]>Quoted 1 line
---
Quoted 1 line
Ack! Thanks again, Konstantin!
Side note: there is a little nit with this patch actually, because while when we do c/r we do "right things" and unmap all vm-executable mappings before we set up new
exe_file. But we can't guarantee that some brave soul would not setup new exe-file just for it's own, then what we migh have-
mm::exe_fileset up and points to some file, moreovernum_exe_file_vmasmight be> 1
- application calls forprctl_set_mm_exe_file
-set_mm_exe_file(mm, exe_file)called, and it dropsnum_exe_file_vmasto 0
- finally application might call forremoved_exe_file_vmavoid
removed_exe_file_vma(struct mm_struct *mm){ mm->num_exe_file_vmas--; if ((mm->num_exe_file_vmas == 0)&& mm->exe_file) { fput(mm->exe_file); mm->exe_file = NULL; }
Quoted 4 lines
}
and it does _not_ test for
num_exe_file_vmasbeing 0 before doing decrement, thus we get inconsistency in counter.
No, removed_exe_file_vma() is called only for vma with VM_EXECUTABLE flag, there no way to get such vma other than sys_execve().
And this brave soul cannot call prctl_set_mm_exe_file() successfully, just because for vma with VM_EXECUTABLE flag vma->vm_file == mm->exe_file.
Anyway, I plan to get rid of mm->num_exe_file_vmas and VM_EXECUTABLE.
Quoted 2 lines
Cyrill
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 24 lines · Konstantin Khlebnikov
Quoted 19 lines
Side note: there is a little nit with this patch actually, because while when we do c/r we do "right things" and unmap all vm-executable mappings before we set up new
exe_file. But we can't guarantee that some brave soul would not setup new exe-file just for it's own, then what we migh have-
mm::exe_fileset up and points to some file, moreovernum_exe_file_vmasmight be> 1
- application calls forprctl_set_mm_exe_file
-set_mm_exe_file(mm, exe_file)called, and it dropsnum_exe_file_vmasto 0
- finally application might call forremoved_exe_file_vmavoid
removed_exe_file_vma(struct mm_struct *mm){ mm->num_exe_file_vmas--; if ((mm->num_exe_file_vmas == 0)&& mm->exe_file) { fput(mm->exe_file); mm->exe_file = NULL; }Quoted 4 lines
}
and it does _not_ test for
num_exe_file_vmasbeing 0 before doing decrement, thus we get inconsistency in counter.
Quoted 6 lines
No,
removed_exe_file_vma()is called only for vma withVM_EXECUTABLEflag, there no way to get such vma other thansys_execve().
And this brave soul cannot callprctl_set_mm_exe_file()successfully, just because for vma withVM_EXECUTABLEflagvma->vm_file==mm->exe_file.Anyway, I plan to get rid of
mm->num_exe_file_vmasandVM_EXECUTABLE.
Yeah, you've changed !path_equal to path_equal. And yes, getting rid of num_exe_file_vmas is good idea. Btw, Konstantin, why do we need to call for path_equal? Maybe we can simply test for mm->exe_file == NULL, and refuse to change anything if it's not nil value? This will simplify the code.
Cyrill
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 30 lines · Cyrill Gorcunov
Quoted 29 lines · Konstantin Khlebnikov
Quoted 19 lines
Side note: there is a little nit with this patch actually, because while when we do c/r we do "right things" and unmap all vm-executable mappings before we set up new
exe_file. But we can't guarantee that some brave soul would not setup new exe-file just for it's own, then what we migh have-
mm::exe_fileset up and points to some file, moreovernum_exe_file_vmasmight be> 1
- application calls forprctl_set_mm_exe_file
-set_mm_exe_file(mm, exe_file)called, and it dropsnum_exe_file_vmasto 0
- finally application might call forremoved_exe_file_vmavoid
removed_exe_file_vma(struct mm_struct *mm){ mm->num_exe_file_vmas--; if ((mm->num_exe_file_vmas == 0)&& mm->exe_file) { fput(mm->exe_file); mm->exe_file = NULL; }Quoted 4 lines
}
and it does _not_ test for
num_exe_file_vmasbeing 0 before doing decrement, thus we get inconsistency in counter.No,
removed_exe_file_vma()is called only for vma withVM_EXECUTABLEflag, there no way to get such vma other thansys_execve().
And this brave soul cannot callprctl_set_mm_exe_file()successfully, just because for vma withVM_EXECUTABLEflagvma->vm_file==mm->exe_file.
Quoted 7 lines
Quoted 1 line
Anyway, I plan to get rid of
mm->num_exe_file_vmasandVM_EXECUTABLE.Yeah, you've changed !path_equal to
path_equal. And yes, getting rid ofnum_exe_file_vmasis good idea. Btw, Konstantin, why do we need to call forpath_equal? Maybe we can simply test formm->exe_file== NULL, and refuse to change anything if it's not nil value? This will simplify the code.
After removing VM_EXECUTABLE and mm->num_exe_file_vmas mm->exe_file will never becomes NULL automatically. Patch for this not commited yet, but I hope it will be in 3.6.
Quoted 2 lines
Cyrill
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 9 lines · Konstantin Khlebnikov
Quoted 5 lines
Yeah, you've changed !path_equal to
path_equal. And yes, getting rid ofnum_exe_file_vmasis good idea. Btw, Konstantin, why do we need to call forpath_equal? Maybe we can simply test formm->exe_file== NULL, and refuse to change anything if it's not nil value? This will simplify the code.After removing
VM_EXECUTABLEandmm->num_exe_file_vmasmm->exe_filewill never becomes NULL automatically. Patch for this not commited yet, but I hope it will be in 3.6.
OK, lets stick with current patch then.
Cyrill
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Cyrill Gorcunov
Tested-byQuoted 7 lines · Cyrill Gorcunov
Quoted 6 lines · Konstantin Khlebnikov
Quoted 5 lines
Yeah, you've changed !path_equal to
path_equal. And yes, getting rid ofnum_exe_file_vmasis good idea. Btw, Konstantin, why do we need to call forpath_equal? Maybe we can simply test formm->exe_file== NULL, and refuse to change anything if it's not nil value? This will simplify the code.
Quoted 5 lines
Quoted 3 lines
After removing
VM_EXECUTABLEandmm->num_exe_file_vmasmm->exe_filewill never becomes NULL automatically. Patch for this not commited yet, but I hope it will be in 3.6.OK, lets stick with current patch then.
To clarify
Andrew, could you please pick up this bugfix. It's critical for us.
P.S. Together with patch https://lkml.org/lkml/2012/6/15/220 it'll be last changes to prctl in a sake of c/r I think. Would be cool to have both bugfixes in 3.5.
Cyrill
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>