[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAHk-=wixR7ZR+aebFsWX4qWZ84tMTmyNWLUPmTy3YvaNJGqd-Q@mail.gmail.com>
Date: Sat, 26 Jul 2025 16:37:33 -0700
From: Linus Torvalds <torvalds@...ux-foundation.org>
To: Kees Cook <kees@...nel.org>
Cc: Bhupesh <bhupesh@...lia.com>, akpm@...ux-foundation.org, kernel-dev@...lia.com,
linux-kernel@...r.kernel.org, bpf@...r.kernel.org,
linux-perf-users@...r.kernel.org, linux-fsdevel@...r.kernel.org,
linux-mm@...ck.org, oliver.sang@...el.com, lkp@...el.com,
laoar.shao@...il.com, pmladek@...e.com, rostedt@...dmis.org,
mathieu.desnoyers@...icios.com, arnaldo.melo@...il.com,
alexei.starovoitov@...il.com, andrii.nakryiko@...il.com,
mirq-linux@...e.qmqm.pl, peterz@...radead.org, willy@...radead.org,
david@...hat.com, viro@...iv.linux.org.uk, ebiederm@...ssion.com,
brauner@...nel.org, jack@...e.cz, mingo@...hat.com, juri.lelli@...hat.com,
bsegall@...gle.com, mgorman@...e.de, vschneid@...hat.com,
linux-trace-kernel@...r.kernel.org
Subject: Re: [PATCH v6 2/3] treewide: Switch memcpy() users of 'task->comm' to
a more safer implementation
On Sat, 26 Jul 2025 at 16:19, Kees Cook <kees@...nel.org> wrote:
>
> That works for me! I just get twitchy around seeing memcpy used for strings. :) if we're gonna NUL after the memcpy, just use strscpy_pad().
I do worry a tiny bit about performance.
Because 'memcpy+set last byte to NUL' really is just a couple of
instructions when we're talking small constant-sized arrays.
strscpy_pad() isn't horrible, but it's still at another level. And
most of the cost is that "return the length" which people often don't
care about.
Dang, I wish we had some compiler trick to say "if the value isn't
used, do X, if it _is_ used do Y".
It's such a trivial thing in the compiler itself, and the information
is there, but I don't think it is exposed in any useful way.
In fact, it *is* exposed in one way I can think of:
__attribute__((__warn_unused_result__))
but not in a useful form for actually generating different code.
Some kind of "__builtin_if_used(x,y)" where it picks 'x' if the value
is used, and 'y' if it isn't would be lovely for this.
Then you could do things like
#define my_helper(x) \
__builtin_if_used( \
full_semantics(x), \
simpler_version(x))
when having a return value means extra work and most people don't care.
Maybe it exists in some form that I haven't thought of?
Any compiler people around?
Linus
Powered by blists - more mailing lists