Skip to content

Commit 25b68a8

Browse files
stephensmalleyKAGA-KOKO
authored andcommitted
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 <sds@tycho.nsa.gov> 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 <tglx@linutronix.de>
1 parent 74e3f63 commit 25b68a8

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

fs/timerfd.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,9 @@ SYSCALL_DEFINE2(timerfd_create, int, clockid, int, flags)
400400
clockid != CLOCK_BOOTTIME_ALARM))
401401
return -EINVAL;
402402

403-
if (!capable(CAP_WAKE_ALARM) &&
404-
(clockid == CLOCK_REALTIME_ALARM ||
405-
clockid == CLOCK_BOOTTIME_ALARM))
403+
if ((clockid == CLOCK_REALTIME_ALARM ||
404+
clockid == CLOCK_BOOTTIME_ALARM) &&
405+
!capable(CAP_WAKE_ALARM))
406406
return -EPERM;
407407

408408
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
@@ -449,7 +449,7 @@ static int do_timerfd_settime(int ufd, int flags,
449449
return ret;
450450
ctx = f.file->private_data;
451451

452-
if (!capable(CAP_WAKE_ALARM) && isalarm(ctx)) {
452+
if (isalarm(ctx) && !capable(CAP_WAKE_ALARM)) {
453453
fdput(f);
454454
return -EPERM;
455455
}

0 commit comments

Comments
 (0)