Re: [PATCH] trace: events: cleanup deprecated strncpy uses

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Apr 10, 2024 at 11:36:14AM -0400, Steven Rostedt wrote:
> On Mon, 01 Apr 2024 23:48:52 +0000
> Justin Stitt <justinstitt@xxxxxxxxxx> wrote:
> 
> > diff --git a/include/trace/events/rpcgss.h b/include/trace/events/rpcgss.h
> > index ba2d96a1bc2f..274c297f1b15 100644
> > --- a/include/trace/events/rpcgss.h
> > +++ b/include/trace/events/rpcgss.h
> > @@ -618,7 +618,7 @@ TRACE_EVENT(rpcgss_context,
> >  		__entry->timeout = timeout;
> >  		__entry->window_size = window_size;
> >  		__entry->len = len;
> > -		strncpy(__get_str(acceptor), data, len);
> > +		memcpy(__get_str(acceptor), data, len);
> >  	),
> >  
> >  	TP_printk("win_size=%u expiry=%lu now=%lu timeout=%u acceptor=%.*s",
> 
> WTF, that code is just buggy. Looking at the rpcgss_context event we have:
> 
> > TRACE_EVENT(rpcgss_context,
> >         TP_PROTO(
> >                 u32 window_size,
> >                 unsigned long expiry,
> >                 unsigned long now,
> >                 unsigned int timeout,
> >                 unsigned int len,
> >                 const u8 *data
> >         ),
> > 
> >         TP_ARGS(window_size, expiry, now, timeout, len, data),
> > 
> >         TP_STRUCT__entry(
> >                 __field(unsigned long, expiry)
> >                 __field(unsigned long, now)
> >                 __field(unsigned int, timeout)
> >                 __field(u32, window_size)
> >                 __field(int, len)
> >                 __string(acceptor, data)
> 
> The __string() macro expects "data" to be a string and does *not* check
> length when copying.
> 
> If anything, it needs to be:
> 
> 		__string_len(acceptor, data, len)
> 
> as the macro code has changed recently, and the current code will crash!

A general question:

Is there a test suite we should run regularly to build some
confidence in the kernel's observability apparatus? We're building
a menagerie of tests around kdevops, and one area where we know
there is a testing gap is the tracepoints in NFSD and SunRPC.


> >         ),
> > 
> >         TP_fast_assign(
> >                 __entry->expiry = expiry;
> >                 __entry->now = now;
> >                 __entry->timeout = timeout;
> >                 __entry->window_size = window_size;
> >                 __entry->len = len;
> >                 strncpy(__get_str(acceptor), data, len);
> 
> Then this needs to be:
> 
> 		__assign_str(acceptor, data);
> 
> Note, the length is now saved via __string_len() and not needed here.
> 
> I'll go send a patch to fix this.
> 
> -- Steve
> 
> 
> >         ),

-- 
Chuck Lever




[Index of Archives]     [Linux Filesystem Development]     [Linux USB Development]     [Linux Media Development]     [Video for Linux]     [Linux NILFS]     [Linux Audio Users]     [Yosemite Info]     [Linux SCSI]

  Powered by Linux