From: Kees Cook <kees@kernel.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: "Zbigniew Jędrzejewski-Szmek" <zbyszek@in.waw.pl>,
"Eric W. Biederman" <ebiederm@xmission.com>,
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>
Subject: Re: [GIT PULL] execve updates for v6.13-rc1
Date: Thu, 21 Nov 2024 10:50:20 -0800 [thread overview]
Message-ID: <202411211011.C2E3ABEAB@keescook> (raw)
In-Reply-To: <CAHk-=whv4q-RBXmc9G7NZ4GiATqE_ORU05f=9g00HkQXbV7vqw@mail.gmail.com>
On Thu, Nov 21, 2024 at 10:02:03AM -0800, Linus Torvalds wrote:
> On Thu, 21 Nov 2024 at 10:00, Zbigniew Jędrzejewski-Szmek
> <zbyszek@in.waw.pl> wrote:
> >
> > Identical — as far as the callee is concerned.
> > Basically, we'd like to switch the execve() that we use in systemd
> > to start everything with fexecve(), but this should be invisible to
> > both the programs that are started and users who call ps/pgrep/….
>
> I'm not discussing this. If you cannot understand the difference
> between comm[] and argv[0], this discussion is entirely pointless.
>
> I'd suggest you just not use fexecve().
I think you're talking past each other. Here's my thought process:
To Linus's point, comm[] is "garbage" in that a process can change it to
anything it wants (i.e. PR_SET_NAME). I think everyone understands this,
but that's not what what I see as the issue.
What commp[] does have, however, is a "default" (starting) value set by
execve(), which is that of the basename of the "pathname" argument of
the syscall (yes, not argv[0], but see below).
Most process list analysis tools (i.e. "ps") use /proc/*/comm for the
short name view of a process. Most process launchers (i.e. shells,
systemd), tend to use basename(pathname) as argv[0] when running
programs. Again, I think everyone understands these things too, but I
think it's worth calling out that while comm[] and argv[0] are obviously
different things, in most cases they start out with identical values
after execve().
The problem is fexecve(), where the pathname is lost since it was,
obviously, only passed to open(). Right now, we re-use bprm->fdpath since
it was already there for scripts, but that unhelpfully just shoves the
fd number into comm[], making "ps" output unreadable. Nobody likes
seeing basename(fdpath) in comm[] today.
I don't think it's unreasonable to want to retain the basename(pathname)
starting value of comm[] when switching from execve() to fexecve().
Using the f_path name is certainly better than basename(fdpath), but it
doesn't really give userspace what they'd like nor expect. Since comm[]
is mutable anyway, why not just copy argv[0] for this case, as that
would give userspace exactly what it was expecting and does no harm?
i.e. yes, comm[] is "garbage", but let's replicate in fexecve() as close
to the default behavior we have from execve() as we can. Why expose
f_path, which doesn't appear in comm[] nor cmdline currently?
The only flip side I can see is that "ps" etc, should just never use comm
at all, and instead use argv[0] from cmdline. That would get the same
behavior as described here, but it is much more expensive in that is takes
the mm lock and has to walk userspace memory. But then we don't need
to change anything on the kernel side and just leave basename(fdpath)
alone. I would note, of course, that cmdline can also be changed by the
process (PR_SET_MM_ARG_START), too, so it is also "garbage". Just more
expensive garbage than comm[].
I still think the original proposal is the most helpful to userspace.
-Kees
--
Kees Cook
next prev parent reply other threads:[~2024-11-21 18:50 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-19 17:00 [GIT PULL] execve updates for v6.13-rc1 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
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 [this message]
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=202411211011.C2E3ABEAB@keescook \
--to=kees@kernel.org \
--cc=christophe.jaillet@wanadoo.fr \
--cc=dan.carpenter@linaro.org \
--cc=ebiederm@xmission.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.