[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHk-=wiGWbU-MpmrXnHdqey5kDkyXnPxQ-ZsGVGBkZQ5d5g0mw@mail.gmail.com>
Date: Sun, 1 Dec 2024 12:23:26 -0800
From: Linus Torvalds <torvalds@...ux-foundation.org>
To: Kees Cook <kees@...nel.org>
Cc: Eric Biederman <ebiederm@...ssion.com>, Alexander Viro <viro@...iv.linux.org.uk>,
Christian Brauner <brauner@...nel.org>, Jan Kara <jack@...e.cz>, linux-mm@...ck.org,
linux-fsdevel@...r.kernel.org, Ingo Molnar <mingo@...hat.com>,
Peter Zijlstra <peterz@...radead.org>, Juri Lelli <juri.lelli@...hat.com>,
Vincent Guittot <vincent.guittot@...aro.org>, Dietmar Eggemann <dietmar.eggemann@....com>,
Steven Rostedt <rostedt@...dmis.org>, Ben Segall <bsegall@...gle.com>, Mel Gorman <mgorman@...e.de>,
Valentin Schneider <vschneid@...hat.com>, Jens Axboe <axboe@...nel.dk>,
Pavel Begunkov <asml.silence@...il.com>, Andrew Morton <akpm@...ux-foundation.org>,
Chen Yu <yu.c.chen@...el.com>, Shuah Khan <skhan@...uxfoundation.org>,
Mickaël Salaün <mic@...ikod.net>,
linux-kernel@...r.kernel.org, io-uring@...r.kernel.org,
linux-hardening@...r.kernel.org
Subject: Re: [PATCH] exec: Make sure task->comm is always NUL-terminated
On Fri, 29 Nov 2024 at 23:15, Linus Torvalds
<torvalds@...ux-foundation.org> wrote:
>
> And yes, we could make the word-at-a-time case also know about masking
> the last word, but it's kind of annoying and depends on byte ordering.
Actually, it turned out to be really trivial to do. It does depend on
byte order, but not in a very complex way.
Also, doing the memory accesses with READ_ONCE() might be good for
clarity, but it makes gcc have conniptions and makes the code
generation noticeably worse.
I'm not sure why, but gcc stops doing address generation in the memory
instruction for volatile accesses. I've seen that before, but
completely forgot about how odd the code generation becomes.
This actually generates quite good code - apart from the later
'memset()' by strscpy_pad(). Kind of sad, since the word-at-a-time
code by 'strscpy()' actually handles comm[] really well (the buffer is
a nice multiple of the word length), and extending it to padding would
be trivial.
The whole sized_strscpy_pad() macro is in fact all kinds of stupid. It does
__wrote = sized_strscpy(__dst, __src, __count);
if (__wrote >= 0 && __wrote < __count)
and that '__wrote' name is actively misleading, and the "__wrote <
__count" test is pointless.
The underlying sized_strscpy() function doesn't return how many
characters it wrote, it returns the length of the resulting string (or
error if it truncated it), so the return value is *always* smaller
than __count.
That's the whole point of the function, after all.
Oh well. I'll just commit my strscpy() improvement as a fix.
And I'll think about how to do the "pad" version better too. Just because.
Linus
Powered by blists - more mailing lists