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

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

 



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!

>         ),
> 
>         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


>         ),




[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