lkml.org 
[lkml]   [2024]   [Apr]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH] trace: events: cleanup deprecated strncpy uses
On Mon, 01 Apr 2024 23:48:52 +0000
Justin Stitt <justinstitt@google.com> 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


> ),

\
 
 \ /
  Last update: 2024-05-27 16:33    [W:0.071 / U:0.220 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site