Commit b45605fa authored by Kees Cook's avatar Kees Cook Committed by Greg Kroah-Hartman
Browse files

exec: fix up /proc/pid/comm in the execveat(AT_EMPTY_PATH) case



[ Upstream commit 543841d1 ]

Zbigniew mentioned at Linux Plumber's that systemd is interested in
switching to execveat() for service execution, but can't, because the
contents of /proc/pid/comm are the file descriptor which was used,
instead of the path to the binary[1]. This makes the output of tools like
top and ps useless, especially in a world where most fds are opened
CLOEXEC so the number is truly meaningless.

When the filename passed in is empty (e.g. with AT_EMPTY_PATH), use the
dentry's filename for "comm" instead of using the useless numeral from
the synthetic fdpath construction. This way the actual exec machinery
is unchanged, but cosmetically the comm looks reasonable to admins
investigating things.

Instead of adding TASK_COMM_LEN more bytes to bprm, use one of the unused
flag bits to indicate that we need to set "comm" from the dentry.

Suggested-by: default avatarZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Suggested-by: default avatarTycho Andersen <tandersen@netflix.com>
Suggested-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
Suggested-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
Link: https://github.com/uapi-group/kernel-features#set-comm-field-before-exec

 [1]
Reviewed-by: default avatarAleksa Sarai <cyphar@cyphar.com>
Tested-by: default avatarZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Signed-off-by: default avatarKees Cook <kees@kernel.org>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 4dcd3360
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment