Re: [PATCH 6/7] uprobes: Fix uprobe_copy_insn() race with itself

From: Srikar Dronamraju
Date: Sat Oct 06 2012 - 05:52:43 EST


* Oleg Nesterov <oleg@xxxxxxxxxx> [2012-09-30 21:42:24]:

> install_breakpoint() is called under mm->mmap_sem, this protects
> set_swbp() but not uprobe_copy_insn(). Two or more different tasks
> can call install_breakpoint()->uprobe_copy_insn() at the same time,
> this leads to numerous problems if UPROBE_COPY_INSN is not set.
>
> Just for example, the second copy_insn() can corrupt the already
> analyzed/fixuped uprobe->arch.insn and race with handle_swbp().
>
> This patch simply adds uprobe->copy_mutex to serialize this code.
> We could probably reuse ->consumer_rwsem, but this would mean that
> consumer->handler() can not use mm->mmap_sem, not good.
>
> Note: this is another temporary ugly hack until we move this logic
> into uprobe_register().
>
> Signed-off-by: Oleg Nesterov <oleg@xxxxxxxxxx>

Given that we copy just for the first install, and register not being a
performance path, Can we use a single mutex instead of a per-uprobe
mutex.

Acked-by: Srikar Dronamraju <srikar@xxxxxxxxxxxxxxxxxx>

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