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

From: Linus Torvalds
Date: Sat Nov 13 2021 - 13:27:17 EST


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.

So if I read this all right, if you ever have a FILTER_STATIC_STRING
or a FILTER_PTR_STRING that has a field->size that is larger than
STR_VAR_LEN_MAX, you're now screwed.

Maybe that is unrealistic, and never happens. And yes, STR_VAR_LEN_MAX
is fairly big, but I would personally be happier if these kinds of
things checked BOTH the source limits and the destination limits.

And no, we don't have that kind of string helper. I've talked about
this before: people tend to always think that string copies are about
"either source limit or destination limit", but the fact is, both can
exist.

Linus