Re: [GIT PULL] execve updates for v6.13-rc1
From: Linus Torvalds
Date: Wed Nov 20 2024 - 17:33:15 EST
On Tue, 19 Nov 2024 at 09:00, Kees Cook <kees@xxxxxxxxxx> wrote:
>
> - exec: Use argv[0] for "comm" with AT_EMPTY_PATH (Tycho Andersen,
> Dan Carpenter, Nir Lichtman)
Ugh. I *really* despise this one.
People: we *have* a filename. It's right there in the dentry. Which is
right there as bprm->file->f_dentry.dentry.
And that's actually going to match the actual execcutable, unlike, for
example, argv[0], which can be filled in with random data.
*AND* we don't need any silly and expensive get_user_arg_ptr() and
strndup_user() copy for it, which does that user access twice.
And no, we shouldn't fall back to the horrid thing that bprm->fdpath
does either. That's the thing that you apparently thought was too ugly
to use, and literally the *only* use of it was for this case.
The reason that code existed at all was to generate a filename, and
because we didn't use to have access to the 'bprm->file' back in the
days.
But that was changed by commit 978ffcbf00d8 ("execve: open the
executable file before doing anything else").
So I really really think that what this code *should* have done is
- get rid of fdpath that you made pointless by not using it for 'comm[]'
- teach the code to use the dentry name instead
because this horrible hack is too broken to live.
Linus