From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 29229 invoked from network); 13 Oct 2020 16:08:00 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 13 Oct 2020 16:08:00 -0000 Received: (qmail 31856 invoked by uid 550); 13 Oct 2020 16:07:58 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 31838 invoked from network); 13 Oct 2020 16:07:57 -0000 Date: Tue, 13 Oct 2020 12:07:45 -0400 From: Rich Felker To: Alexey Izbyshev Cc: musl@lists.openwall.com Message-ID: <20201013160744.GQ17637@brightrain.aerifal.cx> References: <93cbaeffbc860a145843e0380058c50e@ispras.ru> <20201012145549.GG17637@brightrain.aerifal.cx> <20201013024737.GB7816@voyager> <208f256649f23621ada37409eb02ff86@ispras.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <208f256649f23621ada37409eb02ff86@ispras.ru> User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] Calling setxid() in a vfork()-child On Tue, Oct 13, 2020 at 06:24:45PM +0300, Alexey Izbyshev wrote: > On 2020-10-13 05:47, Markus Wichmann wrote: > >If dropping privileges is all you want, then posix_spawn() has a flag > >for that. And if you are foregoing portability anyway by doing anything > >between vfork() and execve(), might as well use clone() and do it > >properly. > > > What do you mean by "do it properly"? Unless you mean doing > syscalls, it seems that I'd have the same issues with clone() (with > CLONE_VFORK, since I'm trying to avoid copying of page tables) as I > do with vfork(). Namely, I'd still have to care about signals, and I > wouldn't be able to safely call setxid() (and, frankly, anything > else from a C library if we want a solution that's, while being > Linux-specific, still portable across C libraries). Indeed, it's not safe to call libc functions from a CLONE_VM context. We might want to make some sort of contract about a subset that are safe to call, but right now there really isn't such a set. AS-safe functions might be close, and indeed after the __synccall change set*id should in theory work from a clone() context too. Really, unless you're trying to support NOMMU, "do it properly" means just forgetting about CLONE_VM if posix_spawn doesn't meet your needs and using plain fork+...+exec. Rich