| 116 | SYSINIT(posix_timer, SI_SUB_P1003_1B, SI_ORDER_FIRST+4, itimer_start, NULL); |
| 117 | |
| 118 | static int |
| 119 | settime(struct thread *td, struct timeval *tv) |
| 120 | { |
| 121 | struct timeval delta, tv1, tv2; |
| 122 | static struct timeval maxtime, laststep; |
| 123 | struct timespec ts; |
| 124 | |
| 125 | microtime(&tv1); |
| 126 | delta = *tv; |
| 127 | timevalsub(&delta, &tv1); |
| 128 | |
| 129 | /* |
| 130 | * If the system is secure, we do not allow the time to be |
| 131 | * set to a value earlier than 1 second less than the highest |
| 132 | * time we have yet seen. The worst a miscreant can do in |
| 133 | * this circumstance is "freeze" time. He couldn't go |
| 134 | * back to the past. |
| 135 | * |
| 136 | * We similarly do not allow the clock to be stepped more |
| 137 | * than one second, nor more than once per second. This allows |
| 138 | * a miscreant to make the clock march double-time, but no worse. |
| 139 | */ |
| 140 | if (securelevel_gt(td->td_ucred, 1) != 0) { |
| 141 | if (delta.tv_sec < 0 || delta.tv_usec < 0) { |
| 142 | /* |
| 143 | * Update maxtime to latest time we've seen. |
| 144 | */ |
| 145 | if (tv1.tv_sec > maxtime.tv_sec) |
| 146 | maxtime = tv1; |
| 147 | tv2 = *tv; |
| 148 | timevalsub(&tv2, &maxtime); |
| 149 | if (tv2.tv_sec < -1) { |
| 150 | tv->tv_sec = maxtime.tv_sec - 1; |
| 151 | printf("Time adjustment clamped to -1 second\n"); |
| 152 | } |
| 153 | } else { |
| 154 | if (tv1.tv_sec == laststep.tv_sec) |
| 155 | return (EPERM); |
| 156 | if (delta.tv_sec > 1) { |
| 157 | tv->tv_sec = tv1.tv_sec + 1; |
| 158 | printf("Time adjustment clamped to +1 second\n"); |
| 159 | } |
| 160 | laststep = *tv; |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | ts.tv_sec = tv->tv_sec; |
| 165 | ts.tv_nsec = tv->tv_usec * 1000; |
| 166 | tc_setclock(&ts); |
| 167 | resettodr(); |
| 168 | return (0); |
| 169 | } |
| 170 | |
| 171 | #ifndef _SYS_SYSPROTO_H_ |
| 172 | struct clock_getcpuclockid2_args { |
no test coverage detected