From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752306AbdCAL6k (ORCPT ); Wed, 1 Mar 2017 06:58:40 -0500 Received: from terminus.zytor.com ([65.50.211.136]:51374 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751378AbdCAL6g (ORCPT ); Wed, 1 Mar 2017 06:58:36 -0500 Date: Wed, 1 Mar 2017 03:58:06 -0800 From: tip-bot for Stephen Smalley Message-ID: Cc: tglx@linutronix.de, sds@tycho.nsa.gov, mingo@kernel.org, hpa@zytor.com, linux-kernel@vger.kernel.org Reply-To: hpa@zytor.com, linux-kernel@vger.kernel.org, sds@tycho.nsa.gov, tglx@linutronix.de, mingo@kernel.org In-Reply-To: <1487344439-22293-1-git-send-email-sds@tycho.nsa.gov> References: <1487344439-22293-1-git-send-email-sds@tycho.nsa.gov> To: linux-tip-commits@vger.kernel.org Subject: [tip:timers/urgent] timerfd: Only check CAP_WAKE_ALARM when it is needed Git-Commit-ID: 25b68a8f0ab13a98de02650208ec927796659898 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 25b68a8f0ab13a98de02650208ec927796659898 Gitweb: http://git.kernel.org/tip/25b68a8f0ab13a98de02650208ec927796659898 Author: Stephen Smalley AuthorDate: Fri, 17 Feb 2017 10:13:59 -0500 Committer: Thomas Gleixner CommitDate: Wed, 1 Mar 2017 12:53:44 +0100 timerfd: Only check CAP_WAKE_ALARM when it is needed timerfd_create() and do_timerfd_settime() evaluate capable(CAP_WAKE_ALARM) unconditionally although CAP_WAKE_ALARM is only required for CLOCK_REALTIME_ALARM and CLOCK_BOOTTIME_ALARM. This can cause extraneous audit messages when using a LSM such as SELinux, incorrectly causes PF_SUPERPRIV to be set even when no privilege was exercised, and is inefficient. Flip the order of the tests in both functions so that we only call capable() if the capability is truly required for the operation. Signed-off-by: Stephen Smalley Cc: linux-security-module@vger.kernel.org Cc: selinux@tycho.nsa.gov Link: http://lkml.kernel.org/r/1487344439-22293-1-git-send-email-sds@tycho.nsa.gov Signed-off-by: Thomas Gleixner --- fs/timerfd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/timerfd.c b/fs/timerfd.c index 384fa75..c543cdb 100644 --- a/fs/timerfd.c +++ b/fs/timerfd.c @@ -400,9 +400,9 @@ SYSCALL_DEFINE2(timerfd_create, int, clockid, int, flags) clockid != CLOCK_BOOTTIME_ALARM)) return -EINVAL; - if (!capable(CAP_WAKE_ALARM) && - (clockid == CLOCK_REALTIME_ALARM || - clockid == CLOCK_BOOTTIME_ALARM)) + if ((clockid == CLOCK_REALTIME_ALARM || + clockid == CLOCK_BOOTTIME_ALARM) && + !capable(CAP_WAKE_ALARM)) return -EPERM; ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); @@ -449,7 +449,7 @@ static int do_timerfd_settime(int ufd, int flags, return ret; ctx = f.file->private_data; - if (!capable(CAP_WAKE_ALARM) && isalarm(ctx)) { + if (isalarm(ctx) && !capable(CAP_WAKE_ALARM)) { fdput(f); return -EPERM; }