uprobes: Refuse to insert a probe into MAP_SHARED vma
Subsystems (2)
Oleg Nesterov
maintainerPATCH 1/1 uprobes: Refuse to insert a probe into MAP_SHARED vma
valid_vma() rejects the VM_SHARED vmas, but this still allows to insert a probe into the MAP_SHARED but not VM_MAYWRITE vma.
Currently this is fine, such a mapping doesn't really differ from the private read-only mmap except mprotect(PROT_WRITE) won't work. However, get_user_pages(FOLL_WRITE | FOLL_FORCE) doesn't allow to COW in this case, and it would be safer to follow the same conventions as mm even if currently this happens to work.
After the recent cda540ace6a1 "mm: get_user_pages(write,force) refuse to COW in shared areas" only uprobes can insert an anon page into the shared file-backed area, lets stop this and change valid_vma() to check VM_MAYSHARE instead.
--- kernel/events/uprobes.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/events/uprobes.c +1 -1
@@ -127,7 +127,7 @@ struct xol_area {*/ static bool valid_vma (struct vm_area_struct *vma,bool is_register) { -vm_flags_t flags =VM_HUGETLB |VM_MAYEXEC |VM_SHARED ; +vm_flags_t flags =VM_HUGETLB |VM_MAYEXEC |VM_MAYSHARE ;if (is_register) flags |=VM_WRITE ;
Signature · 1 line
1.5.5.1
Oleg Nesterov
maintainerAnd of course, I forgot to add Hugh ;) Fix that.
Quoted 36 lines · Oleg Nesterov
valid_vma()rejects theVM_SHAREDvmas, but this still allows to insert a probe into theMAP_SHAREDbut notVM_MAYWRITEvma.Currently this is fine, such a mapping doesn't really differ from the private read-only mmap except
mprotect(PROT_WRITE)won't work. However,get_user_pages(FOLL_WRITE | FOLL_FORCE)doesn't allow to COW in this case, and it would be safer to follow the same conventions as mm even if currently this happens to work.After the recent
cda540ace6a1"mm:get_user_pages(write,force)refuse to COW in shared areas" only uprobes can insert an anon page into the shared file-backed area, lets stop this and changevalid_vma()to checkVM_MAYSHAREinstead.Signed-off-by Oleg Nesterov <[email protected]>--- kernel/events/uprobes.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)kernel/events/uprobes.c +1
-1@@ -127,7 +127,7 @@ struct xol_area {*/ static bool valid_vma (struct vm_area_struct *vma,bool is_register) { -vm_flags_t flags =VM_HUGETLB |VM_MAYEXEC |VM_SHARED ; +vm_flags_t flags =VM_HUGETLB |VM_MAYEXEC |VM_MAYSHARE ;if (is_register) flags |=VM_WRITE ;Signature · 1 line
1.5.5.1