diff options
| author | Oleg Nesterov <oleg@redhat.com> | 2014-05-16 10:23:18 -0400 |
|---|---|---|
| committer | Oleg Nesterov <oleg@redhat.com> | 2014-06-02 09:54:45 -0400 |
| commit | 7fa3134817d3cc813aeba9acc7e284f2f535f1f5 (patch) | |
| tree | 34ea0769ebf4fbf803ac4e7ecef9c808cd92a1d4 | |
| parent | a03b1e1c372b60183b8141cdd161316429fab5ac (diff) | |
uprobes: Shift ->readpage check from __copy_insn() to uprobe_register()
copy_insn() fails with -EIO if ->readpage == NULL, but this error
is not propagated unless uprobe_register() path finds ->mm which
already mmaps this file. In this case (say) "perf record" does not
actually install the probe, but the user can't know about this.
Move this check into uprobe_register() so that this problem can be
detected earlier and reported to user.
Note: this is still not perfect,
- copy_insn() and arch_uprobe_analyze_insn() should be called
by uprobe_register() but this is not simple, we need vm_file
for read_mapping_page() (although perhaps we can pass NULL),
and we need ->mm for is_64bit_mm() (although this logic is
broken anyway).
- uprobe_register() should be called by create_trace_uprobe(),
not by probe_event_enable(), so that an error can be detected
at "perf probe -x" time. This also needs more changes in the
core uprobe code, uprobe register/unregister interface was
poorly designed from the very beginning.
Reported-by: Denys Vlasenko <dvlasenk@redhat.com>
Acked-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
| -rw-r--r-- | kernel/events/uprobes.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c index 3b02c72938a8..c56b13e3b5e1 100644 --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c | |||
| @@ -536,9 +536,6 @@ static int __copy_insn(struct address_space *mapping, struct file *filp, | |||
| 536 | void *insn, int nbytes, loff_t offset) | 536 | void *insn, int nbytes, loff_t offset) |
| 537 | { | 537 | { |
| 538 | struct page *page; | 538 | struct page *page; |
| 539 | |||
| 540 | if (!mapping->a_ops->readpage) | ||
| 541 | return -EIO; | ||
| 542 | /* | 539 | /* |
| 543 | * Ensure that the page that has the original instruction is | 540 | * Ensure that the page that has the original instruction is |
| 544 | * populated and in page-cache. | 541 | * populated and in page-cache. |
| @@ -879,6 +876,9 @@ int uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer * | |||
| 879 | if (!uc->handler && !uc->ret_handler) | 876 | if (!uc->handler && !uc->ret_handler) |
| 880 | return -EINVAL; | 877 | return -EINVAL; |
| 881 | 878 | ||
| 879 | /* copy_insn()->read_mapping_page() needs ->readpage() */ | ||
| 880 | if (!inode->i_mapping->a_ops->readpage) | ||
| 881 | return -EIO; | ||
| 882 | /* Racy, just to catch the obvious mistakes */ | 882 | /* Racy, just to catch the obvious mistakes */ |
| 883 | if (offset > i_size_read(inode)) | 883 | if (offset > i_size_read(inode)) |
| 884 | return -EINVAL; | 884 | return -EINVAL; |
