[PATCH] uprobes: Ignore unsupported instructions in uprobe_mmap

From: Srikar Dronamraju
Date: Thu Aug 02 2012 - 06:05:23 EST


uprobe_mmap()->install_breakpoint() can fail if the probed insn is not
supported (remember, uprobe_register() succeeds if nobody mmaps
inode/offset). Failure in uprobe_mmap() causes mmap_region/do_fork to
fail too.

However failing mmap_region()/do_fork() because of a probe on an
unsupported instruction is wrong.

Hence change uprobe_mmap() to ignore unsupported instructions.

Oleg Nesterov analyzed the root cause of this problem.

While at it, add a missing put_uprobe() in the path where uprobe_mmap()
races with uprobe_unregister().

Reported-by: William Cohen <wcohen@xxxxxxxxxx>
Signed-off-by: Srikar Dronamraju <srikar@xxxxxxxxxxxxxxxxxx>
Cc: Oleg Nesterov <oleg@xxxxxxxxxx>
Cc: <stable@xxxxxxxxxxxxxxx> # v3.5
---
kernel/events/uprobes.c | 13 ++++++++++++-
1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index c08a22d..c8a8c39 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -1051,8 +1051,10 @@ int uprobe_mmap(struct vm_area_struct *vma)
if (ret == -EEXIST) {
ret = 0;

- if (!is_swbp_at_addr(vma->vm_mm, vaddr))
+ if (!is_swbp_at_addr(vma->vm_mm, vaddr)) {
+ put_uprobe(uprobe);
continue;
+ }

/*
* Unable to insert a breakpoint, but
@@ -1060,6 +1062,15 @@ int uprobe_mmap(struct vm_area_struct *vma)
* probe count.
*/
atomic_inc(&vma->vm_mm->uprobes_state.count);
+ } else if (ret == -ENOTSUPP) {
+ /*
+ * A probe at unsupported instruction
+ * shouldnt cause mmap_region() / do_fork()
+ * to fail.
+ */
+ ret = 0;
+ put_uprobe(uprobe);
+ continue;
}

if (!ret)

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/