Skip to content

Commit d5b7ffb

Browse files
deepa-hubAl Viro
authored andcommitted
time: introduce {get,put}_itimerspec64
As we change the user space type for the timerfd and posix timer functions to newer data types, we need some form of conversion helpers to avoid duplicating that logic. Suggested-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent f59dd9c commit d5b7ffb

5 files changed

Lines changed: 68 additions & 1 deletion

File tree

‎include/linux/compat.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ extern int compat_get_timeval(struct timeval *, const void __user *);
166166
extern int compat_put_timeval(const struct timeval *, void __user *);
167167
extern int compat_get_timespec64(struct timespec64 *, const void __user *);
168168
extern int compat_put_timespec64(const struct timespec64 *, void __user *);
169+
extern int get_compat_itimerspec64(struct itimerspec64 *its,
170+
const struct compat_itimerspec __user *uits);
171+
extern int put_compat_itimerspec64(const struct itimerspec64 *its,
172+
struct compat_itimerspec __user *uits);
169173

170174
/*
171175
* This function convert a timespec if necessary and returns a *user

‎include/linux/posix-timers.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,4 @@ void set_process_cpu_timer(struct task_struct *task, unsigned int clock_idx,
113113
void update_rlimit_cpu(struct task_struct *task, unsigned long rlim_new);
114114

115115
void posixtimer_rearm(struct siginfo *info);
116-
117116
#endif

‎include/linux/time.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ int get_timespec64(struct timespec64 *ts,
1212
const struct timespec __user *uts);
1313
int put_timespec64(const struct timespec64 *ts,
1414
struct timespec __user *uts);
15+
int get_itimerspec64(struct itimerspec64 *it,
16+
const struct itimerspec __user *uit);
17+
int put_itimerspec64(const struct itimerspec64 *it,
18+
struct itimerspec __user *uit);
1519

1620
#define TIME_T_MAX (time_t)((1UL << ((sizeof(time_t) << 3) - 1)) - 1)
1721

@@ -275,4 +279,13 @@ static __always_inline void timespec_add_ns(struct timespec *a, u64 ns)
275279
a->tv_nsec = ns;
276280
}
277281

282+
static inline bool itimerspec64_valid(const struct itimerspec64 *its)
283+
{
284+
if (!timespec64_valid(&(its->it_interval)) ||
285+
!timespec64_valid(&(its->it_value)))
286+
return false;
287+
288+
return true;
289+
}
290+
278291
#endif

‎kernel/compat.c‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,27 @@ int put_compat_itimerspec(struct compat_itimerspec __user *dst,
586586
return 0;
587587
}
588588

589+
int get_compat_itimerspec64(struct itimerspec64 *its,
590+
const struct compat_itimerspec __user *uits)
591+
{
592+
593+
if (__compat_get_timespec64(&its->it_interval, &uits->it_interval) ||
594+
__compat_get_timespec64(&its->it_value, &uits->it_value))
595+
return -EFAULT;
596+
return 0;
597+
}
598+
EXPORT_SYMBOL_GPL(get_compat_itimerspec64);
599+
600+
int put_compat_itimerspec64(const struct itimerspec64 *its,
601+
struct compat_itimerspec __user *uits)
602+
{
603+
if (__compat_put_timespec64(&its->it_interval, &uits->it_interval) ||
604+
__compat_put_timespec64(&its->it_value, &uits->it_value))
605+
return -EFAULT;
606+
return 0;
607+
}
608+
EXPORT_SYMBOL_GPL(put_compat_itimerspec64);
609+
589610
/*
590611
* We currently only need the following fields from the sigevent
591612
* structure: sigev_value, sigev_signo, sig_notify and (sometimes

‎kernel/time/time.c‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,3 +918,33 @@ int put_timespec64(const struct timespec64 *ts,
918918
return copy_to_user(uts, &kts, sizeof(kts)) ? -EFAULT : 0;
919919
}
920920
EXPORT_SYMBOL_GPL(put_timespec64);
921+
922+
int get_itimerspec64(struct itimerspec64 *it,
923+
const struct itimerspec __user *uit)
924+
{
925+
int ret;
926+
927+
ret = get_timespec64(&it->it_interval, &uit->it_interval);
928+
if (ret)
929+
return ret;
930+
931+
ret = get_timespec64(&it->it_value, &uit->it_value);
932+
933+
return ret;
934+
}
935+
EXPORT_SYMBOL_GPL(get_itimerspec64);
936+
937+
int put_itimerspec64(const struct itimerspec64 *it,
938+
struct itimerspec __user *uit)
939+
{
940+
int ret;
941+
942+
ret = put_timespec64(&it->it_interval, &uit->it_interval);
943+
if (ret)
944+
return ret;
945+
946+
ret = put_timespec64(&it->it_value, &uit->it_value);
947+
948+
return ret;
949+
}
950+
EXPORT_SYMBOL_GPL(put_itimerspec64);

0 commit comments

Comments
 (0)