[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20171128111214.42esi4igzgnldsx5@gmail.com>
Date: Tue, 28 Nov 2017 12:12:14 +0100
From: Ingo Molnar <mingo@...nel.org>
To: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Peter Zijlstra <peterz@...radead.org>,
Thomas Gleixner <tglx@...utronix.de>,
LKML <linux-kernel@...r.kernel.org>,
Dave Hansen <dave.hansen@...ux.intel.com>,
Andy Lutomirski <luto@...nel.org>,
Borislav Petkov <bp@...en8.de>,
Brian Gerst <brgerst@...il.com>,
Denys Vlasenko <dvlasenk@...hat.com>,
"H. Peter Anvin" <hpa@...or.com>,
Josh Poimboeuf <jpoimboe@...hat.com>,
Rik van Riel <riel@...hat.com>,
Daniel Gruss <daniel.gruss@...k.tugraz.at>,
Hugh Dickins <hughd@...gle.com>,
Kees Cook <keescook@...gle.com>, linux-mm <linux-mm@...ck.org>,
michael.schwarz@...k.tugraz.at, moritz.lipp@...k.tugraz.at,
richard.fellner@...dent.tugraz.at
Subject: Re: [PATCH] vfs: Add PERM_* symbolic helpers for common file
mode/permissions
* Linus Torvalds <torvalds@...ux-foundation.org> wrote:
> On Mon, Nov 27, 2017 at 2:06 AM, Ingo Molnar <mingo@...nel.org> wrote:
> >
> >
> > +/*
> > + * Human readable symbolic definitions for common
> > + * file permissions:
> > + */
> > +#define PERM_r________ 0400
> > +#define PERM_r__r_____ 0440
> > +#define PERM_r__r__r__ 0444
>
> I'm not a fan. Particularly as you have a very random set of
> permissions (rx and wx? Not very common),
So I originally created those defines based on a grep of patterns used in the
kernel, and added the 'wx' variants for completeness.
We would only need a small subset. Here's a git grep based histogram of octal file
permission masks used in the kernel source:
# mode
21 0200
8 0220
14 0222
33 0400
11 0440
219 0444
91 0555
39 0600
906 0644
12 0660
12 0664
18 0666
14 0755
31 0777
So there's literally only 14 variants used, and 0644 and 0444 make up 95% of the
cases. We get the patch below if we extend these existing patterns using their
natural (looking) generators to a complete group - 19 patterns that should cover
all the sensible combinations.
> but also because it's just not that legible.
Fair enough.
Thanks,
Ingo
---
include/linux/stat.h | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
Index: tip/include/linux/stat.h
===================================================================
--- tip.orig/include/linux/stat.h
+++ tip/include/linux/stat.h
@@ -6,6 +6,34 @@
#include <asm/stat.h>
#include <uapi/linux/stat.h>
+/*
+ * Human readable symbolic definitions for common
+ * file permissions:
+ */
+#define PERM_r________ 0400
+#define PERM_r__r_____ 0440
+#define PERM_r__r__r__ 0444
+
+#define PERM_rw_______ 0600
+#define PERM_rw_r_____ 0640
+#define PERM_rw_r__r__ 0644
+#define PERM_rw_rw_r__ 0664
+#define PERM_rw_rw_rw_ 0666
+
+#define PERM__w_______ 0200
+#define PERM__w__w____ 0220
+#define PERM__w__w__w_ 0222
+
+#define PERM_r_x______ 0500
+#define PERM_r_xr_x___ 0550
+#define PERM_r_xr_xr_x 0555
+
+#define PERM_rwx______ 0700
+#define PERM_rwxr_x___ 0750
+#define PERM_rwxr_xr_x 0755
+#define PERM_rwxrwxr_x 0775
+#define PERM_rwxrwxrwx 0777
+
#define S_IRWXUGO (S_IRWXU|S_IRWXG|S_IRWXO)
#define S_IALLUGO (S_ISUID|S_ISGID|S_ISVTX|S_IRWXUGO)
#define S_IRUGO (S_IRUSR|S_IRGRP|S_IROTH)
Powered by blists - more mailing lists