mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Masami Hiramatsu <mhiramat@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Andreas Ziegler <andreas.ziegler@fau.de>,
	Ingo Molnar <mingo@redhat.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/3] tracing: uprobes: Re-enable $comm support for uprobe events
Date: Thu, 24 Jan 2019 12:03:43 +0900	[thread overview]
Message-ID: <20190124120343.dca2887200a50c3f3ad1186b@kernel.org> (raw)
In-Reply-To: <20190123210956.0178b890@vmware.local.home>

On Wed, 23 Jan 2019 21:09:56 -0500
Steven Rostedt <rostedt@goodmis.org> wrote:

> On Thu, 24 Jan 2019 10:43:22 +0900
> Masami Hiramatsu <mhiramat@kernel.org> wrote:
> 
> > > >  kernel/trace/trace_uprobe.c |   15 +++++++++++++--
> > > >  1 file changed, 13 insertions(+), 2 deletions(-)
> > > > 
> > > > diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
> > > > index 3a1d5ab6b4ba..b07e498ccbc6 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 == (unsigned long)current->comm)
> > > > +		ret = strlcpy(dst, current->comm, maxlen);  
> > > 
> > > As user space (although only root) defines the size of the event being
> > > stored, and we could trick addr to be current->comm (although
> > > difficult), we could possibly leak data if maxlen is > TASK_COMM_LEN. I
> > > would feel better if we tested maxlen against TASK_COMM_LEN in this
> > > case.
> > > 
> > > 	if (maxlen > TASK_COMM_LEN)
> > > 		maxlen = TASK_COMM_LEN;
> > > 
> > > Or if we don't think it can happen, add a WARN_ON(maxlen >
> > > TASK_COMM_LEN).  
> > 
> > Hmm, I thought current->comm is null terminated, isn't it?
> 
> Yes it is. I was thinking it was a memcpy (I blame conference fatigue ;-)
> 
> > Anyway, if user can specify current->comm, he must be able to specify 
> > current->comm + TASK_COMM_LEN too by kprobe_events.
> > Moreover, it can leak any data in kernel...
> 
> But this is for uprobes, which I why I was concerned.

OK, what we will leak by this, is the address of current->comm to root
user for a specific application running instance.
Since they can try to write a data on a register and trace it like
"+0(%ax):string" and if rax register has hit the current->comm,
uprobe event will record comm, but other case, it will show "(fault)".
So they can trial and error on that (but leaking just a temporary
task instance address).

If you concern this, I can change it to store a special fixed value, like
(unsigned long)-EINVAL, instead of current->comm address. :-)

> > And also, maxlen is calculated by fetch_store_strlen, right before
> > this has been called.
> > 
> > I rather concern the case that if we have shorter size of maxlen than
> > current->comm. Would we better show "(fault)" or tail-cut name ?
> > (of course this is very difficult to happen, since the length is
> > already checked.)
> 
> Actually, it would still be OK, as strlcpy does guarantee to be nul
> terminated as long as it's greater than zero.

Ah, I meant that we can record a shorter name, like "shutdown" -> "sh". 

> Hmm, strlcpy doesn't pad the rest if what is written is shorter than
> what is allocated. Could that leak data?

Even though, there should be a data that had been recorded on the ring
buffer.

Thank you,

-- 
Masami Hiramatsu <mhiramat@kernel.org>

  reply	other threads:[~2019-01-24  3:03 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-18  4:43 [PATCH v2 0/3] tracing: probeevent: Fix probe argument parser and handler Masami Hiramatsu
2019-01-18  4:44 ` [PATCH v2 1/3] tracing: uprobes: Re-enable $comm support for uprobe events Masami Hiramatsu
2019-01-23  8:40   ` Steven Rostedt
2019-01-24  1:43     ` Masami Hiramatsu
2019-01-24  2:09       ` Steven Rostedt
2019-01-24  3:03         ` Masami Hiramatsu [this message]
2019-02-06 20:52   ` Steven Rostedt
2019-02-08  0:42     ` Masami Hiramatsu
2019-01-18  4:44 ` [PATCH v2 2/3] tracing: probeevent: Do not accumulate on ret variable Masami Hiramatsu
2019-01-18  4:45 ` [PATCH v2 3/3] tracing: probeevent: Fix to make the type of $comm string Masami Hiramatsu

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=20190124120343.dca2887200a50c3f3ad1186b@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=andreas.ziegler@fau.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=rostedt@goodmis.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

Powered by JetHome