From patchwork Wed Aug 3 08:11:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ingo Molnar X-Patchwork-Id: 9260887 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A1D5060754 for ; Wed, 3 Aug 2016 08:13:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9360728560 for ; Wed, 3 Aug 2016 08:13:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 87CD428563; Wed, 3 Aug 2016 08:13:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4769028560 for ; Wed, 3 Aug 2016 08:13:46 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bUrHg-00046h-VF; Wed, 03 Aug 2016 08:12:12 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bUrHZ-0003uM-Lo for linux-arm-kernel@lists.infradead.org; Wed, 03 Aug 2016 08:12:08 +0000 Received: by mail-wm0-x244.google.com with SMTP id x83so34971193wma.3 for ; Wed, 03 Aug 2016 01:11:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=yzlGkNug67Jbtjgjg5kP9YA3LsC5u/xrl1kp+KHapOU=; b=HdpyXyHMweDwmgmazsGnYg+fQjsiFPizGkfwH/AqtLblKr7f0GcwS5j2MFFwtd7psu 4pO/DV94UnMDSOBFJMg4jkrgAl1NitfysG1aV2eNQOV1TGp+joSt3V6gn4WsDUz12YJ8 jwOOwBO7hosrZS0ysp6ODcLsOtgBj1heYwg/SIor4M38rL0mAKLv6VZ/fP3iw6lPU/k8 AX13cPzNXEMZdvaeqGbnbZhVGnv+t4buQUu59iSxx835dBVveKPzmvmzC9r2wTs0QTs6 Qq8rnb9Q0+gZIR3Z+cNeqqPcS70oBF3aJ/z3hdC88efKQOMyCHiq6sad7p8pNSlPhcXE /EFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=yzlGkNug67Jbtjgjg5kP9YA3LsC5u/xrl1kp+KHapOU=; b=ew1AEUAsaVYnHHo7UQAsHByuhdgDSmtD6tz+/7BX3nVoqsGmvpWajlvLUCLVEvgrkM uu84Pze5aqlJdJqnwW3gi7H6OS4enNcuyoqp5wJCBvF8tB0JE8Yqqn/AcDnEw6qSMm4Z lkp+P8yyauJLqmirwlv2xE6aKOEfN2gqkpUO3hKkS7qKaGe/YHsS3t1m2SlL+/AszVhI D9D642/GP70plSL/7nSsi0/hSSVMrYpAiPC8CVtOd7Z5+GJnAwm1ga9AAqQQV4bzWy76 NDQWJNYIZZTC9yuDeBn0lGRrZoRt7pg0r6yxoHE0CZhfoSRFAnXqwf2wPYvsD++GtWu8 hdqw== X-Gm-Message-State: AEkoousf3cDPtClS3Z1wMZLQRQBSnBDV0arnlgVcGsy1ezqn+D0Zcidocssa5IwwclqAsQ== X-Received: by 10.28.187.67 with SMTP id l64mr22201068wmf.11.1470211903841; Wed, 03 Aug 2016 01:11:43 -0700 (PDT) Received: from gmail.com (2E8B0CD5.catv.pool.telekom.hu. [46.139.12.213]) by smtp.gmail.com with ESMTPSA id i7sm6398881wjg.42.2016.08.03.01.11.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Aug 2016 01:11:42 -0700 (PDT) Date: Wed, 3 Aug 2016 10:11:40 +0200 From: Ingo Molnar To: Linus Torvalds Subject: [PATCH] Add file permission mode helpers Message-ID: <20160803081140.GA7833@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160803_011205_871042_8DDD060B X-CRM114-Status: GOOD ( 20.21 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Greg Kroah-Hartman , Heiko Carstens , Russell King - ARM Linux , Linux Kernel Mailing List , Baole Ni , Pavel Machek , chuansheng.liu@intel.com, "linux-arm-kernel@lists.infradead.org" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP * Linus Torvalds wrote: > [ So I answered similarly to another patch, but I'll just re-iterate > and change the subject line so that it stands out a bit from the > millions of actual patches ] > > On Tue, Aug 2, 2016 at 1:42 PM, Pavel Machek wrote: > > > > Everyone knows what 0644 is, but noone can read S_IRUSR | S_IWUSR | > > S_IRCRP | S_IROTH (*). Please don't do this. > > Absolutely. It's *much* easier to parse and understand the octal > numbers, while the symbolic macro names are just random line noise and > hard as hell to understand. You really have to think about it. > > So we should rather go the other way: convert existing bad symbolic > permission bit macro use to just use the octal numbers. In addition to that I'd love to have something even easier to read, a few common variants of the permissions field of 'ls -l' pre-defined. I did some quick grepping, and collected the main variants that are in use: PERM_r________ 0400 PERM_r__r_____ 0440 PERM_r__r__r__ 0444 PERM_rw_______ 0600 PERM_rw_r_____ 0640 PERM_rw_r__r__ 0644 PERM_rw_rw_r__ 0664 PERM_rw_rw_rw_ 0666 PERM__w_______ 0200 PERM__w__w____ 0220 PERM__w__w__w_ 0222 PERM_r_x______ 0500 PERM_r_xr_x___ 0550 PERM_r_xr_xr_x 0555 PERM_rwx______ 0700 PERM_rwxr_x___ 0750 PERM_rwxr_xr_x 0755 PERM_rwxrwxr_x 0775 PERM_rwxrwxrwx 0777 PERM__wx______ 0300 PERM__wx_wx___ 0330 PERM__wx_wx_wx 0333 Allowing these would be nice too, because there were cases in the past where people messed up the octal representation or our internal symbolic helpers, but this representation is fundamentally self-describing and pretty 'fool proof'. An added advantage would be that during review it would stick out like a sore thumb if anyone used a 'weird' permission variant. For example, if you saw these lines in a driver patch: + __ATTR(l1, 0444, driver_show_l4, NULL); + __ATTR(l3, 0446, driver_show_l4, NULL); + __ATTR(l2, 04444, driver_show_l4, NULL); + __ATTR(l4, 0444, driver_show_l4, NULL); ... would you notice it at a glance that it contains two security holes? While the weird permissions in this: + __ATTR(l1, PERM_r__r__r__, driver_show_l4, NULL); + __ATTR(l3, PERM_r__r__rw_, driver_show_l4, NULL); + __ATTR(l2, PERM_sr__r__r__, driver_show_l4, NULL); + __ATTR(l4, PERM_r__r__r__, driver_show_l4, NULL); Wouln't even build, because the dangerous patterns of PERM_r__r__rw_ or PERM_sr__r__r__ are not defined to begin with. The patch below adds them to stat.h. Thanks, Ingo include/linux/stat.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/include/linux/stat.h b/include/linux/stat.h index 075cb0c7eb2a..863d5563427f 100644 --- a/include/linux/stat.h +++ b/include/linux/stat.h @@ -5,6 +5,38 @@ #include #include +/* + * 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 PERM__wx______ 0300 +#define PERM__wx_wx___ 0330 +#define PERM__wx_wx_wx 0333 + #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)