[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <f01aae2a5936450f889fa5a7d350d363@AcuMS.aculab.com>
Date: Fri, 7 Oct 2022 11:58:06 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Theodore Ts'o' <tytso@....edu>, Kees Cook <keescook@...omium.org>
CC: Jorge Merlino <jorge.merlino@...onical.com>,
Christian Brauner <brauner@...nel.org>,
Eric Biederman <ebiederm@...ssion.com>,
Jann Horn <jannh@...gle.com>,
Alexander Viro <viro@...iv.linux.org.uk>,
Thomas Gleixner <tglx@...utronix.de>,
Andy Lutomirski <luto@...nel.org>,
"Sebastian Andrzej Siewior" <bigeasy@...utronix.de>,
Andrew Morton <akpm@...ux-foundation.org>,
"linux-mm@...ck.org" <linux-mm@...ck.org>,
"linux-fsdevel@...r.kernel.org" <linux-fsdevel@...r.kernel.org>,
John Johansen <john.johansen@...onical.com>,
Paul Moore <paul@...l-moore.com>,
James Morris <jmorris@...ei.org>,
"Serge E. Hallyn" <serge@...lyn.com>,
Stephen Smalley <stephen.smalley.work@...il.com>,
Eric Paris <eparis@...isplace.org>,
Richard Haines <richard_c_haines@...nternet.com>,
Casey Schaufler <casey@...aufler-ca.com>,
Xin Long <lucien.xin@...il.com>,
"David S. Miller" <davem@...emloft.net>,
Todd Kjos <tkjos@...gle.com>,
Ondrej Mosnacek <omosnace@...hat.com>,
Prashanth Prahlad <pprahlad@...hat.com>,
Micah Morton <mortonm@...omium.org>,
Fenghua Yu <fenghua.yu@...el.com>,
Andrei Vagin <avagin@...il.com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"apparmor@...ts.ubuntu.com" <apparmor@...ts.ubuntu.com>,
"linux-security-module@...r.kernel.org"
<linux-security-module@...r.kernel.org>,
"selinux@...r.kernel.org" <selinux@...r.kernel.org>,
"linux-hardening@...r.kernel.org" <linux-hardening@...r.kernel.org>
Subject: RE: [PATCH] Fix race condition when exec'ing setuid files
From: Theodore Ts'o
> Sent: 07 October 2022 02:41
>
> On Thu, Oct 06, 2022 at 01:20:35PM -0700, Kees Cook wrote:
> >
> > So the question, then, is "why are they trying to exec while actively
> > spawning new threads?" That appears to be the core problem here, and as
> > far as I can tell, the kernel has behaved this way for a very long time.
> > I don't think the kernel should fix this, either, because it leads to a
> > very weird state for userspace, where the thread spawner may suddenly
> > die due to the exec happening in another thread. This really looks like
> > something userspace needs to handle correctly (i.e. don't try to exec
> > while actively spawning threads).
>
> One of the classic failure modes is when a threaded program calls a
> library, and that library might try to do a fork/exec (or call
> system(3) to run some command. e.g., such as running "lvm create ..."
> or to spawn some kind of helper daemon.
>
> There are a number of stack overflow questions about this, and there
> are some solutions to _some_ of the problems, such as using
> pthread_atfork(), and knowing that you are about to call fork/exec,
> and use some out of band mechanism to to make sure no threads get
> spawned until the fork/exec is completed --- but if you don't know
> that a library is going to do a fork/exec, well, life is tough.
Or that a library thread is about to create a new thread.
> One technique even advocated by a stack overflow article is "avoid
> using threads whenver possible". :-/
Doesn't fork() only create the current thread in the new process?
So by the time exec() runs there is a nice single threaded process
with an fd table that isn't shared.
For helpers there is always (a properly implemented) posix_spawn() :-)
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Powered by blists - more mailing lists