tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Fixing settime1() to reject invalid struct timespec ?
On Mon, Jul 27, 2009 at 03:26:25PM +0200, Joerg Sonnenberger wrote:
> On Mon, Jul 27, 2009 at 02:37:29PM +0200, Nicolas Joly wrote:
> > To solve this, we can: (a) use an ugly __UNCONST() when calling
> > itimespecfix(), or (b) drop the const qualifier from
> > clock_settime1()/settime1() ...
>
> (c) Normalise into a new variable.
That's even better ;-) It kills the __UNCONST from kauth call.
Here follow the corresponding patch.
--
Nicolas Joly
Biological Software and Databanks.
Institut Pasteur, Paris.
Index: sys/kern/kern_time.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kern_time.c,v
retrieving revision 1.160
diff -u -p -r1.160 kern_time.c
--- sys/kern/kern_time.c 29 Mar 2009 19:21:19 -0000 1.160
+++ sys/kern/kern_time.c 27 Jul 2009 15:09:04 -0000
@@ -131,16 +131,21 @@ time_init2(void)
static int
settime1(struct proc *p, const struct timespec *ts, bool check_kauth)
{
- struct timespec delta, now;
- int s;
+ struct timespec delta, now, nts;
+ int s, error;
+
+ nts.tv_sec = ts->tv_sec;
+ nts.tv_nsec = ts->tv_nsec;
+ if ((error = itimespecfix(&nts)) != 0)
+ return error;
/* WHAT DO WE DO ABOUT PENDING REAL-TIME TIMEOUTS??? */
s = splclock();
nanotime(&now);
- timespecsub(ts, &now, &delta);
+ timespecsub(&nts, &now, &delta);
if (check_kauth && kauth_authorize_system(kauth_cred_get(),
- KAUTH_SYSTEM_TIME, KAUTH_REQ_SYSTEM_TIME_SYSTEM, __UNCONST(ts),
+ KAUTH_SYSTEM_TIME, KAUTH_REQ_SYSTEM_TIME_SYSTEM, &nts,
&delta, KAUTH_ARG(check_kauth ? false : true)) != 0) {
splx(s);
return (EPERM);
@@ -153,7 +158,7 @@ settime1(struct proc *p, const struct ti
}
#endif
- tc_setclock(ts);
+ tc_setclock(&nts);
timespecadd(&boottime, &delta, &boottime);
Home |
Main Index |
Thread Index |
Old Index