Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e40cfce6 authored by Oleg Nesterov's avatar Oleg Nesterov
Browse files

uprobes: Restrict valid_vma(false) to skip VM_SHARED vmas



valid_vma(false) ignores ->vm_flags, this is not actually right.
We should never try to write into MAP_SHARED mapping, this can
confuse an apllication which actually writes to ->vm_file.

With this patch valid_vma(false) ignores VM_WRITE only but checks
other (immutable) bits checked by valid_vma(true). This can also
speedup uprobe_munmap() and uprobe_unregister().

Note: even after this patch _unregister can confuse the probed
application if it does mprotect(PROT_WRITE) after _register and
installs "int3", but this is hardly possible to avoid and this
doesn't differ from gdb case.

Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
Acked-by: default avatarSrikar Dronamraju <srikar@linux.vnet.ibm.com>
parent 78a32054
Loading
Loading
Loading
Loading
+4 −9
Original line number Original line Diff line number Diff line
@@ -100,17 +100,12 @@ struct uprobe {
 */
 */
static bool valid_vma(struct vm_area_struct *vma, bool is_register)
static bool valid_vma(struct vm_area_struct *vma, bool is_register)
{
{
	if (!vma->vm_file)
	vm_flags_t flags = VM_HUGETLB | VM_MAYEXEC | VM_SHARED;
		return false;

	if (!is_register)
		return true;


	if ((vma->vm_flags & (VM_HUGETLB | VM_WRITE | VM_MAYEXEC | VM_SHARED))
	if (is_register)
				== VM_MAYEXEC)
		flags |= VM_WRITE;
		return true;


	return false;
	return vma->vm_file && (vma->vm_flags & flags) == VM_MAYEXEC;
}
}


static unsigned long offset_to_vaddr(struct vm_area_struct *vma, loff_t offset)
static unsigned long offset_to_vaddr(struct vm_area_struct *vma, loff_t offset)