linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Andreas Ziegler <andreas.ziegler@fau.de>,
	Masami Hiramatsu <mhiramat@kernel.org>
Subject: [for-next][PATCH 04/13] tracing: uprobes: Re-enable $comm support for uprobe events
Date: Wed, 08 May 2019 16:24:31 -0400	[thread overview]
Message-ID: <20190508202452.369559913@goodmis.org> (raw)
In-Reply-To: 20190508202427.252736423@goodmis.org

From: Masami Hiramatsu <mhiramat@kernel.org>

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  |  1 +
 kernel/trace/trace_uprobe.c | 13 +++++++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h
index b7737666c1a8..f9a8c632188b 100644
--- a/kernel/trace/trace_probe.h
+++ b/kernel/trace/trace_probe.h
@@ -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 {
diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
index cd8750a72768..eb7e06b54741 100644
--- a/kernel/trace/trace_uprobe.c
+++ b/kernel/trace/trace_uprobe.c
@@ -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;
-- 
2.20.1



  parent reply	other threads:[~2019-05-08 20:25 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-08 20:24 [for-next][PATCH 00/13] tracing: Some more last minute changes and fixes Steven Rostedt
2019-05-08 20:24 ` [for-next][PATCH 01/13] x86_64: Add gap to int3 to allow for call emulation Steven Rostedt
2019-05-08 20:24 ` [for-next][PATCH 02/13] x86_64: Allow breakpoints to emulate call instructions Steven Rostedt
2019-05-08 20:24 ` [for-next][PATCH 03/13] ftrace/x86_64: Emulate call function while updating in breakpoint handler Steven Rostedt
2019-05-08 20:24 ` Steven Rostedt [this message]
2019-05-08 20:24 ` [for-next][PATCH 05/13] tracing: probeevent: Do not accumulate on ret variable Steven Rostedt
2019-05-08 20:24 ` [for-next][PATCH 06/13] tracing: probeevent: Fix to make the type of $comm string Steven Rostedt
2019-05-08 20:24 ` [for-next][PATCH 07/13] ring-buffer: Fix mispelling of Calculate Steven Rostedt
2019-05-08 20:24 ` [for-next][PATCH 08/13] tracing: Eliminate const char[] auto variables Steven Rostedt
2019-05-08 20:24 ` [for-next][PATCH 09/13] tracing: Fix white space issues in parse_pred() function Steven Rostedt
2019-05-08 20:24 ` [for-next][PATCH 10/13] tracing: Allow RCU to run between postponed startup tests Steven Rostedt
2019-05-08 20:24 ` [for-next][PATCH 11/13] tracing: Fix partial reading of trace events id file Steven Rostedt
2019-05-08 20:24 ` [for-next][PATCH 12/13] tracing: Replace kzalloc with kcalloc Steven Rostedt
2019-05-08 20:24 ` [for-next][PATCH 13/13] tracing: Fix documentation about disabling options using trace_options Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190508202452.369559913@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=akpm@linux-foundation.org \
    --cc=andreas.ziegler@fau.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).