Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751481AbcDONaA (ORCPT ); Fri, 15 Apr 2016 09:30:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37003 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751137AbcDON36 (ORCPT ); Fri, 15 Apr 2016 09:29:58 -0400 Date: Fri, 15 Apr 2016 14:29:52 +0100 From: "Richard W.M. Jones" To: Michal Hocko Cc: linux-kernel@vger.kernel.org, corbet@lwn.net, akpm@linux-foundation.org, vbabka@suse.cz, hughd@google.com, koct9i@gmail.com, chenhanxiao@cn.fujitsu.com, n-horiguchi@ah.jp.nec.com, ross.zwisler@linux.intel.com, john.stultz@linaro.org, minchan@kernel.org, jmarchan@redhat.com, hannes@cmpxchg.org, nathans@redhat.com, andriy.shevchenko@linux.intel.com, keescook@chromium.org, gorcunov@openvz.org, joe@perches.com, linux@rasmusvillemoes.dk, mingo@kernel.org, cmetcalf@ezchip.com, iago@endocode.com, luto@kernel.org, linux-doc@vger.kernel.org, gorcunov@gmail.com, fw@deneb.enyo.de, walters@verbum.org Subject: Re: [PATCH v2] procfs: expose umask in /proc//status Message-ID: <20160415132952.GZ11600@redhat.com> References: <1460632095-434-1-git-send-email-rjones@redhat.com> <1460632095-434-2-git-send-email-rjones@redhat.com> <20160415131309.GK32377@dhcp22.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160415131309.GK32377@dhcp22.suse.cz> User-Agent: Mutt/1.5.20 (2009-12-10) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4493 Lines: 118 On Fri, Apr 15, 2016 at 03:13:10PM +0200, Michal Hocko wrote: > On Thu 14-04-16 12:08:15, 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. > > It would be helpful to describe the usecase a bit better. Who needs to > read the umask and what for (e.g. what if the umask changes right after > it has been read by the 3rd party?). > > I am not opposing the patch as is but this exports a new information to > the userspace and we will have to maintain it for ever, so we should > better describe the usecase. The use case is that we have endless trouble with people setting weird umask() values (usually on the grounds of "security"), and then everything breaking. I'm on the hook to fix these. We'd like to add debugging to our program so we can dump out the umask in debug reports. Previous versions of the patch used a syscall so you could only read your own umask. That's all I need. However there was quite a lot of push-back from those, so this new version exports it in /proc. See: https://lkml.org/lkml/2016/4/13/704 [umask2] https://lkml.org/lkml/2016/4/13/487 [getumask] Rich. > > Add a new status line ("Umask") in /proc//status. It contains > > the file mode creation mask (umask) in octal. It is only shown for > > tasks which have task->fs. > > > > This patch is adapted from one originally written by Pierre Carrier. > > > > Signed-off-by: Richard W.M. Jones > > --- > > Documentation/filesystems/proc.txt | 1 + > > fs/proc/array.c | 20 +++++++++++++++++++- > > 2 files changed, 20 insertions(+), 1 deletion(-) > > > > diff --git a/Documentation/filesystems/proc.txt b/Documentation/filesystems/proc.txt > > index 7f5607a..e8d0075 100644 > > --- a/Documentation/filesystems/proc.txt > > +++ b/Documentation/filesystems/proc.txt > > @@ -225,6 +225,7 @@ Table 1-2: Contents of the status files (as of 4.1) > > TracerPid PID of process tracing this process (0 if not) > > Uid Real, effective, saved set, and file system UIDs > > Gid Real, effective, saved set, and file system GIDs > > + Umask file mode creation mask > > FDSize number of file descriptor slots currently allocated > > Groups supplementary group list > > NStgid descendant namespace thread group ID hierarchy > > diff --git a/fs/proc/array.c b/fs/proc/array.c > > index b6c00ce..88c7de1 100644 > > --- a/fs/proc/array.c > > +++ b/fs/proc/array.c > > @@ -83,6 +83,7 @@ > > #include > > #include > > #include > > +#include > > > > #include > > #include > > @@ -139,12 +140,25 @@ static inline const char *get_task_state(struct task_struct *tsk) > > return task_state_array[fls(state)]; > > } > > > > +static inline int get_task_umask(struct task_struct *tsk) > > +{ > > + struct fs_struct *fs; > > + int umask = -ENOENT; > > + > > + task_lock(tsk); > > + fs = tsk->fs; > > + if (fs) > > + umask = fs->umask; > > + task_unlock(tsk); > > + return umask; > > +} > > + > > static inline void task_state(struct seq_file *m, struct pid_namespace *ns, > > struct pid *pid, struct task_struct *p) > > { > > struct user_namespace *user_ns = seq_user_ns(m); > > struct group_info *group_info; > > - int g; > > + int g, umask; > > struct task_struct *tracer; > > const struct cred *cred; > > pid_t ppid, tpid = 0, tgid, ngid; > > @@ -162,6 +176,10 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns, > > ngid = task_numa_group_id(p); > > cred = get_task_cred(p); > > > > + umask = get_task_umask(p); > > + if (umask >= 0) > > + seq_printf(m, "Umask:\t%#04o\n", umask); > > + > > task_lock(p); > > if (p->files) > > max_fds = files_fdtable(p->files)->max_fds; > > -- > > 2.7.4 > > -- > Michal Hocko > SUSE Labs -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW