summaryrefslogtreecommitdiff
path: root/fs/timerfd.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-02-24 02:50:11 (GMT)
committerLinus Torvalds <torvalds@linux-foundation.org>2013-02-24 02:50:11 (GMT)
commit9e2d59ad580d590134285f361a0e80f0e98c0207 (patch)
treef3232be75781484193413f32ec82c21f6d8eb76e /fs/timerfd.c
parent5ce1a70e2f00f0bce0cab57f798ca354b9496169 (diff)
parent235b80226b986dabcbba844968f7807866bd0bfe (diff)
downloadlinux-fsl-qoriq-9e2d59ad580d590134285f361a0e80f0e98c0207.tar.xz
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/signal
Pull signal handling cleanups from Al Viro: "This is the first pile; another one will come a bit later and will contain SYSCALL_DEFINE-related patches. - a bunch of signal-related syscalls (both native and compat) unified. - a bunch of compat syscalls switched to COMPAT_SYSCALL_DEFINE (fixing several potential problems with missing argument validation, while we are at it) - a lot of now-pointless wrappers killed - a couple of architectures (cris and hexagon) forgot to save altstack settings into sigframe, even though they used the (uninitialized) values in sigreturn; fixed. - microblaze fixes for delivery of multiple signals arriving at once - saner set of helpers for signal delivery introduced, several architectures switched to using those." * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/signal: (143 commits) x86: convert to ksignal sparc: convert to ksignal arm: switch to struct ksignal * passing alpha: pass k_sigaction and siginfo_t using ksignal pointer burying unused conditionals make do_sigaltstack() static arm64: switch to generic old sigaction() (compat-only) arm64: switch to generic compat rt_sigaction() arm64: switch compat to generic old sigsuspend arm64: switch to generic compat rt_sigqueueinfo() arm64: switch to generic compat rt_sigpending() arm64: switch to generic compat rt_sigprocmask() arm64: switch to generic sigaltstack sparc: switch to generic old sigsuspend sparc: COMPAT_SYSCALL_DEFINE does all sign-extension as well as SYSCALL_DEFINE sparc: kill sign-extending wrappers for native syscalls kill sparc32_open() sparc: switch to use of generic old sigaction sparc: switch sys_compat_rt_sigaction() to COMPAT_SYSCALL_DEFINE mips: switch to generic sys_fork() and sys_clone() ...
Diffstat (limited to 'fs/timerfd.c')
-rw-r--r--fs/timerfd.c85
1 files changed, 66 insertions, 19 deletions
diff --git a/fs/timerfd.c b/fs/timerfd.c
index d03822b..0e606b1 100644
--- a/fs/timerfd.c
+++ b/fs/timerfd.c
@@ -22,6 +22,7 @@
#include <linux/anon_inodes.h>
#include <linux/timerfd.h>
#include <linux/syscalls.h>
+#include <linux/compat.h>
#include <linux/rcupdate.h>
struct timerfd_ctx {
@@ -278,21 +279,17 @@ SYSCALL_DEFINE2(timerfd_create, int, clockid, int, flags)
return ufd;
}
-SYSCALL_DEFINE4(timerfd_settime, int, ufd, int, flags,
- const struct itimerspec __user *, utmr,
- struct itimerspec __user *, otmr)
+static int do_timerfd_settime(int ufd, int flags,
+ const struct itimerspec *new,
+ struct itimerspec *old)
{
struct fd f;
struct timerfd_ctx *ctx;
- struct itimerspec ktmr, kotmr;
int ret;
- if (copy_from_user(&ktmr, utmr, sizeof(ktmr)))
- return -EFAULT;
-
if ((flags & ~TFD_SETTIME_FLAGS) ||
- !timespec_valid(&ktmr.it_value) ||
- !timespec_valid(&ktmr.it_interval))
+ !timespec_valid(&new->it_value) ||
+ !timespec_valid(&new->it_interval))
return -EINVAL;
ret = timerfd_fget(ufd, &f);
@@ -323,27 +320,23 @@ SYSCALL_DEFINE4(timerfd_settime, int, ufd, int, flags,
if (ctx->expired && ctx->tintv.tv64)
hrtimer_forward_now(&ctx->tmr, ctx->tintv);
- kotmr.it_value = ktime_to_timespec(timerfd_get_remaining(ctx));
- kotmr.it_interval = ktime_to_timespec(ctx->tintv);
+ old->it_value = ktime_to_timespec(timerfd_get_remaining(ctx));
+ old->it_interval = ktime_to_timespec(ctx->tintv);
/*
* Re-program the timer to the new value ...
*/
- ret = timerfd_setup(ctx, flags, &ktmr);
+ ret = timerfd_setup(ctx, flags, new);
spin_unlock_irq(&ctx->wqh.lock);
fdput(f);
- if (otmr && copy_to_user(otmr, &kotmr, sizeof(kotmr)))
- return -EFAULT;
-
return ret;
}
-SYSCALL_DEFINE2(timerfd_gettime, int, ufd, struct itimerspec __user *, otmr)
+static int do_timerfd_gettime(int ufd, struct itimerspec *t)
{
struct fd f;
struct timerfd_ctx *ctx;
- struct itimerspec kotmr;
int ret = timerfd_fget(ufd, &f);
if (ret)
return ret;
@@ -356,11 +349,65 @@ SYSCALL_DEFINE2(timerfd_gettime, int, ufd, struct itimerspec __user *, otmr)
hrtimer_forward_now(&ctx->tmr, ctx->tintv) - 1;
hrtimer_restart(&ctx->tmr);
}
- kotmr.it_value = ktime_to_timespec(timerfd_get_remaining(ctx));
- kotmr.it_interval = ktime_to_timespec(ctx->tintv);
+ t->it_value = ktime_to_timespec(timerfd_get_remaining(ctx));
+ t->it_interval = ktime_to_timespec(ctx->tintv);
spin_unlock_irq(&ctx->wqh.lock);
fdput(f);
+ return 0;
+}
+
+SYSCALL_DEFINE4(timerfd_settime, int, ufd, int, flags,
+ const struct itimerspec __user *, utmr,
+ struct itimerspec __user *, otmr)
+{
+ struct itimerspec new, old;
+ int ret;
+
+ if (copy_from_user(&new, utmr, sizeof(new)))
+ return -EFAULT;
+ ret = do_timerfd_settime(ufd, flags, &new, &old);
+ if (ret)
+ return ret;
+ if (otmr && copy_to_user(otmr, &old, sizeof(old)))
+ return -EFAULT;
+
+ return ret;
+}
+SYSCALL_DEFINE2(timerfd_gettime, int, ufd, struct itimerspec __user *, otmr)
+{
+ struct itimerspec kotmr;
+ int ret = do_timerfd_gettime(ufd, &kotmr);
+ if (ret)
+ return ret;
return copy_to_user(otmr, &kotmr, sizeof(kotmr)) ? -EFAULT: 0;
}
+#ifdef COMPAT
+COMPAT_SYSCALL_DEFINE4(timerfd_settime, int, ufd, int, flags,
+ const struct itimerspec __user *, utmr,
+ struct itimerspec __user *, otmr)
+{
+ struct itimerspec new, old;
+ int ret;
+
+ if (get_compat_itimerspec(&new, utmr))
+ return -EFAULT;
+ ret = do_timerfd_settime(ufd, flags, &new, &old);
+ if (ret)
+ return ret;
+ if (otmr && put_compat_itimerspec(otmr, &old))
+ return -EFAULT;
+ return ret;
+}
+
+COMPAT_SYSCALL_DEFINE2(timerfd_gettime, int, ufd,
+ struct itimerspec __user *, otmr)
+{
+ struct itimerspec kotmr;
+ int ret = do_timerfd_gettime(ufd, &kotmr);
+ if (ret)
+ return ret;
+ return put_compat_itimerspec(otmr, &t) ? -EFAULT: 0;
+}
+#endif