Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 334761
b: refs/heads/master
c: ed6f6a5
h: refs/heads/master
i:
  334759: 892786c
v: v3
  • Loading branch information
Oleg Nesterov committed Sep 29, 2012
1 parent 3c29e53 commit bdcbb73
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: cceb55aab73d2aea8f4d6f7414d2e1b647a3dacb
refs/heads/master: ed6f6a50dc5f183c53e7b3b7fed4794bc50d9aa7
32 changes: 23 additions & 9 deletions trunk/kernel/events/uprobes.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,25 @@ static void copy_opcode(struct page *page, unsigned long vaddr, uprobe_opcode_t
kunmap_atomic(kaddr);
}

static int verify_opcode(struct page *page, unsigned long vaddr, uprobe_opcode_t *new_opcode)
{
uprobe_opcode_t old_opcode;
bool is_swbp;

copy_opcode(page, vaddr, &old_opcode);
is_swbp = is_swbp_insn(&old_opcode);

if (is_swbp_insn(new_opcode)) {
if (is_swbp) /* register: already installed? */
return 0;
} else {
if (!is_swbp) /* unregister: was it changed by us? */
return -EINVAL;
}

return 1;
}

/*
* NOTE:
* Expect the breakpoint instruction to be the smallest size instruction for
Expand Down Expand Up @@ -226,6 +245,10 @@ static int write_opcode(struct mm_struct *mm, unsigned long vaddr,
if (ret <= 0)
return ret;

ret = verify_opcode(old_page, vaddr, &opcode);
if (ret <= 0)
goto put_old;

ret = -ENOMEM;
new_page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, vaddr);
if (!new_page)
Expand Down Expand Up @@ -311,15 +334,6 @@ int __weak set_swbp(struct arch_uprobe *auprobe, struct mm_struct *mm, unsigned
int __weak
set_orig_insn(struct arch_uprobe *auprobe, struct mm_struct *mm, unsigned long vaddr)
{
int result;

result = is_swbp_at_addr(mm, vaddr);
if (!result)
return -EINVAL;

if (result != 1)
return result;

return write_opcode(mm, vaddr, *(uprobe_opcode_t *)auprobe->insn);
}

Expand Down

0 comments on commit bdcbb73

Please sign in to comment.