Skip to content

Commit

Permalink
uprobes: Move BUG_ON(UPROBE_SWBP_INSN_SIZE) from write_opcode() to in…
Browse files Browse the repository at this point in the history
…stall_breakpoint()

write_opcode() ensures that UPROBE_SWBP_INSN doesn't cross the
page boundary. This looks a bit confusing, the check does not
depend on vaddr and it is enough to do it only once right after
install_breakpoint()->arch_uprobe_analyze_insn().

Signed-off-by: Oleg Nesterov <[email protected]>
Acked-by: Srikar Dronamraju <[email protected]>
Acked-by: Ananth N Mavinakayanahalli <[email protected]>
Cc: Anton Arapov <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
  • Loading branch information
oleg-nesterov authored and Ingo Molnar committed Jun 16, 2012
1 parent eb2bf57 commit d9c4a30
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions kernel/events/uprobes.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ static int write_opcode(struct arch_uprobe *auprobe, struct mm_struct *mm,
void *vaddr_old, *vaddr_new;
struct vm_area_struct *vma;
struct uprobe *uprobe;
unsigned long pgoff;
int ret;
retry:
/* Read the page with vaddr into memory */
Expand Down Expand Up @@ -251,11 +250,7 @@ static int write_opcode(struct arch_uprobe *auprobe, struct mm_struct *mm,
vaddr_new = kmap_atomic(new_page);

memcpy(vaddr_new, vaddr_old, PAGE_SIZE);

/* poke the new insn in, ASSUMES we don't cross page boundary */
pgoff = (vaddr & ~PAGE_MASK);
BUG_ON(pgoff + UPROBE_SWBP_INSN_SIZE > PAGE_SIZE);
memcpy(vaddr_new + pgoff, &opcode, UPROBE_SWBP_INSN_SIZE);
memcpy(vaddr_new + (vaddr & ~PAGE_MASK), &opcode, UPROBE_SWBP_INSN_SIZE);

kunmap_atomic(vaddr_new);
kunmap_atomic(vaddr_old);
Expand Down Expand Up @@ -699,6 +694,10 @@ install_breakpoint(struct uprobe *uprobe, struct mm_struct *mm,
if (ret)
return ret;

/* write_opcode() assumes we don't cross page boundary */
BUG_ON((uprobe->offset & ~PAGE_MASK) +
UPROBE_SWBP_INSN_SIZE > PAGE_SIZE);

uprobe->flags |= UPROBE_COPY_INSN;
}

Expand Down

0 comments on commit d9c4a30

Please sign in to comment.