Skip to content

Commit

Permalink
y2038: globally rename compat_time to old_time32
Browse files Browse the repository at this point in the history
Christoph Hellwig suggested a slightly different path for handling
backwards compatibility with the 32-bit time_t based system calls:

Rather than simply reusing the compat_sys_* entry points on 32-bit
architectures unchanged, we get rid of those entry points and the
compat_time types by renaming them to something that makes more sense
on 32-bit architectures (which don't have a compat mode otherwise),
and then share the entry points under the new name with the 64-bit
architectures that use them for implementing the compatibility.

The following types and interfaces are renamed here, and moved
from linux/compat_time.h to linux/time32.h:

old				new
---				---
compat_time_t			old_time32_t
struct compat_timeval		struct old_timeval32
struct compat_timespec		struct old_timespec32
struct compat_itimerspec	struct old_itimerspec32
ns_to_compat_timeval()		ns_to_old_timeval32()
get_compat_itimerspec64()	get_old_itimerspec32()
put_compat_itimerspec64()	put_old_itimerspec32()
compat_get_timespec64()		get_old_timespec32()
compat_put_timespec64()		put_old_timespec32()

As we already have aliases in place, this patch addresses only the
instances that are relevant to the system call interface in particular,
not those that occur in device drivers and other modules. Those
will get handled separately, while providing the 64-bit version
of the respective interfaces.

I'm not renaming the timex, rusage and itimerval structures, as we are
still debating what the new interface will look like, and whether we
will need a replacement at all.

This also doesn't change the names of the syscall entry points, which can
be done more easily when we actually switch over the 32-bit architectures
to use them, at that point we need to change COMPAT_SYSCALL_DEFINEx to
SYSCALL_DEFINEx with a new name, e.g. with a _time32 suffix.

Suggested-by: Christoph Hellwig <[email protected]>
Link: https://lore.kernel.org/lkml/[email protected]/
Signed-off-by: Arnd Bergmann <[email protected]>
  • Loading branch information
arndb committed Aug 27, 2018
1 parent 33e2641 commit 9afc5ee
Show file tree
Hide file tree
Showing 36 changed files with 237 additions and 245 deletions.
6 changes: 3 additions & 3 deletions arch/arm64/include/asm/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ struct compat_stat {
compat_off_t st_size;
compat_off_t st_blksize;
compat_off_t st_blocks;
compat_time_t st_atime;
old_time32_t st_atime;
compat_ulong_t st_atime_nsec;
compat_time_t st_mtime;
old_time32_t st_mtime;
compat_ulong_t st_mtime_nsec;
compat_time_t st_ctime;
old_time32_t st_ctime;
compat_ulong_t st_ctime_nsec;
compat_ulong_t __unused4[2];
};
Expand Down
2 changes: 1 addition & 1 deletion arch/arm64/include/asm/stat.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#ifdef CONFIG_COMPAT

#include <linux/compat_time.h>
#include <linux/time.h>
#include <asm/compat.h>

/*
Expand Down
6 changes: 3 additions & 3 deletions arch/mips/include/asm/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ struct compat_stat {
s32 st_pad2[2];
compat_off_t st_size;
s32 st_pad3;
compat_time_t st_atime;
old_time32_t st_atime;
s32 st_atime_nsec;
compat_time_t st_mtime;
old_time32_t st_mtime;
s32 st_mtime_nsec;
compat_time_t st_ctime;
old_time32_t st_ctime;
s32 st_ctime_nsec;
s32 st_blksize;
s32 st_blocks;
Expand Down
14 changes: 7 additions & 7 deletions arch/mips/kernel/binfmt_elfn32.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ struct elf_prstatus32
pid_t pr_ppid;
pid_t pr_pgrp;
pid_t pr_sid;
struct compat_timeval pr_utime; /* User time */
struct compat_timeval pr_stime; /* System time */
struct compat_timeval pr_cutime;/* Cumulative user time */
struct compat_timeval pr_cstime;/* Cumulative system time */
struct old_timeval32 pr_utime; /* User time */
struct old_timeval32 pr_stime; /* System time */
struct old_timeval32 pr_cutime;/* Cumulative user time */
struct old_timeval32 pr_cstime;/* Cumulative system time */
elf_gregset_t pr_reg; /* GP registers */
int pr_fpvalid; /* True if math co-processor being used. */
};
Expand All @@ -81,9 +81,9 @@ struct elf_prpsinfo32
#define elf_caddr_t u32
#define init_elf_binfmt init_elfn32_binfmt

