From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/14755 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: Hangup calling setuid() from vfork() child Date: Mon, 30 Sep 2019 13:43:11 -0400 Message-ID: <20190930174311.GS9017@brightrain.aerifal.cx> References: <20190930173928.GC2037@voyager> Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="190327"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-14771-gllmg-musl=m.gmane.org@lists.openwall.com Mon Sep 30 19:43:25 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.89) (envelope-from ) id 1iEzhl-000nRF-Ox for gllmg-musl@m.gmane.org; Mon, 30 Sep 2019 19:43:25 +0200 Original-Received: (qmail 13864 invoked by uid 550); 30 Sep 2019 17:43:23 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 13842 invoked from network); 30 Sep 2019 17:43:23 -0000 Content-Disposition: inline In-Reply-To: <20190930173928.GC2037@voyager> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:14755 Archived-At: On Mon, Sep 30, 2019 at 07:39:28PM +0200, Markus Wichmann wrote: > On Mon, Sep 30, 2019 at 08:29:16AM -0700, Joshua Hudson wrote: > > If there is more than one thread and vfork() calls setuid(), musl libc hangs up. > > > > void *thfunction(void*ig) {sleep(1000);returnNULL;} > > > > int main() > > { > > pthread_t id; > > pthread_create(&id, NULL, thfunction, NULL); > > if (vfork() == 0) { > > setuid(0); /* hangup */ > > _exit(0); > > } > > } > > That is an interesting interaction between threads and vfork(). > > The child process has only one thread, but it doesn't know that. It also > can't write it down, since it is sharing memory with the parent (it > would overwrite the parent's variables). > > POSIX no longer defines vfork(), and therefore does not define any > safety attributes for it. Is it reasonable to define vfork() as unusable > in a multithreaded process? Calling something as intricate as > __synccall() in a vfork() child is going to corrupt memory on a large > scale. It's simpler than that. The (retired) specification for vfork did not allow anything but _exit or execve in the child after vfork, so the issue doesn't arise and it works perfectly fine with threads as long as you follow the requirement. > posix_spawn() circumvents the problem by calling the system calls > directly, BTW. Yes, posix_spawn should be used if possible. It even has an attribute to reset ids to the real ones. Rich