26
26
* Returns the delta between the expiry time and now, which can be
27
27
* less than zero or 1usec for an pending expired timer
28
28
*/
29
- static struct timeval itimer_get_remtime (struct hrtimer * timer )
29
+ static struct timespec64 itimer_get_remtime (struct hrtimer * timer )
30
30
{
31
31
ktime_t rem = __hrtimer_get_remaining (timer , true);
32
32
@@ -41,11 +41,11 @@ static struct timeval itimer_get_remtime(struct hrtimer *timer)
41
41
} else
42
42
rem = 0 ;
43
43
44
- return ktime_to_timeval (rem );
44
+ return ktime_to_timespec64 (rem );
45
45
}
46
46
47
47
static void get_cpu_itimer (struct task_struct * tsk , unsigned int clock_id ,
48
- struct itimerval * const value )
48
+ struct itimerspec64 * const value )
49
49
{
50
50
u64 val , interval ;
51
51
struct cpu_itimer * it = & tsk -> signal -> it [clock_id ];
@@ -69,11 +69,11 @@ static void get_cpu_itimer(struct task_struct *tsk, unsigned int clock_id,
69
69
70
70
spin_unlock_irq (& tsk -> sighand -> siglock );
71
71
72
- value -> it_value = ns_to_timeval (val );
73
- value -> it_interval = ns_to_timeval (interval );
72
+ value -> it_value = ns_to_timespec64 (val );
73
+ value -> it_interval = ns_to_timespec64 (interval );
74
74
}
75
75
76
- static int do_getitimer (int which , struct itimerval * value )
76
+ static int do_getitimer (int which , struct itimerspec64 * value )
77
77
{
78
78
struct task_struct * tsk = current ;
79
79
@@ -82,7 +82,7 @@ static int do_getitimer(int which, struct itimerval *value)
82
82
spin_lock_irq (& tsk -> sighand -> siglock );
83
83
value -> it_value = itimer_get_remtime (& tsk -> signal -> real_timer );
84
84
value -> it_interval =
85
- ktime_to_timeval (tsk -> signal -> it_real_incr );
85
+ ktime_to_timespec64 (tsk -> signal -> it_real_incr );
86
86
spin_unlock_irq (& tsk -> sighand -> siglock );
87
87
break ;
88
88
case ITIMER_VIRTUAL :
@@ -97,17 +97,26 @@ static int do_getitimer(int which, struct itimerval *value)
97
97
return 0 ;
98
98
}
99
99
100
+ static int put_itimerval (struct itimerval __user * o ,
101
+ const struct itimerspec64 * i )
102
+ {
103
+ struct itimerval v ;
104
+
105
+ v .it_interval .tv_sec = i -> it_interval .tv_sec ;
106
+ v .it_interval .tv_usec = i -> it_interval .tv_nsec / NSEC_PER_USEC ;
107
+ v .it_value .tv_sec = i -> it_value .tv_sec ;
108
+ v .it_value .tv_usec = i -> it_value .tv_nsec / NSEC_PER_USEC ;
109
+ return copy_to_user (o , & v , sizeof (struct itimerval )) ? - EFAULT : 0 ;
110
+ }
111
+
112
+
100
113
SYSCALL_DEFINE2 (getitimer , int , which , struct itimerval __user * , value )
101
114
{
102
- int error = - EFAULT ;
103
- struct itimerval get_buffer ;
115
+ struct itimerspec64 get_buffer ;
116
+ int error = do_getitimer ( which , & get_buffer ) ;
104
117
105
- if (value ) {
106
- error = do_getitimer (which , & get_buffer );
107
- if (!error &&
108
- copy_to_user (value , & get_buffer , sizeof (get_buffer )))
109
- error = - EFAULT ;
110
- }
118
+ if (!error && put_itimerval (value , & get_buffer ))
119
+ error = - EFAULT ;
111
120
return error ;
112
121
}
113
122
@@ -117,24 +126,25 @@ struct old_itimerval32 {
117
126
struct old_timeval32 it_value ;
118
127
};
119
128
120
- static int put_old_itimerval32 (struct old_itimerval32 __user * o , const struct itimerval * i )
129
+ static int put_old_itimerval32 (struct old_itimerval32 __user * o ,
130
+ const struct itimerspec64 * i )
121
131
{
122
132
struct old_itimerval32 v32 ;
123
133
124
134
v32 .it_interval .tv_sec = i -> it_interval .tv_sec ;
125
- v32 .it_interval .tv_usec = i -> it_interval .tv_usec ;
135
+ v32 .it_interval .tv_usec = i -> it_interval .tv_nsec / NSEC_PER_USEC ;
126
136
v32 .it_value .tv_sec = i -> it_value .tv_sec ;
127
- v32 .it_value .tv_usec = i -> it_value .tv_usec ;
137
+ v32 .it_value .tv_usec = i -> it_value .tv_nsec / NSEC_PER_USEC ;
128
138
return copy_to_user (o , & v32 , sizeof (struct old_itimerval32 )) ? - EFAULT : 0 ;
129
139
}
130
140
131
141
COMPAT_SYSCALL_DEFINE2 (getitimer , int , which ,
132
- struct old_itimerval32 __user * , it )
142
+ struct old_itimerval32 __user * , value )
133
143
{
134
- struct itimerval kit ;
135
- int error = do_getitimer (which , & kit );
144
+ struct itimerspec64 get_buffer ;
145
+ int error = do_getitimer (which , & get_buffer );
136
146
137
- if (!error && put_old_itimerval32 (it , & kit ))
147
+ if (!error && put_old_itimerval32 (value , & get_buffer ))
138
148
error = - EFAULT ;
139
149
return error ;
140
150
}
@@ -156,8 +166,8 @@ enum hrtimer_restart it_real_fn(struct hrtimer *timer)
156
166
}
157
167
158
168
static void set_cpu_itimer (struct task_struct * tsk , unsigned int clock_id ,
159
- const struct itimerval * const value ,
160
- struct itimerval * const ovalue )
169
+ const struct itimerspec64 * const value ,
170
+ struct itimerspec64 * const ovalue )
161
171
{
162
172
u64 oval , nval , ointerval , ninterval ;
163
173
struct cpu_itimer * it = & tsk -> signal -> it [clock_id ];
@@ -166,8 +176,8 @@ static void set_cpu_itimer(struct task_struct *tsk, unsigned int clock_id,
166
176
* Use the to_ktime conversion because that clamps the maximum
167
177
* value to KTIME_MAX and avoid multiplication overflows.
168
178
*/
169
- nval = ktime_to_ns ( timeval_to_ktime ( value -> it_value ) );
170
- ninterval = ktime_to_ns ( timeval_to_ktime ( value -> it_interval ) );
179
+ nval = timespec64_to_ns ( & value -> it_value );
180
+ ninterval = timespec64_to_ns ( & value -> it_interval );
171
181
172
182
spin_lock_irq (& tsk -> sighand -> siglock );
173
183
@@ -186,8 +196,8 @@ static void set_cpu_itimer(struct task_struct *tsk, unsigned int clock_id,
186
196
spin_unlock_irq (& tsk -> sighand -> siglock );
187
197
188
198
if (ovalue ) {
189
- ovalue -> it_value = ns_to_timeval (oval );
190
- ovalue -> it_interval = ns_to_timeval (ointerval );
199
+ ovalue -> it_value = ns_to_timespec64 (oval );
200
+ ovalue -> it_interval = ns_to_timespec64 (ointerval );
191
201
}
192
202
}
193
203
@@ -197,19 +207,13 @@ static void set_cpu_itimer(struct task_struct *tsk, unsigned int clock_id,
197
207
#define timeval_valid (t ) \
198
208
(((t)->tv_sec >= 0) && (((unsigned long) (t)->tv_usec) < USEC_PER_SEC))
199
209
200
- static int do_setitimer (int which , struct itimerval * value , struct itimerval * ovalue )
210
+ static int do_setitimer (int which , struct itimerspec64 * value ,
211
+ struct itimerspec64 * ovalue )
201
212
{
202
213
struct task_struct * tsk = current ;
203
214
struct hrtimer * timer ;
204
215
ktime_t expires ;
205
216
206
- /*
207
- * Validate the timevals in value.
208
- */
209
- if (!timeval_valid (& value -> it_value ) ||
210
- !timeval_valid (& value -> it_interval ))
211
- return - EINVAL ;
212
-
213
217
switch (which ) {
214
218
case ITIMER_REAL :
215
219
again :
@@ -218,18 +222,18 @@ static int do_setitimer(int which, struct itimerval *value, struct itimerval *ov
218
222
if (ovalue ) {
219
223
ovalue -> it_value = itimer_get_remtime (timer );
220
224
ovalue -> it_interval
221
- = ktime_to_timeval (tsk -> signal -> it_real_incr );
225
+ = ktime_to_timespec64 (tsk -> signal -> it_real_incr );
222
226
}
223
227
/* We are sharing ->siglock with it_real_fn() */
224
228
if (hrtimer_try_to_cancel (timer ) < 0 ) {
225
229
spin_unlock_irq (& tsk -> sighand -> siglock );
226
230
hrtimer_cancel_wait_running (timer );
227
231
goto again ;
228
232
}
229
- expires = timeval_to_ktime (value -> it_value );
233
+ expires = timespec64_to_ktime (value -> it_value );
230
234
if (expires != 0 ) {
231
235
tsk -> signal -> it_real_incr =
232
- timeval_to_ktime (value -> it_interval );
236
+ timespec64_to_ktime (value -> it_interval );
233
237
hrtimer_start (timer , expires , HRTIMER_MODE_REL );
234
238
} else
235
239
tsk -> signal -> it_real_incr = 0 ;
@@ -252,7 +256,7 @@ static int do_setitimer(int which, struct itimerval *value, struct itimerval *ov
252
256
#ifdef CONFIG_SECURITY_SELINUX
253
257
void clear_itimer (void )
254
258
{
255
- struct itimerval v = {};
259
+ struct itimerspec64 v = {};
256
260
int i ;
257
261
258
262
for (i = 0 ; i < 3 ; i ++ )
@@ -276,24 +280,24 @@ void clear_itimer(void)
276
280
*/
277
281
static unsigned int alarm_setitimer (unsigned int seconds )
278
282
{
279
- struct itimerval it_new , it_old ;
283
+ struct itimerspec64 it_new , it_old ;
280
284
281
285
#if BITS_PER_LONG < 64
282
286
if (seconds > INT_MAX )
283
287
seconds = INT_MAX ;
284
288
#endif
285
289
it_new .it_value .tv_sec = seconds ;
286
- it_new .it_value .tv_usec = 0 ;
287
- it_new .it_interval .tv_sec = it_new .it_interval .tv_usec = 0 ;
290
+ it_new .it_value .tv_nsec = 0 ;
291
+ it_new .it_interval .tv_sec = it_new .it_interval .tv_nsec = 0 ;
288
292
289
293
do_setitimer (ITIMER_REAL , & it_new , & it_old );
290
294
291
295
/*
292
296
* We can't return 0 if we have an alarm pending ... And we'd
293
297
* better return too much than too little anyway
294
298
*/
295
- if ((!it_old .it_value .tv_sec && it_old .it_value .tv_usec ) ||
296
- it_old .it_value .tv_usec >= 500000 )
299
+ if ((!it_old .it_value .tv_sec && it_old .it_value .tv_nsec ) ||
300
+ it_old .it_value .tv_nsec >= 500000 )
297
301
it_old .it_value .tv_sec ++ ;
298
302
299
303
return it_old .it_value .tv_sec ;
@@ -310,15 +314,35 @@ SYSCALL_DEFINE1(alarm, unsigned int, seconds)
310
314
311
315
#endif
312
316
317
+ static int get_itimerval (struct itimerspec64 * o , const struct itimerval __user * i )
318
+ {
319
+ struct itimerval v ;
320
+
321
+ if (copy_from_user (& v , i , sizeof (struct itimerval )))
322
+ return - EFAULT ;
323
+
324
+ /* Validate the timevals in value. */
325
+ if (!timeval_valid (& v .it_value ) ||
326
+ !timeval_valid (& v .it_interval ))
327
+ return - EINVAL ;
328
+
329
+ o -> it_interval .tv_sec = v .it_interval .tv_sec ;
330
+ o -> it_interval .tv_nsec = v .it_interval .tv_usec * NSEC_PER_USEC ;
331
+ o -> it_value .tv_sec = v .it_value .tv_sec ;
332
+ o -> it_value .tv_nsec = v .it_value .tv_usec * NSEC_PER_USEC ;
333
+ return 0 ;
334
+ }
335
+
313
336
SYSCALL_DEFINE3 (setitimer , int , which , struct itimerval __user * , value ,
314
337
struct itimerval __user * , ovalue )
315
338
{
316
- struct itimerval set_buffer , get_buffer ;
339
+ struct itimerspec64 set_buffer , get_buffer ;
317
340
int error ;
318
341
319
342
if (value ) {
320
- if (copy_from_user (& set_buffer , value , sizeof (set_buffer )))
321
- return - EFAULT ;
343
+ error = get_itimerval (& set_buffer , value );
344
+ if (error )
345
+ return error ;
322
346
} else {
323
347
memset (& set_buffer , 0 , sizeof (set_buffer ));
324
348
printk_once (KERN_WARNING "%s calls setitimer() with new_value NULL pointer."
@@ -330,43 +354,53 @@ SYSCALL_DEFINE3(setitimer, int, which, struct itimerval __user *, value,
330
354
if (error || !ovalue )
331
355
return error ;
332
356
333
- if (copy_to_user (ovalue , & get_buffer , sizeof ( get_buffer ) ))
357
+ if (put_itimerval (ovalue , & get_buffer ))
334
358
return - EFAULT ;
335
359
return 0 ;
336
360
}
337
361
338
362
#if defined(CONFIG_COMPAT ) || defined(CONFIG_ALPHA )
339
- static int get_old_itimerval32 (struct itimerval * o , const struct old_itimerval32 __user * i )
363
+ static int get_old_itimerval32 (struct itimerspec64 * o , const struct old_itimerval32 __user * i )
340
364
{
341
365
struct old_itimerval32 v32 ;
342
366
343
367
if (copy_from_user (& v32 , i , sizeof (struct old_itimerval32 )))
344
368
return - EFAULT ;
369
+
370
+ /* Validate the timevals in value. */
371
+ if (!timeval_valid (& v32 .it_value ) ||
372
+ !timeval_valid (& v32 .it_interval ))
373
+ return - EINVAL ;
374
+
345
375
o -> it_interval .tv_sec = v32 .it_interval .tv_sec ;
346
- o -> it_interval .tv_usec = v32 .it_interval .tv_usec ;
376
+ o -> it_interval .tv_nsec = v32 .it_interval .tv_usec * NSEC_PER_USEC ;
347
377
o -> it_value .tv_sec = v32 .it_value .tv_sec ;
348
- o -> it_value .tv_usec = v32 .it_value .tv_usec ;
378
+ o -> it_value .tv_nsec = v32 .it_value .tv_usec * NSEC_PER_USEC ;
349
379
return 0 ;
350
380
}
351
381
352
382
COMPAT_SYSCALL_DEFINE3 (setitimer , int , which ,
353
- struct old_itimerval32 __user * , in ,
354
- struct old_itimerval32 __user * , out )
383
+ struct old_itimerval32 __user * , value ,
384
+ struct old_itimerval32 __user * , ovalue )
355
385
{
356
- struct itimerval kin , kout ;
386
+ struct itimerspec64 set_buffer , get_buffer ;
357
387
int error ;
358
388
359
- if (in ) {
360
- if (get_old_itimerval32 (& kin , in ))
361
- return - EFAULT ;
389
+ if (value ) {
390
+ error = get_old_itimerval32 (& set_buffer , value );
391
+ if (error )
392
+ return error ;
362
393
} else {
363
- memset (& kin , 0 , sizeof (kin ));
394
+ memset (& set_buffer , 0 , sizeof (set_buffer ));
395
+ printk_once (KERN_WARNING "%s calls setitimer() with new_value NULL pointer."
396
+ " Misfeature support will be removed\n" ,
397
+ current -> comm );
364
398
}
365
399
366
- error = do_setitimer (which , & kin , out ? & kout : NULL );
367
- if (error || !out )
400
+ error = do_setitimer (which , & set_buffer , ovalue ? & get_buffer : NULL );
401
+ if (error || !ovalue )
368
402
return error ;
369
- if (put_old_itimerval32 (out , & kout ))
403
+ if (put_old_itimerval32 (ovalue , & get_buffer ))
370
404
return - EFAULT ;
371
405
return 0 ;
372
406
}
0 commit comments