#define jiffies_to_timeval jiffies_to_compat_timeval
#define jiffies_to_timeval jiffies_to_old_timeval32
static __inline__ void
jiffies_to_compat_timeval(unsigned long jiffies, struct compat_timeval *value)
jiffies_to_old_timeval32(unsigned long jiffies, struct old_timeval32 *value)
{
/*
* Convert jiffies to nanoseconds and separate with
Expand All @@ -101,6 +101,6 @@ jiffies_to_compat_timeval(unsigned long jiffies, struct compat_timeval *value)
#define TASK_SIZE TASK_SIZE32

#undef ns_to_timeval
#define ns_to_timeval ns_to_compat_timeval
#define ns_to_timeval ns_to_old_timeval32

#include "../../../fs/binfmt_elf.c"
14 changes: 7 additions & 7 deletions arch/mips/kernel/binfmt_elfo32.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ struct elf_prstatus32
pid_t pr_ppid;
pid_t pr_pgrp;
pid_t pr_sid;
struct compat_timeval pr_utime; /* User time */
struct compat_timeval pr_stime; /* System time */
struct compat_timeval pr_cutime;/* Cumulative user time */
struct compat_timeval pr_cstime;/* Cumulative system time */
struct old_timeval32 pr_utime; /* User time */
struct old_timeval32 pr_stime; /* System time */
struct old_timeval32 pr_cutime;/* Cumulative user time */
struct old_timeval32 pr_cstime;/* Cumulative system time */
elf_gregset_t pr_reg; /* GP registers */
int pr_fpvalid; /* True if math co-processor being used. */
};
Expand All @@ -86,9 +86,9 @@ struct elf_prpsinfo32
#define elf_caddr_t u32
#define init_elf_binfmt init_elf32_binfmt

