Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751790AbcDRB6D (ORCPT ); Sun, 17 Apr 2016 21:58:03 -0400 Received: from slow1-d.mail.gandi.net ([217.70.178.86]:37741 "EHLO slow1-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751323AbcDRB6B (ORCPT ); Sun, 17 Apr 2016 21:58:01 -0400 X-Originating-IP: 50.39.163.18 Date: Sun, 17 Apr 2016 18:57:36 -0700 From: Josh Triplett To: "H. Peter Anvin" Cc: Colin Walters , "Richard W.M. Jones" , linux-kernel@vger.kernel.org, tglx@linutronix.de, mingo@redhat.com, akpm@linux-foundation.org, luto@kernel.org, viro@zeniv.linux.org.uk, mathieu.desnoyers@efficios.com, zab@redhat.com, emunson@akamai.com, paulmck@linux.vnet.ibm.com, aarcange@redhat.com, xemul@parallels.com, sfr@canb.auug.org.au, milosz@adfin.com, rostedt@goodmis.org, arnd@arndb.de, ebiederm@xmission.com, gorcunov@openvz.org, iulia.manda21@gmail.com, dave.hansen@linux.intel.com, mguzik@redhat.com, adobriyan@gmail.com, dave@stgolabs.net, linux-api@vger.kernel.org, gorcunov@gmail.com, fw@deneb.enyo.de Subject: Re: [PATCH v2 0/2] vfs: Define new syscall getumask. Message-ID: <20160418015736.GA16600@x> References: <1460552272-15985-1-git-send-email-rjones@redhat.com> <1460562105.353100.577697153.013DF466@webmail.messagingengine.com> <57143B74.3070302@zytor.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <57143B74.3070302@zytor.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1826 Lines: 40 On Sun, Apr 17, 2016 at 06:42:12PM -0700, H. Peter Anvin wrote: > On 04/13/16 08:41, Colin Walters wrote: > > On Wed, Apr 13, 2016, at 08:57 AM, Richard W.M. Jones wrote: > > > >> It's not possible to read the process umask without also modifying it, > >> which is what umask(2) does. A library cannot read umask safely, > >> especially if the main program might be multithreaded. > > > > I assume you just want to do this from a shared library so you can > > determine whether or not you need to call fchown() after making files > > and the like? If that's the case it'd be good to note it in the commit > > message. > > > > BTW...it might be a good idea to add a flags argument: > > https://lwn.net/Articles/585415/ > > > > Did you consider calling this `umask2`, having the initial version only support > > retrieving it via a UMASK_GET flag, and lay the groundwork to support > > setting a threadsafe umask with a UMASK_SET_THREAD flag? > > > > The comments on that article also list a number of problems with this > approach, related to how undefined flags are handled. > > In fact, if it wasn't for this exact problem then umask(-1) would have > been the logical way to deal with this, but because umask(2) is defined > to have an internal & 07777 it becomes infeasible at least in theory. > In practice it might work... > > However, see previous discussions about making this available in /proc. > Also, I really think there is something to be said for a O_NOUMASK > option... O_NOUMASK seems potentially useful to support implementation of umask entirely in userspace, which also addresses thread-safety. A program could read its process umask out at startup, handle umask entirely in userspace (including for threads), and only interact with the system umask after fork and before exec. - Josh Triplett