linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] fs/exec: Explicitly unshare fs_struct on exec
@ 2022-10-06  8:27 Kees Cook
  2022-10-06  8:27 ` [PATCH 1/2] " Kees Cook
  2022-10-06  8:27 ` [PATCH 2/2] exec: Remove LSM_UNSAFE_SHARE Kees Cook
  0 siblings, 2 replies; 15+ messages in thread
From: Kees Cook @ 2022-10-06  8:27 UTC (permalink / raw)
  To: Eric Biederman
  Cc: Kees Cook, Jorge Merlino, Al Viro, Christian Brauner (Microsoft),
	Thomas Gleixner, Andy Lutomirski, Sebastian Andrzej Siewior,
	Andrew Morton, John Johansen, Paul Moore, James Morris,
	Serge E. Hallyn, Stephen Smalley, Eric Paris, Richard Haines,
	Casey Schaufler, Xin Long, David S. Miller, Todd Kjos,
	Ondrej Mosnacek, Prashanth Prahlad, Micah Morton, Fenghua Yu,
	Andrei Vagin, linux-kernel, linux-mm, linux-fsdevel, apparmor,
	linux-security-module, selinux, linux-hardening

Hi,

These changes seek to address an issue reported[1] by Jorge Merlino where
high-thread-count processes would sometimes fail to setuid during a
setuid execve().

It looks to me like the solution is to explicitly do an unshare_fs(),
which should almost always be a no-op. Current testing seems to indicate
that only the swapper->init exec triggers this condition (and I'm unclear
on whether that's expected or undesirable). This has only received very
light testing so far, but I wanted to share it so other folks could look
it over.

Jorge, can you test with these patches? Your PoC triggered immediately
for me on an unpatched kernel, and did not trigger on a patched one.

I added this patch on top of the series to see if the code ever fired:

diff --git a/kernel/fork.c b/kernel/fork.c
index 53b7248f7a4b..3c197d9d8daa 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -3113,6 +3113,7 @@ int unshare_fs(void)
 	if (error || !new_fs)
 		return error;
 
+	pr_notice("UNSHARE of \"%s\" [%d]\n", current->comm, current->pid);
 	unshare_fs_finalize(&new_fs);
 
 	if (new_fs)

Thanks!

-Kees

[1] https://lore.kernel.org/lkml/20220910211215.140270-1-jorge.merlino@canonical.com/

Kees Cook (2):
  fs/exec: Explicitly unshare fs_struct on exec
  exec: Remove LSM_UNSAFE_SHARE

 fs/exec.c                  | 26 ++++------------
 fs/fs_struct.c             |  1 -
 include/linux/fdtable.h    |  1 +
 include/linux/fs_struct.h  |  1 -
 include/linux/security.h   |  5 ++-
 kernel/fork.c              | 62 ++++++++++++++++++++++++++------------
 security/apparmor/domain.c |  5 ---
 security/selinux/hooks.c   | 10 ------
 8 files changed, 51 insertions(+), 60 deletions(-)

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2022-11-28 18:31 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-06  8:27 [PATCH 0/2] fs/exec: Explicitly unshare fs_struct on exec Kees Cook
2022-10-06  8:27 ` [PATCH 1/2] " Kees Cook
2022-10-06  9:05   ` Christian Brauner
2022-10-06 10:48     ` David Laight
2022-10-06 14:13     ` Jann Horn
2022-10-06 15:25       ` Kees Cook
2022-10-06 15:35         ` Jann Horn
2022-10-14  3:18       ` Andy Lutomirski
2022-10-14  3:54         ` Kees Cook
2022-10-14 15:35         ` Jann Horn
2022-10-18  7:09           ` Kees Cook
2022-10-18 11:19             ` Jann Horn
2022-10-14 22:03         ` David Laight
2022-11-28 17:49           ` Eric W. Biederman
2022-10-06  8:27 ` [PATCH 2/2] exec: Remove LSM_UNSAFE_SHARE Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).