#define jiffies_to_timeval jiffies_to_compat_timeval
#define jiffies_to_timeval jiffies_to_old_timeval32
static inline void
jiffies_to_compat_timeval(unsigned long jiffies, struct compat_timeval *value)
jiffies_to_old_timeval32(unsigned long jiffies, struct old_timeval32 *value)
{
/*
* Convert jiffies to nanoseconds and separate with
Expand All @@ -104,6 +104,6 @@ jiffies_to_compat_timeval(unsigned long jiffies, struct compat_timeval *value)
#define TASK_SIZE TASK_SIZE32

#undef ns_to_timeval
#define ns_to_timeval ns_to_compat_timeval
#define ns_to_timeval ns_to_old_timeval32

#include "../../../fs/binfmt_elf.c"
6 changes: 3 additions & 3 deletions arch/parisc/include/asm/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ struct compat_stat {
u16 st_reserved2; /* old st_gid */
compat_dev_t st_rdev;
compat_off_t st_size;
compat_time_t st_atime;
old_time32_t st_atime;
u32 st_atime_nsec;
compat_time_t st_mtime;
old_time32_t st_mtime;
u32 st_mtime_nsec;
compat_time_t st_ctime;
old_time32_t st_ctime;
u32 st_ctime_nsec;
s32 st_blksize;
s32 st_blocks;
Expand Down
6 changes: 3 additions & 3 deletions arch/powerpc/include/asm/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ struct compat_stat {
compat_off_t st_size;
compat_off_t st_blksize;
compat_off_t st_blocks;
compat_time_t st_atime;
old_time32_t st_atime;
u32 st_atime_nsec;
compat_time_t st_mtime;
old_time32_t st_mtime;
u32 st_mtime_nsec;
compat_time_t st_ctime;
old_time32_t st_ctime;
u32 st_ctime_nsec;
u32 __unused4[2];
};
Expand Down
8 changes: 4 additions & 4 deletions arch/powerpc/kernel/asm-offsets.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,12 @@ int main(void)
OFFSET(CFG_SYSCALL_MAP64, vdso_data, syscall_map_64);
OFFSET(TVAL64_TV_SEC, timeval, tv_sec);
OFFSET(TVAL64_TV_USEC, timeval, tv_usec);
OFFSET(TVAL32_TV_SEC, compat_timeval, tv_sec);
OFFSET(TVAL32_TV_USEC, compat_timeval, tv_usec);
OFFSET(TVAL32_TV_SEC, old_timeval32, tv_sec);
OFFSET(TVAL32_TV_USEC, old_timeval32, tv_usec);
OFFSET(TSPC64_TV_SEC, timespec, tv_sec);
OFFSET(TSPC64_TV_NSEC, timespec, tv_nsec);
OFFSET(TSPC32_TV_SEC, compat_timespec, tv_sec);
OFFSET(TSPC32_TV_NSEC, compat_timespec, tv_nsec);
OFFSET(TSPC32_TV_SEC, old_timespec32, tv_sec);
OFFSET(TSPC32_TV_NSEC, old_timespec32, tv_nsec);
#else
OFFSET(TVAL32_TV_SEC, timeval, tv_sec);
OFFSET(TVAL32_TV_USEC, timeval, tv_usec);
Expand Down
2 changes: 1 addition & 1 deletion arch/powerpc/oprofile/backtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* 2 of the License, or (at your option) any later version.
**/

#include <linux/compat_time.h>
#include <linux/time.h>
#include <linux/oprofile.h>
#include <linux/sched.h>
#include <asm/processor.h>
Expand Down
6 changes: 3 additions & 3 deletions arch/sparc/include/asm/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ struct compat_stat {
__compat_gid_t st_gid;
compat_dev_t st_rdev;
compat_off_t st_size;
compat_time_t st_atime;
old_time32_t st_atime;
compat_ulong_t st_atime_nsec;
compat_time_t st_mtime;
old_time32_t st_mtime;
compat_ulong_t st_mtime_nsec;
compat_time_t st_ctime;
old_time32_t st_ctime;
compat_ulong_t st_ctime_nsec;
compat_off_t st_blksize;
compat_off_t st_blocks;
Expand Down
8 changes: 4 additions & 4 deletions fs/aio.c
Original file line number Diff line number Diff line change
Expand Up @@ -2135,12 +2135,12 @@ COMPAT_SYSCALL_DEFINE5(io_getevents, compat_aio_context_t, ctx_id,
compat_long_t, min_nr,
compat_long_t, nr,
struct io_event __user *, events,
struct compat_timespec __user *, timeout)
struct old_timespec32 __user *, timeout)
{
struct timespec64 t;
int ret;

if (timeout && compat_get_timespec64(&t, timeout))
if (timeout && get_old_timespec32(&t, timeout))
return -EFAULT;

ret = do_io_getevents(ctx_id, min_nr, nr, events, timeout ? &t : NULL);
Expand All @@ -2160,15 +2160,15 @@ COMPAT_SYSCALL_DEFINE6(io_pgetevents,
compat_long_t, min_nr,
compat_long_t, nr,
struct io_event __user *, events,
struct compat_timespec __user *, timeout,
struct old_timespec32 __user *, timeout,
const struct __compat_aio_sigset __user *, usig)
{
struct __compat_aio_sigset ksig = { NULL, };
sigset_t ksigmask, sigsaved;
struct timespec64 t;
int ret;

if (timeout && compat_get_timespec64(&t, timeout))
if (timeout && get_old_timespec32(&t, timeout))
return -EFAULT;

if (usig && copy_from_user(&ksig, usig, sizeof(ksig)))
Expand Down
2 changes: 1 addition & 1 deletion fs/compat_binfmt_elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
#define elf_prpsinfo compat_elf_prpsinfo

#undef ns_to_timeval
#define ns_to_timeval ns_to_compat_timeval
#define ns_to_timeval ns_to_old_timeval32

/*
* To use this file, asm/elf.h must define compat_elf_check_arch.
Expand Down
20 changes: 10 additions & 10 deletions fs/select.c
Original file line number Diff line number Diff line change
Expand Up @@ -1120,15 +1120,15 @@ int compat_poll_select_copy_remaining(struct timespec64 *end_time, void __user *
ts.tv_sec = ts.tv_nsec = 0;

if (timeval) {
struct compat_timeval rtv;
struct old_timeval32 rtv;

rtv.tv_sec = ts.tv_sec;
rtv.tv_usec = ts.tv_nsec / NSEC_PER_USEC;

if (!copy_to_user(p, &rtv, sizeof(rtv)))
return ret;
} else {
if (!compat_put_timespec64(&ts, p))
if (!put_old_timespec32(&ts, p))
return ret;
}
/*
Expand Down Expand Up @@ -1257,10 +1257,10 @@ static int compat_core_sys_select(int n, compat_ulong_t __user *inp,

static int do_compat_select(int n, compat_ulong_t __user *inp,
compat_ulong_t __user *outp, compat_ulong_t __user *exp,
struct compat_timeval __user *tvp)
struct old_timeval32 __user *tvp)
{
struct timespec64 end_time, *to = NULL;
struct compat_timeval tv;
struct old_timeval32 tv;
int ret;

if (tvp) {
Expand All @@ -1282,7 +1282,7 @@ static int do_compat_select(int n, compat_ulong_t __user *inp,

COMPAT_SYSCALL_DEFINE5(select, int, n, compat_ulong_t __user *, inp,
compat_ulong_t __user *, outp, compat_ulong_t __user *, exp,
struct compat_timeval __user *, tvp)
struct old_timeval32 __user *, tvp)
{
return do_compat_select(n, inp, outp, exp, tvp);
}
Expand All @@ -1307,15 +1307,15 @@ COMPAT_SYSCALL_DEFINE1(old_select, struct compat_sel_arg_struct __user *, arg)

static long do_compat_pselect(int n, compat_ulong_t __user *inp,
compat_ulong_t __user *outp, compat_ulong_t __user *exp,
struct compat_timespec __user *tsp, compat_sigset_t __user *sigmask,
struct old_timespec32 __user *tsp, compat_sigset_t __user *sigmask,
compat_size_t sigsetsize)
{
sigset_t ksigmask, sigsaved;
struct timespec64 ts, end_time, *to = NULL;
int ret;

if (tsp) {
if (compat_get_timespec64(&ts, tsp))
if (get_old_timespec32(&ts, tsp))
return -EFAULT;

to = &end_time;
Expand Down Expand Up @@ -1355,7 +1355,7 @@ static long do_compat_pselect(int n, compat_ulong_t __user *inp,

COMPAT_SYSCALL_DEFINE6(pselect6, int, n, compat_ulong_t __user *, inp,
compat_ulong_t __user *, outp, compat_ulong_t __user *, exp,
struct compat_timespec __user *, tsp, void __user *, sig)
struct old_timespec32 __user *, tsp, void __user *, sig)
{
compat_size_t sigsetsize = 0;
compat_uptr_t up = 0;
Expand All @@ -1373,15 +1373,15 @@ COMPAT_SYSCALL_DEFINE6(pselect6, int, n, compat_ulong_t __user *, inp,
}

COMPAT_SYSCALL_DEFINE5(ppoll, struct pollfd __user *, ufds,
unsigned int, nfds, struct compat_timespec __user *, tsp,
unsigned int, nfds, struct old_timespec32 __user *, tsp,
const compat_sigset_t __user *, sigmask, compat_size_t, sigsetsize)
{
sigset_t ksigmask, sigsaved;
struct timespec64 ts, end_time, *to = NULL;
int ret;

if (tsp) {
if (compat_get_timespec64(&ts, tsp))
if (get_old_timespec32(&ts, tsp))
return -EFAULT;

to = &end_time;
Expand Down
12 changes: 6 additions & 6 deletions fs/timerfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,29 +561,29 @@ SYSCALL_DEFINE2(timerfd_gettime, int, ufd, struct __kernel_itimerspec __user *,

#ifdef CONFIG_COMPAT_32BIT_TIME
COMPAT_SYSCALL_DEFINE4(timerfd_settime, int, ufd, int, flags,
const struct compat_itimerspec __user *, utmr,
struct compat_itimerspec __user *, otmr)
const struct old_itimerspec32 __user *, utmr,
struct old_itimerspec32 __user *, otmr)
{
struct itimerspec64 new, old;
int ret;

if (get_compat_itimerspec64(&new, utmr))
if (get_old_itimerspec32(&new, utmr))
return -EFAULT;
ret = do_timerfd_settime(ufd, flags, &new, &old);
if (ret)
return ret;
if (otmr && put_compat_itimerspec64(&old, otmr))
if (otmr && put_old_itimerspec32(&old, otmr))
return -EFAULT;
return ret;
}

COMPAT_SYSCALL_DEFINE2(timerfd_gettime, int, ufd,
struct compat_itimerspec __user *, otmr)
struct old_itimerspec32 __user *, otmr)
{
struct itimerspec64 kotmr;
int ret = do_timerfd_gettime(ufd, &kotmr);
if (ret)
return ret;
return put_compat_itimerspec64(&kotmr, otmr) ? -EFAULT : 0;
return put_old_itimerspec32(&kotmr, otmr) ? -EFAULT : 0;
}
#endif
12 changes: 6 additions & 6 deletions fs/utimes.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,13 @@ COMPAT_SYSCALL_DEFINE2(utime, const char __user *, filename,
return do_utimes(AT_FDCWD, filename, t ? tv : NULL, 0);
}

COMPAT_SYSCALL_DEFINE4(utimensat, unsigned int, dfd, const char __user *, filename, struct compat_timespec __user *, t, int, flags)
COMPAT_SYSCALL_DEFINE4(utimensat, unsigned int, dfd, const char __user *, filename, struct old_timespec32 __user *, t, int, flags)
{
struct timespec64 tv[2];

if (t) {
if (compat_get_timespec64(&tv[0], &t[0]) ||
compat_get_timespec64(&tv[1], &t[1]))
if (get_old_timespec32(&tv[0], &t[0]) ||
get_old_timespec32(&tv[1], &t[1]))
return -EFAULT;

if (tv[0].tv_nsec == UTIME_OMIT && tv[1].tv_nsec == UTIME_OMIT)
Expand All @@ -261,7 +261,7 @@ COMPAT_SYSCALL_DEFINE4(utimensat, unsigned int, dfd, const char __user *, filena
}

static long do_compat_futimesat(unsigned int dfd, const char __user *filename,
struct compat_timeval __user *t)
struct old_timeval32 __user *t)
{
struct timespec64 tv[2];

Expand All @@ -282,12 +282,12 @@ static long do_compat_futimesat(unsigned int dfd, const char __user *filename,

COMPAT_SYSCALL_DEFINE3(futimesat, unsigned int, dfd,
const char __user *, filename,
struct compat_timeval __user *, t)
struct old_timeval32 __user *, t)
{
return do_compat_futimesat(dfd, filename, t);
}

COMPAT_SYSCALL_DEFINE2(utimes, const char __user *, filename, struct compat_timeval __user *, t)
COMPAT_SYSCALL_DEFINE2(utimes, const char __user *, filename, struct old_timeval32 __user *, t)
{
return do_compat_futimesat(AT_FDCWD, filename, t);
}
Expand Down
Loading

0 comments on commit 9afc5ee

Please sign in to comment.