| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: kern_time.c,v 1.201 2019/10/05 12:57:40 kamil Exp $ */ | | 1 | /* $NetBSD: kern_time.c,v 1.202 2020/01/01 17:28:17 thorpej Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2000, 2004, 2005, 2007, 2008, 2009 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2000, 2004, 2005, 2007, 2008, 2009 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Christopher G. Demetriou, and by Andrew Doran. | | 8 | * by Christopher G. Demetriou, and by Andrew Doran. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -51,27 +51,27 @@ | | | @@ -51,27 +51,27 @@ |
51 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | | 51 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
52 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 52 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
53 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 53 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
54 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 54 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
55 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 55 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
56 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 56 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
57 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 57 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
58 | * SUCH DAMAGE. | | 58 | * SUCH DAMAGE. |
59 | * | | 59 | * |
60 | * @(#)kern_time.c 8.4 (Berkeley) 5/26/95 | | 60 | * @(#)kern_time.c 8.4 (Berkeley) 5/26/95 |
61 | */ | | 61 | */ |
62 | | | 62 | |
63 | #include <sys/cdefs.h> | | 63 | #include <sys/cdefs.h> |
64 | __KERNEL_RCSID(0, "$NetBSD: kern_time.c,v 1.201 2019/10/05 12:57:40 kamil Exp $"); | | 64 | __KERNEL_RCSID(0, "$NetBSD: kern_time.c,v 1.202 2020/01/01 17:28:17 thorpej Exp $"); |
65 | | | 65 | |
66 | #include <sys/param.h> | | 66 | #include <sys/param.h> |
67 | #include <sys/resourcevar.h> | | 67 | #include <sys/resourcevar.h> |
68 | #include <sys/kernel.h> | | 68 | #include <sys/kernel.h> |
69 | #include <sys/systm.h> | | 69 | #include <sys/systm.h> |
70 | #include <sys/proc.h> | | 70 | #include <sys/proc.h> |
71 | #include <sys/vnode.h> | | 71 | #include <sys/vnode.h> |
72 | #include <sys/signalvar.h> | | 72 | #include <sys/signalvar.h> |
73 | #include <sys/syslog.h> | | 73 | #include <sys/syslog.h> |
74 | #include <sys/timetc.h> | | 74 | #include <sys/timetc.h> |
75 | #include <sys/timex.h> | | 75 | #include <sys/timex.h> |
76 | #include <sys/kauth.h> | | 76 | #include <sys/kauth.h> |
77 | #include <sys/mount.h> | | 77 | #include <sys/mount.h> |
| @@ -126,53 +126,48 @@ time_init2(void) | | | @@ -126,53 +126,48 @@ time_init2(void) |
126 | * | | 126 | * |
127 | * These routines provide the kernel entry points to get and set | | 127 | * These routines provide the kernel entry points to get and set |
128 | * the time-of-day and per-process interval timers. Subroutines | | 128 | * the time-of-day and per-process interval timers. Subroutines |
129 | * here provide support for adding and subtracting timeval structures | | 129 | * here provide support for adding and subtracting timeval structures |
130 | * and decrementing interval timers, optionally reloading the interval | | 130 | * and decrementing interval timers, optionally reloading the interval |
131 | * timers when they expire. | | 131 | * timers when they expire. |
132 | */ | | 132 | */ |
133 | | | 133 | |
134 | /* This function is used by clock_settime and settimeofday */ | | 134 | /* This function is used by clock_settime and settimeofday */ |
135 | static int | | 135 | static int |
136 | settime1(struct proc *p, const struct timespec *ts, bool check_kauth) | | 136 | settime1(struct proc *p, const struct timespec *ts, bool check_kauth) |
137 | { | | 137 | { |
138 | struct timespec delta, now; | | 138 | struct timespec delta, now; |
139 | int s; | | | |
140 | | | 139 | |
141 | /* WHAT DO WE DO ABOUT PENDING REAL-TIME TIMEOUTS??? */ | | 140 | /* WHAT DO WE DO ABOUT PENDING REAL-TIME TIMEOUTS??? */ |
142 | s = splclock(); | | | |
143 | nanotime(&now); | | 141 | nanotime(&now); |
144 | timespecsub(ts, &now, &delta); | | 142 | timespecsub(ts, &now, &delta); |
145 | | | 143 | |
146 | if (check_kauth && kauth_authorize_system(kauth_cred_get(), | | 144 | if (check_kauth && kauth_authorize_system(kauth_cred_get(), |
147 | KAUTH_SYSTEM_TIME, KAUTH_REQ_SYSTEM_TIME_SYSTEM, __UNCONST(ts), | | 145 | KAUTH_SYSTEM_TIME, KAUTH_REQ_SYSTEM_TIME_SYSTEM, __UNCONST(ts), |
148 | &delta, KAUTH_ARG(check_kauth ? false : true)) != 0) { | | 146 | &delta, KAUTH_ARG(check_kauth ? false : true)) != 0) { |
149 | splx(s); | | | |
150 | return (EPERM); | | 147 | return (EPERM); |
151 | } | | 148 | } |
152 | | | 149 | |
153 | #ifdef notyet | | 150 | #ifdef notyet |
154 | if ((delta.tv_sec < 86400) && securelevel > 0) { /* XXX elad - notyet */ | | 151 | if ((delta.tv_sec < 86400) && securelevel > 0) { /* XXX elad - notyet */ |
155 | splx(s); | | | |
156 | return (EPERM); | | 152 | return (EPERM); |
157 | } | | 153 | } |
158 | #endif | | 154 | #endif |
159 | | | 155 | |
160 | tc_setclock(ts); | | 156 | tc_setclock(ts); |
161 | | | 157 | |
162 | timespecadd(&boottime, &delta, &boottime); | | 158 | timespecadd(&boottime, &delta, &boottime); |
163 | | | 159 | |
164 | resettodr(); | | 160 | resettodr(); |
165 | splx(s); | | | |
166 | | | 161 | |
167 | return (0); | | 162 | return (0); |
168 | } | | 163 | } |
169 | | | 164 | |
170 | int | | 165 | int |
171 | settime(struct proc *p, struct timespec *ts) | | 166 | settime(struct proc *p, struct timespec *ts) |
172 | { | | 167 | { |
173 | return (settime1(p, ts, true)); | | 168 | return (settime1(p, ts, true)); |
174 | } | | 169 | } |
175 | | | 170 | |
176 | /* ARGSUSED */ | | 171 | /* ARGSUSED */ |
177 | int | | 172 | int |
178 | sys___clock_gettime50(struct lwp *l, | | 173 | sys___clock_gettime50(struct lwp *l, |