From: "Eric W. Biederman" <ebiederm@xmission.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: "Kees Cook" <kees@kernel.org>,
linux-kernel@vger.kernel.org,
"Alexander Viro" <viro@zeniv.linux.org.uk>,
"Christophe JAILLET" <christophe.jaillet@wanadoo.fr>,
"Dan Carpenter" <dan.carpenter@linaro.org>,
"Nir Lichtman" <nir@lichtman.org>,
syzbot+03e1af5c332f7e0eb84b@syzkaller.appspotmail.com,
"Tycho Andersen" <tandersen@netflix.com>,
"Vegard Nossum" <vegard.nossum@oracle.com>,
"Zbigniew Jędrzejewski-Szmek" <zbyszek@in.waw.pl>
Subject: Re: [GIT PULL] execve updates for v6.13-rc1
Date: Wed, 20 Nov 2024 18:54:40 -0600 [thread overview]
Message-ID: <87jzcxv227.fsf@email.froward.int.ebiederm.org> (raw)
In-Reply-To: <CAHk-=wgB1L75+C89AU62n4jBEiwKs=e4dvBDOoLQ13rUwJLFXQ@mail.gmail.com> (Linus Torvalds's message of "Wed, 20 Nov 2024 14:32:44 -0800")
Linus Torvalds <torvalds@linux-foundation.org> writes:
> On Tue, 19 Nov 2024 at 09:00, Kees Cook <kees@kernel.org> 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.
__set_task_comm cannot be called with bprm->file->f_dentry
unconditionally. That will break userspace. On at least debian using
/etc/alternatives there are a lot of symlinks to executables.
For example if I run "vi", two symlinks are followed:
/usr/bin/vi -> /etc/alternatives/vi
/etc/alternatives/vi -> usr/bin/vim.nox
Seeing "vim.nox" in ps instead "vi" would be weird and break tooks like
psgrep.
https://lore.kernel.org/all/Zv1OayMEmLP2kjhj@kawka3.in.waw.pl/
The reason bprm->file->f_dentry.dentry was abandoned were concerns
about breaking userspace.
Limited to just the binaries that systemd wants to call. I don't know
if symlinks to binaries matters. At a quick skim I couldn't see
anything but *shrug*.
> 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.
bprm->fdpath is for passing the pathname of the script to an interpreter
like /bin/sh. That task->comm wind up being filled from it, is a bit
of a surprise.
> 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").
That should work for binfmt_script. I don't know which solution
is less racy, and less prone to problems in the binfmt_script case.
No one has complained so I have been assuming that case works just
fine.
> 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[]'
Again binfmt_script still uses it.
I can assure you there was no thought at all given to task->comm when
the contents of bprm->fdpath were chosen. Which is why there is
a problem now.
task->comm is for people. bprm->fdpath is for programs.
> - teach the code to use the dentry name instead
Which is fine for task->comm, when the pathname is NULL. Assuming it
actually makes things usable for userspace.
That doesn't work for bprm->fdpath with becomes bprm->interp. That
would require using d_path.
Eric
next prev parent reply other threads:[~2024-11-21 2:37 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-19 17:00 Kees Cook
2024-11-20 22:32 ` Linus Torvalds
2024-11-20 22:33 ` Linus Torvalds
2024-11-20 22:50 ` Linus Torvalds
2024-11-21 2:36 ` Al Viro
2024-11-21 2:41 ` Al Viro
2024-11-21 2:51 ` Linus Torvalds
2024-11-21 0:54 ` Eric W. Biederman [this message]
2024-11-21 2:23 ` Linus Torvalds
2024-11-21 2:29 ` Kees Cook
2024-11-21 2:45 ` Linus Torvalds
2024-11-21 17:22 ` Zbigniew Jędrzejewski-Szmek
2024-11-21 17:28 ` Linus Torvalds
2024-11-21 17:47 ` Linus Torvalds
2024-11-21 18:00 ` Zbigniew Jędrzejewski-Szmek
2024-11-21 18:02 ` Linus Torvalds
2024-11-21 18:47 ` Zbigniew Jędrzejewski-Szmek
2024-11-21 18:50 ` Kees Cook
2024-11-21 19:23 ` Linus Torvalds
2024-11-21 21:31 ` Zbigniew Jędrzejewski-Szmek
2024-11-21 21:48 ` Linus Torvalds
2024-11-21 22:24 ` Zbigniew Jędrzejewski-Szmek
2024-11-21 22:06 ` Kees Cook
2024-11-21 22:38 ` Linus Torvalds
[not found] ` <87zflrsw1c.fsf@email.froward.int.ebiederm.org>
2024-11-22 7:47 ` Zbigniew Jędrzejewski-Szmek
2024-11-22 10:21 ` Harald Arnesen
[not found] ` <87frnjqqh6.fsf@email.froward.int.ebiederm.org>
2024-11-24 15:21 ` Zbigniew Jędrzejewski-Szmek
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=87jzcxv227.fsf@email.froward.int.ebiederm.org \
--to=ebiederm@xmission.com \
--cc=christophe.jaillet@wanadoo.fr \
--cc=dan.carpenter@linaro.org \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nir@lichtman.org \
--cc=syzbot+03e1af5c332f7e0eb84b@syzkaller.appspotmail.com \
--cc=tandersen@netflix.com \
--cc=torvalds@linux-foundation.org \
--cc=vegard.nossum@oracle.com \
--cc=viro@zeniv.linux.org.uk \
--cc=zbyszek@in.waw.pl \
/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
all inboxes | Powered by JetHome®