]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
uprobes: Change register_for_each_vma() to take mm->mmap_sem for writing
authorOleg Nesterov <oleg@redhat.com>
Tue, 29 May 2012 19:29:28 +0000 (21:29 +0200)
committerIngo Molnar <mingo@kernel.org>
Wed, 6 Jun 2012 15:21:48 +0000 (17:21 +0200)
Change register_for_each_vma() to take mm->mmap_sem for writing.
This is a bit unfortunate but hopefully not too bad, this is the
slow path anyway.

This is needed to ensure that find_active_uprobe() can not race
with uprobe_register() which adds the new bp at the same
bp_vaddr, after find_uprobe() fails and before
is_swbp_at_addr_fast() checks the memory.

IOW, this is needed to ensure that if find_active_uprobe()
returns NULL but is_swbp == true, we can safely assume that it
was the "normal" int3 and we should send SIGTRAP.

There is another reason for this change. We are going to replace
uprobes_state->count with MMF_ flags set by register/unregister
and cleared by find_active_uprobe(), and set/clear shouldn't
race with each other.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Anton Arapov <anton@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20120529192928.GE8057@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
kernel/events/uprobes.c

index ee3df704e78aa10d5f43604f6e8ad8de913c02b6..a2ed82b4808c6c017519f3b727abe8883c9bd8a8 100644 (file)
@@ -853,12 +853,12 @@ static int register_for_each_vma(struct uprobe *uprobe, bool is_register)
                }
 
                mm = vi->mm;
-               down_read(&mm->mmap_sem);
+               down_write(&mm->mmap_sem);
                vma = find_vma(mm, (unsigned long)vi->vaddr);
                if (!vma || !valid_vma(vma, is_register)) {
                        list_del(&vi->probe_list);
                        kfree(vi);
-                       up_read(&mm->mmap_sem);
+                       up_write(&mm->mmap_sem);
                        mmput(mm);
                        continue;
                }
@@ -867,7 +867,7 @@ static int register_for_each_vma(struct uprobe *uprobe, bool is_register)
                                                vaddr != vi->vaddr) {
                        list_del(&vi->probe_list);
                        kfree(vi);
-                       up_read(&mm->mmap_sem);
+                       up_write(&mm->mmap_sem);
                        mmput(mm);
                        continue;
                }
@@ -877,7 +877,7 @@ static int register_for_each_vma(struct uprobe *uprobe, bool is_register)
                else
                        remove_breakpoint(uprobe, mm, vi->vaddr);
 
-               up_read(&mm->mmap_sem);
+               up_write(&mm->mmap_sem);
                mmput(mm);
                if (is_register) {
                        if (ret && ret == -EEXIST)