Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: James Hogan <james.hogan@imgtec.com>
To: Trond Myklebust <trond.myklebust@primarydata.com>
Cc: Jeff Layton <jlayton@primarydata.com>,
	"J. Bruce Fields" <bfields@redhat.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	"Ingo Molnar" <mingo@redhat.com>,
	Stable Tree Mailing List <stable@vger.kernel.org>
Subject: Re: [PATCH] sunrpc: Fix trace events to store data in the struct
Date: Tue, 24 Feb 2015 13:46:00 +0000	[thread overview]
Message-ID: <54EC8098.6070709@imgtec.com> (raw)
In-Reply-To: <CAHQdGtS4s6A=woScsXTwmnRmCSCEWcUNoUGMmXCF_E=+BBH73w@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 4329 bytes --]

Hi Trond,

On 24/02/15 13:36, Trond Myklebust wrote:
> On Tue, Feb 24, 2015 at 6:47 AM, James Hogan <james.hogan@imgtec.com> wrote:
>> Commit 83a712e0afef ("sunrpc: add some tracepoints around enqueue and
>> dequeue of svc_xprt") merged in v3.19-rc1 added some new trace events,
>> however a couple of them printed data from dereferenced pointers rather
>> than storing the data in the struct. In general this isn't safe as the
>> print may not happen until later when the data may have changed or been
>> freed, and nor is it portable as userland won't have access to that
>> other data in order to interpret the trace data itself.
>>
>> Fix by copying the data into the struct and printing from there.
>>
>> Fixes: 83a712e0afef ("sunrpc: add some tracepoints around enqueue ...")
>> Signed-off-by: James Hogan <james.hogan@imgtec.com>
>> Cc: Jeff Layton <jlayton@primarydata.com>
>> Cc: J. Bruce Fields <bfields@redhat.com>
>> Cc: Trond Myklebust <trond.myklebust@primarydata.com>
>> Cc: Steven Rostedt <rostedt@goodmis.org>
>> Cc: Ingo Molnar <mingo@redhat.com>
>> Cc: <stable@vger.kernel.org> # v3.19+
>> ---
>> Build tested only. Perhaps somebody familiar with the code could give it
>> a spin to sanity check the trace output.
>> ---
>>  include/trace/events/sunrpc.h | 22 +++++++++++++++-------
>>  1 file changed, 15 insertions(+), 7 deletions(-)
>>
>> diff --git a/include/trace/events/sunrpc.h b/include/trace/events/sunrpc.h
>> index b9c1dc6c825a..47dfcaebfaaf 100644
>> --- a/include/trace/events/sunrpc.h
>> +++ b/include/trace/events/sunrpc.h
>> @@ -503,18 +503,22 @@ TRACE_EVENT(svc_xprt_do_enqueue,
>>
>>         TP_STRUCT__entry(
>>                 __field(struct svc_xprt *, xprt)
>> -               __field(struct svc_rqst *, rqst)
>> +               __field_struct(struct sockaddr_storage, ss)
>> +               __field(unsigned long, flags);
>> +               __field(int, pid)
>>         ),
>>
>>         TP_fast_assign(
>>                 __entry->xprt = xprt;
>> -               __entry->rqst = rqst;
>> +               xprt ? memcpy(&__entry->ss, &xprt->xpt_remote, sizeof(__entry->ss)) : memset(&__entry->ss, 0, sizeof(__entry->ss));
> 
> How could xprt ever be NULL here, and even if it was, why the esoteric
> C instead of a simple 'if' statement?

Yeh, I had a straight forward unconditional assignment before, but I
changed it purely for consistency with the svc_xprt_dequeue trace event.

I don't pretend to understand the details of what is being traced
though, so I'm happy to change it if required.

Thanks
James

> 
>> +               __entry->flags = xprt ? xprt->xpt_flags : 0;
>> +               __entry->pid = rqst ? rqst->rq_task->pid : 0;
>>         ),
>>
>>         TP_printk("xprt=0x%p addr=%pIScp pid=%d flags=%s", __entry->xprt,
>> -               (struct sockaddr *)&__entry->xprt->xpt_remote,
>> -               __entry->rqst ? __entry->rqst->rq_task->pid : 0,
>> -               show_svc_xprt_flags(__entry->xprt->xpt_flags))
>> +               (struct sockaddr *)&__entry->ss,
>> +               __entry->pid,
>> +               show_svc_xprt_flags(__entry->flags))
>>  );
>>
>>  TRACE_EVENT(svc_xprt_dequeue,
>> @@ -562,17 +566,21 @@ TRACE_EVENT(svc_handle_xprt,
>>
>>         TP_STRUCT__entry(
>>                 __field(struct svc_xprt *, xprt)
>> +               __field_struct(struct sockaddr_storage, ss)
>> +               __field(unsigned long, flags);
>>                 __field(int, len)
>>         ),
>>
>>         TP_fast_assign(
>>                 __entry->xprt = xprt;
>> +               xprt ? memcpy(&__entry->ss, &xprt->xpt_remote, sizeof(__entry->ss)) : memset(&__entry->ss, 0, sizeof(__entry->ss));
> 
> Ditto.
> 
>> +               __entry->flags = xprt ? xprt->xpt_flags : 0;
>>                 __entry->len = len;
>>         ),
>>
>>         TP_printk("xprt=0x%p addr=%pIScp len=%d flags=%s", __entry->xprt,
>> -               (struct sockaddr *)&__entry->xprt->xpt_remote, __entry->len,
>> -               show_svc_xprt_flags(__entry->xprt->xpt_flags))
>> +               (struct sockaddr *)&__entry->ss, __entry->len,
>> +               show_svc_xprt_flags(__entry->flags))
>>  );
>>  #endif /* _TRACE_SUNRPC_H */
>>
>> --
>> 2.0.5
>>
> 
> 
> 


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  reply	other threads:[~2015-02-24 13:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-24 11:47 [PATCH] sunrpc: Fix trace events to store data in the struct James Hogan
2015-02-24 13:36 ` Trond Myklebust
2015-02-24 13:46   ` James Hogan [this message]
2015-02-24 14:49   ` Steven Rostedt
2015-02-24 14:09 ` Steven Rostedt
2015-02-24 14:19   ` James Hogan
2015-02-24 14:48     ` Steven Rostedt
2015-02-24 16:03       ` David Ahern
2015-02-24 16:07         ` 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=54EC8098.6070709@imgtec.com \
    --to=james.hogan@imgtec.com \
    --cc=bfields@redhat.com \
    --cc=jlayton@primarydata.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=stable@vger.kernel.org \
    --cc=trond.myklebust@primarydata.com \
    /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