Skip to content

Commit

Permalink
Merge tag 'y2038-cleanups-5.5' of git://git.kernel.org:/pub/scm/linux…
Browse files Browse the repository at this point in the history
…/kernel/git/arnd/playground

Pull y2038 cleanups from Arnd Bergmann:
 "y2038 syscall implementation cleanups

  This is a series of cleanups for the y2038 work, mostly intended for
  namespace cleaning: the kernel defines the traditional time_t, timeval
  and timespec types that often lead to y2038-unsafe code. Even though
  the unsafe usage is mostly gone from the kernel, having the types and
  associated functions around means that we can still grow new users,
  and that we may be missing conversions to safe types that actually
  matter.

  There are still a number of driver specific patches needed to get the
  last users of these types removed, those have been submitted to the
  respective maintainers"

Link: https://lore.kernel.org/lkml/[email protected]/

* tag 'y2038-cleanups-5.5' of git://git.kernel.org:/pub/scm/linux/kernel/git/arnd/playground: (26 commits)
  y2038: alarm: fix half-second cut-off
  y2038: ipc: fix x32 ABI breakage
  y2038: fix typo in powerpc vdso "LOPART"
  y2038: allow disabling time32 system calls
  y2038: itimer: change implementation to timespec64
  y2038: move itimer reset into itimer.c
  y2038: use compat_{get,set}_itimer on alpha
  y2038: itimer: compat handling to itimer.c
  y2038: time: avoid timespec usage in settimeofday()
  y2038: timerfd: Use timespec64 internally
  y2038: elfcore: Use __kernel_old_timeval for process times
  y2038: make ns_to_compat_timeval use __kernel_old_timeval
  y2038: socket: use __kernel_old_timespec instead of timespec
  y2038: socket: remove timespec reference in timestamping
  y2038: syscalls: change remaining timeval to __kernel_old_timeval
  y2038: rusage: use __kernel_old_timeval
  y2038: uapi: change __kernel_time_t to __kernel_old_time_t
  y2038: stat: avoid 'time_t' in 'struct stat'
  y2038: ipc: remove __kernel_time_t reference from headers
  y2038: vdso: powerpc: avoid timespec references
  ...
  • Loading branch information
torvalds committed Dec 1, 2019
2 parents 0da5221 + b111df8 commit ceb3074
Show file tree
Hide file tree
Showing 79 changed files with 472 additions and 468 deletions.
11 changes: 2 additions & 9 deletions arch/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -796,16 +796,9 @@ config OLD_SIGACTION
config COMPAT_OLD_SIGACTION
bool

config 64BIT_TIME
def_bool y
help
This should be selected by all architectures that need to support
new system calls with a 64-bit time_t. This is relevant on all 32-bit
architectures, and 64-bit architectures as part of compat syscall
handling.

config COMPAT_32BIT_TIME
def_bool !64BIT || COMPAT
bool "Provide system calls for 32-bit time_t"
default !64BIT || COMPAT
help
This enables 32 bit time_t support in addition to 64 bit time_t support.
This is relevant on all 32-bit architectures, and 64-bit architectures
Expand Down
67 changes: 1 addition & 66 deletions arch/alpha/kernel/osf_sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -963,38 +963,14 @@ put_tv32(struct timeval32 __user *o, struct timespec64 *i)
}

static inline long
put_tv_to_tv32(struct timeval32 __user *o, struct timeval *i)
put_tv_to_tv32(struct timeval32 __user *o, struct __kernel_old_timeval *i)
{
return copy_to_user(o, &(struct timeval32){
.tv_sec = i->tv_sec,
.tv_usec = i->tv_usec},
sizeof(struct timeval32));
}

static inline long
get_it32(struct itimerval *o, struct itimerval32 __user *i)
{
struct itimerval32 itv;
if (copy_from_user(&itv, i, sizeof(struct itimerval32)))
return -EFAULT;
o->it_interval.tv_sec = itv.it_interval.tv_sec;
o->it_interval.tv_usec = itv.it_interval.tv_usec;
o->it_value.tv_sec = itv.it_value.tv_sec;
o->it_value.tv_usec = itv.it_value.tv_usec;
return 0;
}

static inline long
put_it32(struct itimerval32 __user *o, struct itimerval *i)
{
return copy_to_user(o, &(struct itimerval32){
.it_interval.tv_sec = o->it_interval.tv_sec,
.it_interval.tv_usec = o->it_interval.tv_usec,
.it_value.tv_sec = o->it_value.tv_sec,
.it_value.tv_usec = o->it_value.tv_usec},
sizeof(struct itimerval32));
}

