Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755306AbcDNMl5 (ORCPT ); Thu, 14 Apr 2016 08:41:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39653 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754594AbcDNMl4 (ORCPT ); Thu, 14 Apr 2016 08:41:56 -0400 Subject: Re: [PATCH v2] procfs: expose umask in /proc//status To: "Richard W.M. Jones" , linux-kernel@vger.kernel.org References: <1460632095-434-1-git-send-email-rjones@redhat.com> <1460632095-434-2-git-send-email-rjones@redhat.com> Cc: corbet@lwn.net, akpm@linux-foundation.org, vbabka@suse.cz, mhocko@suse.com, 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, 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 From: Jerome Marchand Message-ID: <570F9003.4050101@redhat.com> Date: Thu, 14 Apr 2016 14:41:39 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.1 MIME-Version: 1.0 In-Reply-To: <1460632095-434-2-git-send-email-rjones@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="Ra6Lhf8uwg5Lhw2V5hX8k6FbJfgOlihVk" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5097 Lines: 140 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --Ra6Lhf8uwg5Lhw2V5hX8k6FbJfgOlihVk Content-Type: multipart/mixed; boundary="mBNmiGSGWbbRWr8LqXXsKeiaCjqEwnSPV" From: Jerome Marchand To: "Richard W.M. Jones" , linux-kernel@vger.kernel.org Cc: corbet@lwn.net, akpm@linux-foundation.org, vbabka@suse.cz, mhocko@suse.com, 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, 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 Message-ID: <570F9003.4050101@redhat.com> Subject: Re: [PATCH v2] procfs: expose umask in /proc//status References: <1460632095-434-1-git-send-email-rjones@redhat.com> <1460632095-434-2-git-send-email-rjones@redhat.com> In-Reply-To: <1460632095-434-2-git-send-email-rjones@redhat.com> --mBNmiGSGWbbRWr8LqXXsKeiaCjqEwnSPV Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 04/14/2016 01:08 PM, 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. >=20 > 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. >=20 > This patch is adapted from one originally written by Pierre Carrier. >=20 > Signed-off-by: Richard W.M. Jones Acked-by: Jerome Marchand > --- > Documentation/filesystems/proc.txt | 1 + > fs/proc/array.c | 20 +++++++++++++++++++- > 2 files changed, 20 insertions(+), 1 deletion(-) >=20 > diff --git a/Documentation/filesystems/proc.txt b/Documentation/filesys= tems/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 sys= tem UIDs > Gid Real, effective, saved set, and file sys= tem GIDs > + Umask file mode creation mask > FDSize number of file descriptor slots currently= allocated > Groups supplementary group list > NStgid descendant namespace thread group ID hier= archy > 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 > =20 > #include > #include > @@ -139,12 +140,25 @@ static inline const char *get_task_state(struct t= ask_struct *tsk) > return task_state_array[fls(state)]; > } > =20 > +static inline int get_task_umask(struct task_struct *tsk) > +{ > + struct fs_struct *fs; > + int umask =3D -ENOENT; > + > + task_lock(tsk); > + fs =3D tsk->fs; > + if (fs) > + umask =3D 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 =3D 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 =3D 0, tgid, ngid; > @@ -162,6 +176,10 @@ static inline void task_state(struct seq_file *m, = struct pid_namespace *ns, > ngid =3D task_numa_group_id(p); > cred =3D get_task_cred(p); > =20 > + umask =3D get_task_umask(p); > + if (umask >=3D 0) > + seq_printf(m, "Umask:\t%#04o\n", umask); > + > task_lock(p); > if (p->files) > max_fds =3D files_fdtable(p->files)->max_fds; >=20 --mBNmiGSGWbbRWr8LqXXsKeiaCjqEwnSPV-- --Ra6Lhf8uwg5Lhw2V5hX8k6FbJfgOlihVk Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJXD5AEAAoJEHTzHJCtsuoCp9cIAK49p/93FeVz6c/svP33fwtB bwtRX+tAbB54wDIbdHkUsjW9gh3UriXvj67h8RcPzCK8qTXYctY7GxKA6JdAI9PY FPXzxtn5avc+3Z3HsZWVQUgjjCNzmrTHvRYfD4lqX73vsP0DMQzeNzyfNSH9XtCZ EmKU/UO9TFgMVdVz0JrreaARN1YY1RvmniCJWNmSChrGCL+3em8Pd8ILIWQDxIqz X9sdTd1oSlIWC8U4cK5PG8mA6ChskXU5riFxMEbVYnruoehVewUgEJsR2xT8oZWp C1yDxUanHlmxA+Olg0FzQzSLOE1mk3PC+O1B+Or/KE6ovtVtslmUcAQ7COa1R9I= =awx8 -----END PGP SIGNATURE----- --Ra6Lhf8uwg5Lhw2V5hX8k6FbJfgOlihVk--