aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Nesterov <oleg@redhat.com>2014-05-19 14:41:36 -0400
committerIngo Molnar <mingo@kernel.org>2014-06-05 06:30:11 -0400
commit40814f6805a524130a5ec313871147f7aa9b5318 (patch)
tree2605a03d0a7360c377126c590cb929e1ed9d0057
parent41ccba029e9492dd0fc1bf5c23b72c6322a6dfe9 (diff)
uprobes: Teach copy_insn() to support tmpfs
tmpfs is widely used but as Denys reports shmem_aops doesn't have ->readpage() and thus you can't probe a binary on this filesystem. As Hugh suggested we can use shmem_read_mapping_page() in this case, just we need to check shmem_mapping() if ->readpage == NULL. Reported-by: Denys Vlasenko <dvlasenk@redhat.com> Suggested-by: Hugh Dickins <hughd@google.com> Signed-off-by: Oleg Nesterov <oleg@redhat.com> Acked-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com> Signed-off-by: Peter Zijlstra <peterz@infradead.org> Cc: Arnaldo Carvalho de Melo <acme@kernel.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Link: http://lkml.kernel.org/r/20140519184136.GB6750@redhat.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r--kernel/events/uprobes.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index c56b13e3b5e1..6bfb6717f878 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -36,6 +36,7 @@
36#include "../../mm/internal.h" /* munlock_vma_page */ 36#include "../../mm/internal.h" /* munlock_vma_page */
37#include <linux/percpu-rwsem.h> 37#include <linux/percpu-rwsem.h>
38#include <linux/task_work.h> 38#include <linux/task_work.h>
39#include <linux/shmem_fs.h>
39 40
40#include <linux/uprobes.h> 41#include <linux/uprobes.h>
41 42
@@ -537,10 +538,14 @@ static int __copy_insn(struct address_space *mapping, struct file *filp,
537{ 538{
538 struct page *page; 539 struct page *page;
539 /* 540 /*
540 * Ensure that the page that has the original instruction is 541 * Ensure that the page that has the original instruction is populated
541 * populated and in page-cache. 542 * and in page-cache. If ->readpage == NULL it must be shmem_mapping(),
543 * see uprobe_register().
542 */ 544 */
543 page = read_mapping_page(mapping, offset >> PAGE_CACHE_SHIFT, filp); 545 if (mapping->a_ops->readpage)
546 page = read_mapping_page(mapping, offset >> PAGE_CACHE_SHIFT, filp);
547 else
548 page = shmem_read_mapping_page(mapping, offset >> PAGE_CACHE_SHIFT);
544 if (IS_ERR(page)) 549 if (IS_ERR(page))
545 return PTR_ERR(page); 550 return PTR_ERR(page);
546 551
@@ -876,8 +881,8 @@ int uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *
876 if (!uc->handler && !uc->ret_handler) 881 if (!uc->handler && !uc->ret_handler)
877 return -EINVAL; 882 return -EINVAL;
878 883
879 /* copy_insn()->read_mapping_page() needs ->readpage() */ 884 /* copy_insn() uses read_mapping_page() or shmem_read_mapping_page() */
880 if (!inode->i_mapping->a_ops->readpage) 885 if (!inode->i_mapping->a_ops->readpage && !shmem_mapping(inode->i_mapping))
881 return -EIO; 886 return -EIO;
882 /* Racy, just to catch the obvious mistakes */ 887 /* Racy, just to catch the obvious mistakes */
883 if (offset > i_size_read(inode)) 888 if (offset > i_size_read(inode))