From patchwork Fri Feb 17 15:13:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Smalley X-Patchwork-Id: 9580129 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 4149C600F6 for ; Fri, 17 Feb 2017 15:21:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3220828113 for ; Fri, 17 Feb 2017 15:21:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 26E1B28701; Fri, 17 Feb 2017 15:21:21 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B155428113 for ; Fri, 17 Feb 2017 15:21:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934572AbdBQPUi (ORCPT ); Fri, 17 Feb 2017 10:20:38 -0500 Received: from smtp.nsa.gov ([8.44.101.8]:19937 "EHLO emsm-gh1-uea10.nsa.gov" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934159AbdBQPUg (ORCPT ); Fri, 17 Feb 2017 10:20:36 -0500 X-Greylist: delayed 590 seconds by postgrey-1.27 at vger.kernel.org; Fri, 17 Feb 2017 10:20:36 EST X-IronPort-AV: E=Sophos;i="5.35,172,1484006400"; d="scan'208";a="3997600" IronPort-PHdr: =?us-ascii?q?9a23=3ASN9zxxa3VXW/XXPvhP8xdMH/LSx+4OfEezUN459i?= =?us-ascii?q?sYplN5qZr8SzbnLW6fgltlLVR4KTs6sC0LuL9fi+EjNbqb+681k6OKRWUBEEjc?= =?us-ascii?q?hE1ycBO+WiTXPBEfjxciYhF95DXlI2t1uyMExSBdqsLwaK+i764jEdAAjwOhRo?= =?us-ascii?q?LerpBIHSk9631+ev8JHPfglEnjSwbLdyIRmssQnct8YajIlsJ60s1hbHv3xEdv?= =?us-ascii?q?hMy2h1P1yThRH85smx/J5n7Stdvu8q+tBDX6vnYak2VKRUAzs6PW874s3rrgTD?= =?us-ascii?q?QhCU5nQASGUWkwFHDBbD4RrnQ5r+qCr6tu562CmHIc37SK0/VDq+46t3ThLjlS?= =?us-ascii?q?kINyQ98GrKlMJ+iqxVqw+lqxBm3YLYfISZOfxjda3fYNwaX3JMUMZPWSJcDI2y?= =?us-ascii?q?bIwBAvEdMepEtYTxu0EDoQeiCQSqGejhyiVIhnjz3aAizuohDR/J3BQgH90Qtn?= =?us-ascii?q?Tfscj7NKIIXuCxyKnH0zXCZO5R1Dfm9YfIaQssoe2MXL1sccrRzlMjFwXejlqK?= =?us-ascii?q?s4DlMDSV1voUvmWd8uFuVvqvhnY6pwx+rTWj3MchhpTTio4LxV3I6z91zJszKN?= =?us-ascii?q?alUkB0e8SkH4FVtyyCMot2Rd4tTH9wtSYhz70GpYa7fC8XyJQ73xLfa+KIc4yP?= =?us-ascii?q?4h/7SOaeOy14hHN4eLKknRqy7UihxfH8VsmzylpKqDZKksLQuXwX0hzT68yHRu?= =?us-ascii?q?N8/kenxzmPyxje5vxLLE07j6bWK4MtzqQumpccr0jPBDL6lF3zjKCMd0Uk/uao?= =?us-ascii?q?6/7gYrXjvpKcLJJ7ihrlP6Qyms2wHeQ4Mg8UU2id4uSzzqfv/UL+QLVUlvE2iL?= =?us-ascii?q?XWsIjGJcQHoa60GwtV0ocl6xaiADaqyc8YkmcbI1JYYhKHjpTpOlHXLPD9Cvew?= =?us-ascii?q?nkmskDN1yP3dIL3hDYvCLmLZnLfiY7l98UhcxxQ3zdxF4JJUEL4BKurpWkDtrN?= =?us-ascii?q?zYEgM5MwuszubjCdV90J4eWG2WDq+aLqzSq1mI6fwrI+SXeo8VtyjyK+I/6/7t?= =?us-ascii?q?k3A5g1kdcret3ZcNb3C4BPtmKV2DYXXwmtcBDXsKvg0mQez2h12CVTFSam22X6?= =?us-ascii?q?I94DE7FZ6mDZ3ERoCrgbyA0z23EYBIaTMONlfZDXjsZ62AWvERdDiVJM5x1DAJ?= =?us-ascii?q?Bpa7TIp07g2jrA/3zfJcK+PQ/iAJ/cb42MNd+/zYlRZ08yd9ScuazTfeHClPgm?= =?us-ascii?q?oUSmpuj+hEqktnxwLGi/B1?= X-IPAS-Result: =?us-ascii?q?A2GMBADuEadY/wHyM5BeGwEBAQMBAQEJAQEBFgEBAQMBAQE?= =?us-ascii?q?JAQEBgyaBap5IAQEBAQEBBpRHhBsahgiCIVcBAQEBAQEBAQIBAl8ogjMigklSK?= =?us-ascii?q?IEpiV8NslQ6JgKLLzKGB4pUggAMgw0FkEWLPIoSiAcCilSGMAJIklZYgQAZBwI?= =?us-ascii?q?SCBsPhx8iNYprAQEB?= Received: from unknown (HELO tarius.tycho.ncsc.mil) ([144.51.242.1]) by emsm-gh1-uea10.nsa.gov with ESMTP; 17 Feb 2017 15:10:44 +0000 Received: from moss-pluto.infosec.tycho.ncsc.mil (moss-pluto [192.168.25.131]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id v1HFAggB013656; Fri, 17 Feb 2017 10:10:43 -0500 From: Stephen Smalley To: tglx@linutronix.de Cc: linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, selinux@tycho.nsa.gov, Stephen Smalley Subject: [PATCH] timerfd: only check CAP_WAKE_ALARM when it is needed Date: Fri, 17 Feb 2017 10:13:59 -0500 Message-Id: <1487344439-22293-1-git-send-email-sds@tycho.nsa.gov> X-Mailer: git-send-email 2.7.4 Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP timerfd_create() and do_timerfd_settime() presently always call capable(CAP_WAKE_ALARM) 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 --- 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; }