mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-28 18:51:56 -04:00
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: Oleg Nesterov <[email protected]> Acked-by: Srikar Dronamraju <[email protected]> Cc: Ananth N Mavinakayanahalli <[email protected]> Cc: Anton Arapov <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
This commit is contained in:
parent
a3d7bb4793
commit
3a9ea0520f
1 changed files with 28 additions and 19 deletions
|
|
@ -1489,37 +1489,46 @@ static bool can_skip_sstep(struct uprobe *uprobe, struct pt_regs *regs)
|
|||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
down_read(&mm->mmap_sem);
|
||||
vma = find_vma(mm, bp_vaddr);
|
||||
|
||||
if (vma && vma->vm_start <= bp_vaddr) {
|
||||
if (valid_vma(vma, false)) {
|
||||
struct inode *inode;
|
||||
loff_t offset;
|
||||
|
||||
inode = vma->vm_file->f_mapping->host;
|
||||
offset = bp_vaddr - vma->vm_start;
|
||||
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 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)) {
|
||||
struct inode *inode;
|
||||
loff_t offset;
|
||||
|
||||
inode = vma->vm_file->f_mapping->host;
|
||||
offset = bp_vaddr - vma->vm_start;
|
||||
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);
|
||||
uprobe = find_active_uprobe(bp_vaddr);
|
||||
|
||||
if (!uprobe) {
|
||||
/* No matching uprobe; signal SIGTRAP. */
|
||||
|
|
|
|||
Loading…
Reference in a new issue