Re: [PATCH v7 3.2-rc2 4/30] uprobes: Define hooks for mmap/munmap.

From: Srikar Dronamraju
Date: Wed Nov 30 2011 - 00:32:54 EST


>
> int mmap_uprobe(...) {
> ....
> ret = install_breakpoint(vma->vm_mm, uprobe);
> if (ret == -EEXIST) {
> if (!read_opcode(vma->vm_mm, vaddr, &opcode) &&
> (opcode == UPROBES_BKPT_INSN))
> atomic_inc(&vma->vm_mm->mm_uprobes_count);
> ret = 0;
> }
> ....
> }
>

Infact the check for EEXIST and read_opcode in mmap_uprobe() is needed
for another reason too.

Lets say while unregister_uprobe was around, a thread thats being
probed, just forked a child and the child called mmap_uprobe.

Now mmap_uprobe might find that the breakpoint is already inserted
since the pages are shared with the parent. But before
unregister_uprobe can come around and cleanup, the child can run and hit
the breakpoint. Since the breakpoint count is 0 for the child, we dont
expect the child to have hit a breakpoint placed by uprobes, and the
child gets a SIGTRAP.

With this check for read_opcode on EEXIST from install_breakpoint, we
will know that there is a valid breakpoint underneath and increment
the count. So on a breakpoint hit, the uprobes notifier does the right
thing.

If the unregister_uprobe() had already cleanup the breakpoint in the
parent, the child's copy would also be clean so read_opcode wont find
the breakpoint and hence we wont increment the breakpoint.

--
Thanks and Regards
Srikar

--
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/