summaryrefslogtreecommitdiffstats
path: root/fs/timerfd.c
diff options
context:
space:
mode:
authorEric Caruso <ejcaruso@google.com>2016-06-08 19:08:59 -0400
committerThomas Gleixner <tglx@linutronix.de>2016-06-09 17:42:38 -0400
commit2895a5e5b3ae78d9923a91fce405d4a2f32c4309 (patch)
tree8168121926c218cc7896c0eacc4382ecdaca3d0c /fs/timerfd.c
parentaf8c34ce6ae32addda3788d54a7e340cad22516b (diff)
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 <ejcaruso@google.com> Cc: Todd Poynor <toddpoynor@google.com> Link: http://lkml.kernel.org/r/1465427339-96209-1-git-send-email-ejcaruso@chromium.org Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'fs/timerfd.c')
-rw-r--r--fs/timerfd.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/fs/timerfd.c b/fs/timerfd.c
index 053818dd6c18..9ae4abb4110b 100644
--- a/fs/timerfd.c
+++ b/fs/timerfd.c
@@ -390,6 +390,11 @@ SYSCALL_DEFINE2(timerfd_create, int, clockid, int, flags)
390 clockid != CLOCK_BOOTTIME_ALARM)) 390 clockid != CLOCK_BOOTTIME_ALARM))
391 return -EINVAL; 391 return -EINVAL;
392 392
393 if (!capable(CAP_WAKE_ALARM) &&
394 (clockid == CLOCK_REALTIME_ALARM ||
395 clockid == CLOCK_BOOTTIME_ALARM))
396 return -EPERM;
397
393 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); 398 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
394 if (!ctx) 399 if (!ctx)
395 return -ENOMEM; 400 return -ENOMEM;
@@ -433,6 +438,11 @@ static int do_timerfd_settime(int ufd, int flags,
433 return ret; 438 return ret;
434 ctx = f.file->private_data; 439 ctx = f.file->private_data;
435 440
441 if (!capable(CAP_WAKE_ALARM) && isalarm(ctx)) {
442 fdput(f);
443 return -EPERM;
444 }
445
436 timerfd_setup_cancel(ctx, flags); 446 timerfd_setup_cancel(ctx, flags);
437 447
438 /* 448 /*