From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753120AbcFIVtd (ORCPT ); Thu, 9 Jun 2016 17:49:33 -0400 Received: from terminus.zytor.com ([198.137.202.10]:38234 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932173AbcFIVtH (ORCPT ); Thu, 9 Jun 2016 17:49:07 -0400 Date: Thu, 9 Jun 2016 14:48:54 -0700 From: tip-bot for Eric Caruso Message-ID: Cc: tglx@linutronix.de, toddpoynor@google.com, ejcaruso@google.com, mingo@kernel.org, hpa@zytor.com, linux-kernel@vger.kernel.org Reply-To: hpa@zytor.com, linux-kernel@vger.kernel.org, mingo@kernel.org, toddpoynor@google.com, ejcaruso@google.com, tglx@linutronix.de In-Reply-To: <1465427339-96209-1-git-send-email-ejcaruso@chromium.org> References: <1465427339-96209-1-git-send-email-ejcaruso@chromium.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:timers/core] timerfd: Reject ALARM timerfds without CAP_WAKE_ALARM Git-Commit-ID: 2895a5e5b3ae78d9923a91fce405d4a2f32c4309 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: 2895a5e5b3ae78d9923a91fce405d4a2f32c4309 Gitweb: http://git.kernel.org/tip/2895a5e5b3ae78d9923a91fce405d4a2f32c4309 Author: Eric Caruso AuthorDate: Wed, 8 Jun 2016 16:08:59 -0700 Committer: Thomas Gleixner CommitDate: Thu, 9 Jun 2016 23:42:38 +0200 timerfd: Reject ALARM timerfds without CAP_WAKE_ALARM timerfd gives processes a way to set wake alarms, but unlike timers made using timer_create, timerfds don't check whether the process has CAP_WAKE_ALARM before setting alarm-time timers. CAP_WAKE_ALARM is supposed to gate this behavior and so it makes sense that we should deny permission to create such timerfds if the process doesn't have this capability. Signed-off-by: Eric Caruso Cc: Todd Poynor Link: http://lkml.kernel.org/r/1465427339-96209-1-git-send-email-ejcaruso@chromium.org Signed-off-by: Thomas Gleixner --- fs/timerfd.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fs/timerfd.c b/fs/timerfd.c index 053818d..9ae4abb 100644 --- a/fs/timerfd.c +++ b/fs/timerfd.c @@ -390,6 +390,11 @@ 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)) + return -EPERM; + ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); if (!ctx) return -ENOMEM; @@ -433,6 +438,11 @@ static int do_timerfd_settime(int ufd, int flags, return ret; ctx = f.file->private_data; + if (!capable(CAP_WAKE_ALARM) && isalarm(ctx)) { + fdput(f); + return -EPERM; + } + timerfd_setup_cancel(ctx, flags); /*