Re: [GIT PULL] tracing: Three small fixes for 5.16

From: Steven Rostedt
Date: Sun Nov 14 2021 - 12:43:26 EST


On Sat, 13 Nov 2021 10:26:29 -0800
Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:

> On Sat, Nov 13, 2021 at 5:35 AM Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
> >
> > - Copy just actual size of histogram strings
>
> I have pulled this, but I think it's wrong. Or at least it looks
> _very_ suspicious.
>
> > - strscpy(str, val_str, STR_VAR_LEN_MAX);
> > + strscpy(str, val_str, val->size);
>
> So now it doesn't overrun the source string any more, but I don't see
> what protects it from not overrunning the destination - which is
> indeed STR_VAR_LEN_MAX.
>
> Maybe 'val->size' is guaranteed to be sufficiently limited, but that
> sure as hell isn't obvious at least lkocally.

Ideally this should be checked on the time the histogram is created.
But looking into it, the size could be determined by the size of a
string of an event field. Now in practice, no event field should be
bigger than 256 bytes, but nothing prevents it from happening.

I'll add logic here to include:

size = min(val->size, STR_VAR_LEN_MAX);

and use that instead.

-- Steve