]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
tracing: uprobes: Re-enable $comm support for uprobe events
authorMasami Hiramatsu <mhiramat@kernel.org>
Tue, 7 May 2019 13:55:41 +0000 (22:55 +0900)
committerSteven Rostedt (VMware) <rostedt@goodmis.org>
Wed, 8 May 2019 16:15:11 +0000 (12:15 -0400)
Since commit 533059281ee5 ("tracing: probeevent: Introduce new
argument fetching code") dropped the $comm support from uprobe
events, this re-enables it.

For $comm support, uses strlcpy() instead of strncpy_from_user()
to copy current task's comm. Because it is in the kernel space,
strncpy_from_user() always fails to copy the comm.
This also uses strlen() instead of strnlen_user() to measure the
length of the comm.

Note that this uses -ECOMM as a token value to fetch the comm
string. If the user-space pointer points -ECOMM, it will be
translated to task->comm.

Link: http://lkml.kernel.org/r/155723734162.9149.4042756162201097965.stgit@devnote2
Fixes: 533059281ee5 ("tracing: probeevent: Introduce new argument fetching code")
Reported-by: Andreas Ziegler <andreas.ziegler@fau.de>
Acked-by: Andreas Ziegler <andreas.ziegler@fau.de>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
kernel/trace/trace_probe.h
kernel/trace/trace_uprobe.c

index b7737666c1a838dffd21b07599d8b3a583f9b4dc..f9a8c632188bcf8a3d849cdf94f2d9a11a081eb6 100644 (file)
@@ -124,6 +124,7 @@ struct fetch_insn {
 
 /* fetch + deref*N + store + mod + end <= 16, this allows N=12, enough */
 #define FETCH_INSN_MAX 16
+#define FETCH_TOKEN_COMM       (-ECOMM)
 
 /* Fetch type information table */
 struct fetch_type {
index cd8750a72768b9640080ebd75286087c25a95bd0..eb7e06b54741beec641f536a645597698a5df986 100644 (file)
@@ -156,7 +156,10 @@ fetch_store_string(unsigned long addr, void *dest, void *base)
        if (unlikely(!maxlen))
                return -ENOMEM;
 
-       ret = strncpy_from_user(dst, src, maxlen);
+       if (addr == FETCH_TOKEN_COMM)
+               ret = strlcpy(dst, current->comm, maxlen);
+       else
+               ret = strncpy_from_user(dst, src, maxlen);
        if (ret >= 0) {
                if (ret == maxlen)
                        dst[ret - 1] = '\0';
@@ -180,7 +183,10 @@ fetch_store_strlen(unsigned long addr)
        int len;
        void __user *vaddr = (void __force __user *) addr;
 
-       len = strnlen_user(vaddr, MAX_STRING_SIZE);
+       if (addr == FETCH_TOKEN_COMM)
+               len = strlen(current->comm) + 1;
+       else
+               len = strnlen_user(vaddr, MAX_STRING_SIZE);
 
        return (len > MAX_STRING_SIZE) ? 0 : len;
 }
@@ -220,6 +226,9 @@ process_fetch_insn(struct fetch_insn *code, struct pt_regs *regs, void *dest,
        case FETCH_OP_IMM:
                val = code->immediate;
                break;
+       case FETCH_OP_COMM:
+               val = FETCH_TOKEN_COMM;
+               break;
        case FETCH_OP_FOFFS:
                val = translate_user_vaddr(code->immediate);
                break;