From: Linus Torvalds <[email protected]>
To: Kees Cook <[email protected]>
Cc: "Eric Biederman" <[email protected]>,
"Alexander Viro" <[email protected]>,
"Christian Brauner" <[email protected]>,
"Jan Kara" <[email protected]>,
[email protected], [email protected],
"Ingo Molnar" <[email protected]>,
"Peter Zijlstra" <[email protected]>,
"Juri Lelli" <[email protected]>,
"Vincent Guittot" <[email protected]>,
"Dietmar Eggemann" <[email protected]>,
"Steven Rostedt" <[email protected]>,
"Ben Segall" <[email protected]>, "Mel Gorman" <[email protected]>,
"Valentin Schneider" <[email protected]>,
"Jens Axboe" <[email protected]>,
"Pavel Begunkov" <[email protected]>,
"Andrew Morton" <[email protected]>,
"Chen Yu" <[email protected]>,
"Shuah Khan" <[email protected]>,
"Mickaël Salaün" <[email protected]>,
[email protected], [email protected],
[email protected]
Subject: Re: [PATCH] exec: Make sure task->comm is always NUL-terminated
Date: Sun, 1 Dec 2024 12:23:26 -0800 [thread overview]
Message-ID: <CAHk-=wiGWbU-MpmrXnHdqey5kDkyXnPxQ-ZsGVGBkZQ5d5g0mw@mail.gmail.com> (raw)
In-Reply-To: <CAHk-=wjAmu9OBS--RwB+HQn4nhUku=7ECOnSRP8JG0oRU97-kA@mail.gmail.com>
On Fri, 29 Nov 2024 at 23:15, Linus Torvalds
<[email protected]> 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
next prev parent reply other threads:[~2024-12-01 20:23 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-30 4:49 [PATCH] exec: Make sure task->comm is always NUL-terminated Kees Cook
2024-11-30 7:15 ` Linus Torvalds
2024-11-30 21:05 ` Kees Cook
2024-11-30 21:33 ` Linus Torvalds
2024-12-01 20:23 ` Linus Torvalds [this message]
2024-11-30 21:40 ` David Laight
2024-12-01 21:49 ` Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAHk-=wiGWbU-MpmrXnHdqey5kDkyXnPxQ-ZsGVGBkZQ5d5g0mw@mail.gmail.com' \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox