Skip to content

Commit

Permalink
time: Move compat_gettimeofday()/settimeofday() to native
Browse files Browse the repository at this point in the history
Signed-off-by: Al Viro <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Cc: John Stultz <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
  • Loading branch information
Al Viro authored and KAGA-KOKO committed Jun 13, 2017
1 parent b180db2 commit 2b2d028
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 38 deletions.
38 changes: 0 additions & 38 deletions kernel/compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,44 +92,6 @@ int compat_put_timex(struct compat_timex __user *utp, const struct timex *txc)
return 0;
}

COMPAT_SYSCALL_DEFINE2(gettimeofday, struct compat_timeval __user *, tv,
struct timezone __user *, tz)
{
if (tv) {
struct timeval ktv;
do_gettimeofday(&ktv);
if (compat_put_timeval(&ktv, tv))
return -EFAULT;
}
if (tz) {
if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
return -EFAULT;
}

return 0;
}

COMPAT_SYSCALL_DEFINE2(settimeofday, struct compat_timeval __user *, tv,
struct timezone __user *, tz)
{
struct timespec64 new_ts;
struct timeval user_tv;
struct timezone new_tz;

if (tv) {
if (compat_get_timeval(&user_tv, tv))
return -EFAULT;
new_ts.tv_sec = user_tv.tv_sec;
new_ts.tv_nsec = user_tv.tv_usec * NSEC_PER_USEC;
}
if (tz) {
if (copy_from_user(&new_tz, tz, sizeof(*tz)))
return -EFAULT;
}

return do_sys_settimeofday64(tv ? &new_ts : NULL, tz ? &new_tz : NULL);
}

static int __compat_get_timeval(struct timeval *tv, const struct compat_timeval __user *ctv)
{
return (!access_ok(VERIFY_READ, ctv, sizeof(*ctv)) ||
Expand Down
41 changes: 41 additions & 0 deletions kernel/time/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,47 @@ SYSCALL_DEFINE2(settimeofday, struct timeval __user *, tv,
return do_sys_settimeofday64(tv ? &new_ts : NULL, tz ? &new_tz : NULL);
}

#ifdef CONFIG_COMPAT
COMPAT_SYSCALL_DEFINE2(gettimeofday, struct compat_timeval __user *, tv,
struct timezone __user *, tz)
{
if (tv) {
struct timeval ktv;

do_gettimeofday(&ktv);
if (compat_put_timeval(&ktv, tv))
return -EFAULT;
}
if (tz) {
if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
return -EFAULT;
}

return 0;
}

COMPAT_SYSCALL_DEFINE2(settimeofday, struct compat_timeval __user *, tv,
struct timezone __user *, tz)
{
struct timespec64 new_ts;
struct timeval user_tv;
struct timezone new_tz;

if (tv) {
if (compat_get_timeval(&user_tv, tv))
return -EFAULT;
new_ts.tv_sec = user_tv.tv_sec;
new_ts.tv_nsec = user_tv.tv_usec * NSEC_PER_USEC;
}
if (tz) {
if (copy_from_user(&new_tz, tz, sizeof(*tz)))
return -EFAULT;
}

return do_sys_settimeofday64(tv ? &new_ts : NULL, tz ? &new_tz : NULL);
}
#endif

SYSCALL_DEFINE1(adjtimex, struct timex __user *, txc_p)
{
struct timex txc; /* Local copy of parameter */
Expand Down

0 comments on commit 2b2d028

Please sign in to comment.