Skip to content

Commit 1acbe77

Browse files
Al ViroKAGA-KOKO
authored andcommitted
posix-timers: Take compat timer_settime(2) to native one
... and get rid of set_fs() in there Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: John Stultz <john.stultz@linaro.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/20170607084241.28657-10-viro@ZenIV.linux.org.uk
1 parent 3a4d44b commit 1acbe77

3 files changed

Lines changed: 64 additions & 47 deletions

File tree

‎kernel/compat.c‎

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -635,29 +635,6 @@ COMPAT_SYSCALL_DEFINE3(timer_create, clockid_t, which_clock,
635635
return sys_timer_create(which_clock, event, created_timer_id);
636636
}
637637

638-
COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
639-
struct compat_itimerspec __user *, new,
640-
struct compat_itimerspec __user *, old)
641-
{
642-
long err;
643-
mm_segment_t oldfs;
644-
struct itimerspec newts, oldts;
645-
646-
if (!new)
647-
return -EINVAL;
648-
if (get_compat_itimerspec(&newts, new))
649-
return -EFAULT;
650-
oldfs = get_fs();
651-
set_fs(KERNEL_DS);
652-
err = sys_timer_settime(timer_id, flags,
653-
(struct itimerspec __user *) &newts,
654-
(struct itimerspec __user *) &oldts);
655-
set_fs(oldfs);
656-
if (!err && old && put_compat_itimerspec(old, &oldts))
657-
return -EFAULT;
658-
return err;
659-
}
660-
661638
COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
662639
struct compat_itimerspec __user *, setting)
663640
{

‎kernel/time/posix-stubs.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ SYS_NI(setitimer);
4242
SYS_NI(alarm);
4343
#endif
4444
COMPAT_SYS_NI(clock_adjtime);
45+
COMPAT_SYS_NI(timer_settime);
4546

4647
/*
4748
* We preserve minimal support for CLOCK_REALTIME and CLOCK_MONOTONIC

‎kernel/time/posix-timers.c‎

Lines changed: 63 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -819,31 +819,21 @@ int common_timer_set(struct k_itimer *timr, int flags,
819819
return 0;
820820
}
821821

822-
/* Set a POSIX.1b interval timer */
823-
SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
824-
const struct itimerspec __user *, new_setting,
825-
struct itimerspec __user *, old_setting)
822+
static int do_timer_settime(timer_t timer_id, int flags,
823+
struct itimerspec64 *new_spec64,
824+
struct itimerspec64 *old_spec64)
826825
{
827-
struct itimerspec64 new_spec64, old_spec64;
828-
struct itimerspec64 *rtn = old_setting ? &old_spec64 : NULL;
829-
struct itimerspec new_spec, old_spec;
826+
const struct k_clock *kc;
830827
struct k_itimer *timr;
831828
unsigned long flag;
832-
const struct k_clock *kc;
833829
int error = 0;
834830

835-
if (!new_setting)
831+
if (!timespec64_valid(&new_spec64->it_interval) ||
832+
!timespec64_valid(&new_spec64->it_value))
836833
return -EINVAL;
837834

838-
if (copy_from_user(&new_spec, new_setting, sizeof (new_spec)))
839-
return -EFAULT;
840-
new_spec64 = itimerspec_to_itimerspec64(&new_spec);
841-
842-
if (!timespec64_valid(&new_spec64.it_interval) ||
843-
!timespec64_valid(&new_spec64.it_value))
844-
return -EINVAL;
845-
if (rtn)
846-
memset(rtn, 0, sizeof(*rtn));
835+
if (old_spec64)
836+
memset(old_spec64, 0, sizeof(*old_spec64));
847837
retry:
848838
timr = lock_timer(timer_id, &flag);
849839
if (!timr)
@@ -853,22 +843,71 @@ SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
853843
if (WARN_ON_ONCE(!kc || !kc->timer_set))
854844
error = -EINVAL;
855845
else
856-
error = kc->timer_set(timr, flags, &new_spec64, rtn);
846+
error = kc->timer_set(timr, flags, new_spec64, old_spec64);
857847

858848
unlock_timer(timr, flag);
859849
if (error == TIMER_RETRY) {
860-
rtn = NULL; // We already got the old time...
850+
old_spec64 = NULL; // We already got the old time...
861851
goto retry;
862852
}
863853

864-
old_spec = itimerspec64_to_itimerspec(&old_spec64);
865-
if (old_setting && !error &&
866-
copy_to_user(old_setting, &old_spec, sizeof (old_spec)))
867-
error = -EFAULT;
854+
return error;
855+
}
856+
857+
/* Set a POSIX.1b interval timer */
858+
SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
859+
const struct itimerspec __user *, new_setting,
860+
struct itimerspec __user *, old_setting)
861+
{
862+
struct itimerspec64 new_spec64, old_spec64;
863+
struct itimerspec64 *rtn = old_setting ? &old_spec64 : NULL;
864+
struct itimerspec new_spec;
865+
int error = 0;
866+
867+
if (!new_setting)
868+
return -EINVAL;
868869

870+
if (copy_from_user(&new_spec, new_setting, sizeof (new_spec)))
871+
return -EFAULT;
872+
new_spec64 = itimerspec_to_itimerspec64(&new_spec);
873+
874+
error = do_timer_settime(timer_id, flags, &new_spec64, rtn);
875+
if (!error && old_setting) {
876+
struct itimerspec old_spec;
877+
old_spec = itimerspec64_to_itimerspec(&old_spec64);
878+
if (copy_to_user(old_setting, &old_spec, sizeof (old_spec)))
879+
error = -EFAULT;
880+
}
869881
return error;
870882
}
871883

884+
#ifdef CONFIG_COMPAT
885+
COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
886+
struct compat_itimerspec __user *, new,
887+
struct compat_itimerspec __user *, old)
888+
{
889+
struct itimerspec64 new_spec64, old_spec64;
890+
struct itimerspec64 *rtn = old ? &old_spec64 : NULL;
891+
struct itimerspec new_spec;
892+
int error = 0;
893+
894+
if (!new)
895+
return -EINVAL;
896+
if (get_compat_itimerspec(&new_spec, new))
897+
return -EFAULT;
898+
899+
new_spec64 = itimerspec_to_itimerspec64(&new_spec);
900+
error = do_timer_settime(timer_id, flags, &new_spec64, rtn);
901+
if (!error && old) {
902+
struct itimerspec old_spec;
903+
old_spec = itimerspec64_to_itimerspec(&old_spec64);
904+
if (put_compat_itimerspec(old, &old_spec))
905+
error = -EFAULT;
906+
}
907+
return error;
908+
}
909+
#endif
910+
872911
int common_timer_del(struct k_itimer *timer)
873912
{
874913
const struct k_clock *kc = timer->kclock;

0 commit comments

Comments
 (0)