Skip to content

Commit 1c68adf

Browse files
deepa-hubarndb
authored andcommitted
compat: Enable compat_get/put_timespec64 always
These functions are used in the repurposed compat syscalls to provide backward compatibility for using 32 bit time_t on 32 bit systems. Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
1 parent 0d55303 commit 1c68adf

File tree

4 files changed

+56
-46
lines changed

4 files changed

+56
-46
lines changed

include/linux/compat.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,6 @@ extern int compat_get_timespec(struct timespec *, const void __user *);
294294
extern int compat_put_timespec(const struct timespec *, void __user *);
295295
extern int compat_get_timeval(struct timeval *, const void __user *);
296296
extern int compat_put_timeval(const struct timeval *, void __user *);
297-
extern int compat_get_timespec64(struct timespec64 *, const void __user *);
298-
extern int compat_put_timespec64(const struct timespec64 *, void __user *);
299297
extern int get_compat_itimerspec64(struct itimerspec64 *its,
300298
const struct compat_itimerspec __user *uits);
301299
extern int put_compat_itimerspec64(const struct itimerspec64 *its,

include/linux/compat_time.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#define _LINUX_COMPAT_TIME_H
44

55
#include <linux/types.h>
6+
#include <linux/time64.h>
67

78
typedef s32 compat_time_t;
89

@@ -16,4 +17,7 @@ struct compat_timeval {
1617
s32 tv_usec;
1718
};
1819

20+
extern int compat_get_timespec64(struct timespec64 *, const void __user *);
21+
extern int compat_put_timespec64(const struct timespec64 *, void __user *);
22+
1923
#endif /* _LINUX_COMPAT_TIME_H */

kernel/compat.c

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -120,50 +120,6 @@ static int __compat_put_timespec(const struct timespec *ts, struct compat_timesp
120120
__put_user(ts->tv_nsec, &cts->tv_nsec)) ? -EFAULT : 0;
121121
}
122122

123-
static int __compat_get_timespec64(struct timespec64 *ts64,
124-
const struct compat_timespec __user *cts)
125-
{
126-
struct compat_timespec ts;
127-
int ret;
128-
129-
ret = copy_from_user(&ts, cts, sizeof(ts));
130-
if (ret)
131-
return -EFAULT;
132-
133-
ts64->tv_sec = ts.tv_sec;
134-
ts64->tv_nsec = ts.tv_nsec;
135-
136-
return 0;
137-
}
138-
139-
static int __compat_put_timespec64(const struct timespec64 *ts64,
140-
struct compat_timespec __user *cts)
141-
{
142-
struct compat_timespec ts = {
143-
.tv_sec = ts64->tv_sec,
144-
.tv_nsec = ts64->tv_nsec
145-
};
146-
return copy_to_user(cts, &ts, sizeof(ts)) ? -EFAULT : 0;
147-
}
148-
149-
int compat_get_timespec64(struct timespec64 *ts, const void __user *uts)
150-
{
151-
if (COMPAT_USE_64BIT_TIME)
152-
return copy_from_user(ts, uts, sizeof(*ts)) ? -EFAULT : 0;
153-
else
154-
return __compat_get_timespec64(ts, uts);
155-
}
156-
EXPORT_SYMBOL_GPL(compat_get_timespec64);
157-
158-
int compat_put_timespec64(const struct timespec64 *ts, void __user *uts)
159-
{
160-
if (COMPAT_USE_64BIT_TIME)
161-
return copy_to_user(uts, ts, sizeof(*ts)) ? -EFAULT : 0;
162-
else
163-
return __compat_put_timespec64(ts, uts);
164-
}
165-
EXPORT_SYMBOL_GPL(compat_put_timespec64);
166-
167123
int compat_get_timeval(struct timeval *tv, const void __user *utv)
168124
{
169125
if (COMPAT_USE_64BIT_TIME)
@@ -367,6 +323,14 @@ COMPAT_SYSCALL_DEFINE3(sched_getaffinity, compat_pid_t, pid, unsigned int, len,
367323
return ret;
368324
}
369325

326+
/* Todo: Delete these extern declarations when get/put_compat_itimerspec64()
327+
* are moved to kernel/time/time.c .
328+
*/
329+
extern int __compat_get_timespec64(struct timespec64 *ts64,
330+
const struct compat_timespec __user *cts);
331+
extern int __compat_put_timespec64(const struct timespec64 *ts64,
332+
struct compat_timespec __user *cts);
333+
370334
int get_compat_itimerspec64(struct itimerspec64 *its,
371335
const struct compat_itimerspec __user *uits)
372336
{

kernel/time/time.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,50 @@ int put_timespec64(const struct timespec64 *ts,
880880
}
881881
EXPORT_SYMBOL_GPL(put_timespec64);
882882

883+
int __compat_get_timespec64(struct timespec64 *ts64,
884+
const struct compat_timespec __user *cts)
885+
{
886+
struct compat_timespec ts;
887+
int ret;
888+
889+
ret = copy_from_user(&ts, cts, sizeof(ts));
890+
if (ret)
891+
return -EFAULT;
892+
893+
ts64->tv_sec = ts.tv_sec;
894+
ts64->tv_nsec = ts.tv_nsec;
895+
896+
return 0;
897+
}
898+
899+
int __compat_put_timespec64(const struct timespec64 *ts64,
900+
struct compat_timespec __user *cts)
901+
{
902+
struct compat_timespec ts = {
903+
.tv_sec = ts64->tv_sec,
904+
.tv_nsec = ts64->tv_nsec
905+
};
906+
return copy_to_user(cts, &ts, sizeof(ts)) ? -EFAULT : 0;
907+
}
908+
909+
int compat_get_timespec64(struct timespec64 *ts, const void __user *uts)
910+
{
911+
if (COMPAT_USE_64BIT_TIME)
912+
return copy_from_user(ts, uts, sizeof(*ts)) ? -EFAULT : 0;
913+
else
914+
return __compat_get_timespec64(ts, uts);
915+
}
916+
EXPORT_SYMBOL_GPL(compat_get_timespec64);
917+
918+
int compat_put_timespec64(const struct timespec64 *ts, void __user *uts)
919+
{
920+
if (COMPAT_USE_64BIT_TIME)
921+
return copy_to_user(uts, ts, sizeof(*ts)) ? -EFAULT : 0;
922+
else
923+
return __compat_put_timespec64(ts, uts);
924+
}
925+
EXPORT_SYMBOL_GPL(compat_put_timespec64);
926+
883927
int get_itimerspec64(struct itimerspec64 *it,
884928
const struct itimerspec __user *uit)
885929
{

0 commit comments

Comments
 (0)