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

Commit 3a9ea052 authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Ingo Molnar
Browse files

uprobes: Introduce find_active_uprobe() helper



No functional changes. Move the "find uprobe" code from
handle_swbp() to the new helper, find_active_uprobe().

Note: with or without this change, the find-active-uprobe logic
is not exactly right. We can race with another thread which
unmaps the memory with the valid uprobe before we take
mm->mmap_sem. We can't find this uprobe simply because
find_vma() fails. In this case we wrongly assume that this trap
was not caused by uprobe and send the erroneous SIGTRAP. See the
next changes.

Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
Acked-by: default avatarSrikar 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/20120529192857.GC8057@redhat.com


Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent a3d7bb47
Loading
Loading
Loading
Loading
+28 −19
Original line number Diff line number Diff line
@@ -1489,25 +1489,17 @@ static bool can_skip_sstep(struct uprobe *uprobe, struct pt_regs *regs)
	return false;
}

/*
 * Run handler and ask thread to singlestep.
 * Ensure all non-fatal signals cannot interrupt thread while it singlesteps.
 */
static void handle_swbp(struct pt_regs *regs)
static struct uprobe *find_active_uprobe(unsigned long bp_vaddr)
{
	struct mm_struct *mm = current->mm;
	struct uprobe *uprobe = NULL;
	struct vm_area_struct *vma;
	struct uprobe_task *utask;
	struct uprobe *uprobe;
	struct mm_struct *mm;
	unsigned long bp_vaddr;

	uprobe = NULL;
	bp_vaddr = uprobe_get_swbp_addr(regs);
	mm = current->mm;
	down_read(&mm->mmap_sem);
	vma = find_vma(mm, bp_vaddr);

	if (vma && vma->vm_start <= bp_vaddr && valid_vma(vma, false)) {
	if (vma && vma->vm_start <= bp_vaddr) {
		if (valid_vma(vma, false)) {
			struct inode *inode;
			loff_t offset;

@@ -1516,11 +1508,28 @@ static void handle_swbp(struct pt_regs *regs)
			offset += (vma->vm_pgoff << PAGE_SHIFT);
			uprobe = find_uprobe(inode, offset);
		}
	}

	srcu_read_unlock_raw(&uprobes_srcu, current->uprobe_srcu_id);
	current->uprobe_srcu_id = -1;
	up_read(&mm->mmap_sem);

	return uprobe;
}

/*
 * Run handler and ask thread to singlestep.
 * Ensure all non-fatal signals cannot interrupt thread while it singlesteps.
 */
static void handle_swbp(struct pt_regs *regs)
{
	struct uprobe_task *utask;
	struct uprobe *uprobe;
	unsigned long bp_vaddr;

	bp_vaddr = uprobe_get_swbp_addr(regs);
	uprobe = find_active_uprobe(bp_vaddr);

	if (!uprobe) {
		/* No matching uprobe; signal SIGTRAP. */
		send_sig(SIGTRAP, current, 0);