static inline void
jiffies_to_timeval32(unsigned long jiffies, struct timeval32 *value)
{
Expand Down Expand Up @@ -1039,47 +1015,6 @@ SYSCALL_DEFINE2(osf_settimeofday, struct timeval32 __user *, tv,

asmlinkage long sys_ni_posix_timers(void);

SYSCALL_DEFINE2(osf_getitimer, int, which, struct itimerval32 __user *, it)
{
struct itimerval kit;
int error;

if (!IS_ENABLED(CONFIG_POSIX_TIMERS))
return sys_ni_posix_timers();

error = do_getitimer(which, &kit);
if (!error && put_it32(it, &kit))
error = -EFAULT;

return error;
}

SYSCALL_DEFINE3(osf_setitimer, int, which, struct itimerval32 __user *, in,
struct itimerval32 __user *, out)
{
struct itimerval kin, kout;
int error;

if (!IS_ENABLED(CONFIG_POSIX_TIMERS))
return sys_ni_posix_timers();

if (in) {
if (get_it32(&kin, in))
return -EFAULT;
} else
memset(&kin, 0, sizeof(kin));

error = do_setitimer(which, &kin, out ? &kout : NULL);
if (error || !out)
return error;

if (put_it32(out, &kout))
return -EFAULT;

return 0;

}

SYSCALL_DEFINE2(osf_utimes, const char __user *, filename,
struct timeval32 __user *, tvs)
{
Expand Down
4 changes: 2 additions & 2 deletions arch/alpha/kernel/syscalls/syscall.tbl
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@
80 common setgroups sys_setgroups
81 common osf_old_getpgrp sys_ni_syscall
82 common setpgrp sys_setpgid
83 common osf_setitimer sys_osf_setitimer
83 common osf_setitimer compat_sys_setitimer
84 common osf_old_wait sys_ni_syscall
85 common osf_table sys_ni_syscall
86 common osf_getitimer sys_osf_getitimer
86 common osf_getitimer compat_sys_getitimer
87 common gethostname sys_gethostname
88 common sethostname sys_sethostname
89 common getdtablesize sys_getdtablesize
Expand Down
2 changes: 1 addition & 1 deletion arch/ia64/kernel/asm-offsets.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ void foo(void)
offsetof (struct cpuinfo_ia64, ptce_stride));
BLANK();
DEFINE(IA64_TIMESPEC_TV_NSEC_OFFSET,
offsetof (struct timespec, tv_nsec));
offsetof (struct __kernel_old_timespec, tv_nsec));
DEFINE(IA64_TIME_SN_SPEC_SNSEC_OFFSET,
offsetof (struct time_sn_spec, snsec));

Expand Down
6 changes: 3 additions & 3 deletions arch/mips/include/uapi/asm/msgbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
#if defined(__mips64)
struct msqid64_ds {
struct ipc64_perm msg_perm;
__kernel_time_t msg_stime; /* last msgsnd time */
__kernel_time_t msg_rtime; /* last msgrcv time */
__kernel_time_t msg_ctime; /* last change time */
long msg_stime; /* last msgsnd time */
long msg_rtime; /* last msgrcv time */
long msg_ctime; /* last change time */
unsigned long msg_cbytes; /* current number of bytes on queue */
unsigned long msg_qnum; /* number of messages in queue */
unsigned long msg_qbytes; /* max number of bytes on queue */
Expand Down
4 changes: 2 additions & 2 deletions arch/mips/include/uapi/asm/sembuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#ifdef __mips64
struct semid64_ds {
struct ipc64_perm sem_perm; /* permissions .. see ipc.h */
__kernel_time_t sem_otime; /* last semop time */
__kernel_time_t sem_ctime; /* last change time */
long sem_otime; /* last semop time */
long sem_ctime; /* last change time */
unsigned long sem_nsems; /* no. of semaphores in array */
unsigned long __unused1;
unsigned long __unused2;
Expand Down
6 changes: 3 additions & 3 deletions arch/mips/include/uapi/asm/shmbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
struct shmid64_ds {
struct ipc64_perm shm_perm; /* operation perms */
size_t shm_segsz; /* size of segment (bytes) */
__kernel_time_t shm_atime; /* last attach time */
__kernel_time_t shm_dtime; /* last detach time */
__kernel_time_t shm_ctime; /* last change time */
long shm_atime; /* last attach time */
long shm_dtime; /* last detach time */
long shm_ctime; /* last change time */
__kernel_pid_t shm_cpid; /* pid of creator */
__kernel_pid_t shm_lpid; /* pid of last operator */
unsigned long shm_nattch; /* no. of current attaches */
Expand Down
16 changes: 8 additions & 8 deletions arch/mips/include/uapi/asm/stat.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ struct stat {
gid_t st_gid;
unsigned st_rdev;
long st_pad2[2];
off_t st_size;
long st_size;
long st_pad3;
/*
* Actually this should be timestruc_t st_atime, st_mtime and st_ctime
* but we don't have it under Linux.
*/
time_t st_atime;
long st_atime;
long st_atime_nsec;
time_t st_mtime;
long st_mtime;
long st_mtime_nsec;
time_t st_ctime;
long st_ctime;
long st_ctime_nsec;
long st_blksize;
long st_blocks;
Expand Down Expand Up @@ -70,13 +70,13 @@ struct stat64 {
* Actually this should be timestruc_t st_atime, st_mtime and st_ctime
* but we don't have it under Linux.
*/
time_t st_atime;
long st_atime;
unsigned long st_atime_nsec; /* Reserved for st_atime expansion */

time_t st_mtime;
long st_mtime;
unsigned long st_mtime_nsec; /* Reserved for st_mtime expansion */

time_t st_ctime;
long st_ctime;
unsigned long st_ctime_nsec; /* Reserved for st_ctime expansion */

unsigned long st_blksize;
Expand Down Expand Up @@ -105,7 +105,7 @@ struct stat {
unsigned int st_rdev;
unsigned int st_pad1[3]; /* Reserved for st_rdev expansion */

off_t st_size;
long st_size;

/*
* Actually this should be timestruc_t st_atime, st_mtime and st_ctime
Expand Down
4 changes: 2 additions & 2 deletions arch/mips/kernel/binfmt_elfn32.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ jiffies_to_old_timeval32(unsigned long jiffies, struct old_timeval32 *value)
#undef TASK_SIZE
#define TASK_SIZE TASK_SIZE32

#undef ns_to_timeval
#define ns_to_timeval ns_to_old_timeval32
#undef ns_to_kernel_old_timeval
#define ns_to_kernel_old_timeval ns_to_old_timeval32

#include "../../../fs/binfmt_elf.c"
4 changes: 2 additions & 2 deletions arch/mips/kernel/binfmt_elfo32.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ jiffies_to_old_timeval32(unsigned long jiffies, struct old_timeval32 *value)
#undef TASK_SIZE
#define TASK_SIZE TASK_SIZE32

#undef ns_to_timeval
#define ns_to_timeval ns_to_old_timeval32
#undef ns_to_kernel_old_timeval
#define ns_to_kernel_old_timeval ns_to_old_timeval32

#include "../../../fs/binfmt_elf.c"
61 changes: 29 additions & 32 deletions arch/nds32/kernel/vdso/gettimeofday.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ static notrace int vdso_read_retry(const struct vdso_data *vdata, u32 start)
}

static notrace long clock_gettime_fallback(clockid_t _clkid,
struct timespec *_ts)
struct __kernel_old_timespec *_ts)
{
register struct timespec *ts asm("$r1") = _ts;
register struct __kernel_old_timespec *ts asm("$r1") = _ts;
register clockid_t clkid asm("$r0") = _clkid;
register long ret asm("$r0");

Expand All @@ -63,7 +63,7 @@ static notrace long clock_gettime_fallback(clockid_t _clkid,
return ret;
}

static notrace int do_realtime_coarse(struct timespec *ts,
static notrace int do_realtime_coarse(struct __kernel_old_timespec *ts,
struct vdso_data *vdata)
{
u32 seq;
Expand All @@ -78,25 +78,23 @@ static notrace int do_realtime_coarse(struct timespec *ts,
return 0;
}

static notrace int do_monotonic_coarse(struct timespec *ts,
static notrace int do_monotonic_coarse(struct __kernel_old_timespec *ts,
struct vdso_data *vdata)
{
struct timespec tomono;
u32 seq;
u64 ns;

do {
seq = vdso_read_begin(vdata);

ts->tv_sec = vdata->xtime_coarse_sec;
ts->tv_nsec = vdata->xtime_coarse_nsec;

tomono.tv_sec = vdata->wtm_clock_sec;
tomono.tv_nsec = vdata->wtm_clock_nsec;
ts->tv_sec = vdata->xtime_coarse_sec + vdata->wtm_clock_sec;
ns = vdata->xtime_coarse_nsec + vdata->wtm_clock_nsec;

} while (vdso_read_retry(vdata, seq));

ts->tv_sec += tomono.tv_sec;
timespec_add_ns(ts, tomono.tv_nsec);
ts->tv_sec += __iter_div_u64_rem(ns, NSEC_PER_SEC, &ns);
ts->tv_nsec = ns;

return 0;
}

Expand All @@ -115,7 +113,7 @@ static notrace inline u64 vgetsns(struct vdso_data *vdso)
return ((u64) cycle_delta & vdso->cs_mask) * vdso->cs_mult;
}

static notrace int do_realtime(struct timespec *ts, struct vdso_data *vdata)
static notrace int do_realtime(struct __kernel_old_timespec *ts, struct vdso_data *vdata)
{
unsigned count;
u64 ns;
Expand All @@ -133,32 +131,31 @@ static notrace int do_realtime(struct timespec *ts, struct vdso_data *vdata)
return 0;
}

static notrace int do_monotonic(struct timespec *ts, struct vdso_data *vdata)
static notrace int do_monotonic(struct __kernel_old_timespec *ts, struct vdso_data *vdata)
{
struct timespec tomono;
u64 nsecs;
u64 ns;
u32 seq;

do {
seq = vdso_read_begin(vdata);

ts->tv_sec = vdata->xtime_clock_sec;
nsecs = vdata->xtime_clock_nsec;
nsecs += vgetsns(vdata);
nsecs >>= vdata->cs_shift;
ns = vdata->xtime_clock_nsec;
ns += vgetsns(vdata);
ns >>= vdata->cs_shift;

tomono.tv_sec = vdata->wtm_clock_sec;
tomono.tv_nsec = vdata->wtm_clock_nsec;
ts->tv_sec += vdata->wtm_clock_sec;
ns += vdata->wtm_clock_nsec;

} while (vdso_read_retry(vdata, seq));

ts->tv_sec += tomono.tv_sec;
ts->tv_nsec = 0;
timespec_add_ns(ts, nsecs + tomono.tv_nsec);
ts->tv_sec += __iter_div_u64_rem(ns, NSEC_PER_SEC, &ns);
ts->tv_nsec = ns;

return 0;
}

notrace int __vdso_clock_gettime(clockid_t clkid, struct timespec *ts)
notrace int __vdso_clock_gettime(clockid_t clkid, struct __kernel_old_timespec *ts)
{
struct vdso_data *vdata;
int ret = -1;
Expand Down Expand Up @@ -191,10 +188,10 @@ notrace int __vdso_clock_gettime(clockid_t clkid, struct timespec *ts)
}

static notrace int clock_getres_fallback(clockid_t _clk_id,
struct timespec *_res)
struct __kernel_old_timespec *_res)
{
register clockid_t clk_id asm("$r0") = _clk_id;
register struct timespec *res asm("$r1") = _res;
register struct __kernel_old_timespec *res asm("$r1") = _res;
register int ret asm("$r0");

asm volatile ("movi $r15, %3\n"
Expand All @@ -206,7 +203,7 @@ static notrace int clock_getres_fallback(clockid_t _clk_id,
return ret;
}

notrace int __vdso_clock_getres(clockid_t clk_id, struct timespec *res)
notrace int __vdso_clock_getres(clockid_t clk_id, struct __kernel_old_timespec *res)
{
struct vdso_data *vdata = __get_datapage();

Expand All @@ -230,10 +227,10 @@ notrace int __vdso_clock_getres(clockid_t clk_id, struct timespec *res)
return 0;
}

static notrace inline int gettimeofday_fallback(struct timeval *_tv,
static notrace inline int gettimeofday_fallback(struct __kernel_old_timeval *_tv,
struct timezone *_tz)
{
register struct timeval *tv asm("$r0") = _tv;
register struct __kernel_old_timeval *tv asm("$r0") = _tv;
register struct timezone *tz asm("$r1") = _tz;
register int ret asm("$r0");

Expand All @@ -246,9 +243,9 @@ static notrace inline int gettimeofday_fallback(struct timeval *_tv,
return ret;
}

notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
notrace int __vdso_gettimeofday(struct __kernel_old_timeval *tv, struct timezone *tz)
{
struct timespec ts;
struct __kernel_old_timespec ts;
struct vdso_data *vdata;
int ret;

Expand Down
Loading

0 comments on commit ceb3074

Please sign in to comment.