.. | .. |
---|
8 | 8 | #include <linux/compat.h> |
---|
9 | 9 | #include <asm/unistd.h> |
---|
10 | 10 | |
---|
11 | | -#ifdef __ARCH_WANT_SYS_UTIME |
---|
12 | | - |
---|
13 | | -/* |
---|
14 | | - * sys_utime() can be implemented in user-level using sys_utimes(). |
---|
15 | | - * Is this for backwards compatibility? If so, why not move it |
---|
16 | | - * into the appropriate arch directory (for those architectures that |
---|
17 | | - * need it). |
---|
18 | | - */ |
---|
19 | | - |
---|
20 | | -/* If times==NULL, set access and modification to current time, |
---|
21 | | - * must be owner or have write permission. |
---|
22 | | - * Else, update from *times, must be owner or super user. |
---|
23 | | - */ |
---|
24 | | -SYSCALL_DEFINE2(utime, char __user *, filename, struct utimbuf __user *, times) |
---|
25 | | -{ |
---|
26 | | - struct timespec64 tv[2]; |
---|
27 | | - |
---|
28 | | - if (times) { |
---|
29 | | - if (get_user(tv[0].tv_sec, ×->actime) || |
---|
30 | | - get_user(tv[1].tv_sec, ×->modtime)) |
---|
31 | | - return -EFAULT; |
---|
32 | | - tv[0].tv_nsec = 0; |
---|
33 | | - tv[1].tv_nsec = 0; |
---|
34 | | - } |
---|
35 | | - return do_utimes(AT_FDCWD, filename, times ? tv : NULL, 0); |
---|
36 | | -} |
---|
37 | | - |
---|
38 | | -#endif |
---|
39 | | - |
---|
40 | 11 | static bool nsec_valid(long nsec) |
---|
41 | 12 | { |
---|
42 | 13 | if (nsec == UTIME_OMIT || nsec == UTIME_NOW) |
---|
.. | .. |
---|
45 | 16 | return nsec >= 0 && nsec <= 999999999; |
---|
46 | 17 | } |
---|
47 | 18 | |
---|
48 | | -static int utimes_common(const struct path *path, struct timespec64 *times) |
---|
| 19 | +int vfs_utimes(const struct path *path, struct timespec64 *times) |
---|
49 | 20 | { |
---|
50 | 21 | int error; |
---|
51 | 22 | struct iattr newattrs; |
---|
52 | 23 | struct inode *inode = path->dentry->d_inode; |
---|
53 | 24 | struct inode *delegated_inode = NULL; |
---|
54 | 25 | |
---|
| 26 | + if (times) { |
---|
| 27 | + if (!nsec_valid(times[0].tv_nsec) || |
---|
| 28 | + !nsec_valid(times[1].tv_nsec)) |
---|
| 29 | + return -EINVAL; |
---|
| 30 | + if (times[0].tv_nsec == UTIME_NOW && |
---|
| 31 | + times[1].tv_nsec == UTIME_NOW) |
---|
| 32 | + times = NULL; |
---|
| 33 | + } |
---|
| 34 | + |
---|
55 | 35 | error = mnt_want_write(path->mnt); |
---|
56 | 36 | if (error) |
---|
57 | 37 | goto out; |
---|
58 | | - |
---|
59 | | - if (times && times[0].tv_nsec == UTIME_NOW && |
---|
60 | | - times[1].tv_nsec == UTIME_NOW) |
---|
61 | | - times = NULL; |
---|
62 | 38 | |
---|
63 | 39 | newattrs.ia_valid = ATTR_CTIME | ATTR_MTIME | ATTR_ATIME; |
---|
64 | 40 | if (times) { |
---|
65 | 41 | if (times[0].tv_nsec == UTIME_OMIT) |
---|
66 | 42 | newattrs.ia_valid &= ~ATTR_ATIME; |
---|
67 | 43 | else if (times[0].tv_nsec != UTIME_NOW) { |
---|
68 | | - newattrs.ia_atime.tv_sec = times[0].tv_sec; |
---|
69 | | - newattrs.ia_atime.tv_nsec = times[0].tv_nsec; |
---|
| 44 | + newattrs.ia_atime = times[0]; |
---|
70 | 45 | newattrs.ia_valid |= ATTR_ATIME_SET; |
---|
71 | 46 | } |
---|
72 | 47 | |
---|
73 | 48 | if (times[1].tv_nsec == UTIME_OMIT) |
---|
74 | 49 | newattrs.ia_valid &= ~ATTR_MTIME; |
---|
75 | 50 | else if (times[1].tv_nsec != UTIME_NOW) { |
---|
76 | | - newattrs.ia_mtime.tv_sec = times[1].tv_sec; |
---|
77 | | - newattrs.ia_mtime.tv_nsec = times[1].tv_nsec; |
---|
| 51 | + newattrs.ia_mtime = times[1]; |
---|
78 | 52 | newattrs.ia_valid |= ATTR_MTIME_SET; |
---|
79 | 53 | } |
---|
80 | 54 | /* |
---|
.. | .. |
---|
88 | 62 | } |
---|
89 | 63 | retry_deleg: |
---|
90 | 64 | inode_lock(inode); |
---|
91 | | - error = notify_change2(path->mnt, path->dentry, &newattrs, &delegated_inode); |
---|
| 65 | + error = notify_change(path->dentry, &newattrs, &delegated_inode); |
---|
92 | 66 | inode_unlock(inode); |
---|
93 | 67 | if (delegated_inode) { |
---|
94 | 68 | error = break_deleg_wait(&delegated_inode); |
---|
.. | .. |
---|
98 | 72 | |
---|
99 | 73 | mnt_drop_write(path->mnt); |
---|
100 | 74 | out: |
---|
| 75 | + return error; |
---|
| 76 | +} |
---|
| 77 | + |
---|
| 78 | +static int do_utimes_path(int dfd, const char __user *filename, |
---|
| 79 | + struct timespec64 *times, int flags) |
---|
| 80 | +{ |
---|
| 81 | + struct path path; |
---|
| 82 | + int lookup_flags = 0, error; |
---|
| 83 | + |
---|
| 84 | + if (flags & ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH)) |
---|
| 85 | + return -EINVAL; |
---|
| 86 | + |
---|
| 87 | + if (!(flags & AT_SYMLINK_NOFOLLOW)) |
---|
| 88 | + lookup_flags |= LOOKUP_FOLLOW; |
---|
| 89 | + if (flags & AT_EMPTY_PATH) |
---|
| 90 | + lookup_flags |= LOOKUP_EMPTY; |
---|
| 91 | + |
---|
| 92 | +retry: |
---|
| 93 | + error = user_path_at(dfd, filename, lookup_flags, &path); |
---|
| 94 | + if (error) |
---|
| 95 | + return error; |
---|
| 96 | + |
---|
| 97 | + error = vfs_utimes(&path, times); |
---|
| 98 | + path_put(&path); |
---|
| 99 | + if (retry_estale(error, lookup_flags)) { |
---|
| 100 | + lookup_flags |= LOOKUP_REVAL; |
---|
| 101 | + goto retry; |
---|
| 102 | + } |
---|
| 103 | + |
---|
| 104 | + return error; |
---|
| 105 | +} |
---|
| 106 | + |
---|
| 107 | +static int do_utimes_fd(int fd, struct timespec64 *times, int flags) |
---|
| 108 | +{ |
---|
| 109 | + struct fd f; |
---|
| 110 | + int error; |
---|
| 111 | + |
---|
| 112 | + if (flags) |
---|
| 113 | + return -EINVAL; |
---|
| 114 | + |
---|
| 115 | + f = fdget(fd); |
---|
| 116 | + if (!f.file) |
---|
| 117 | + return -EBADF; |
---|
| 118 | + error = vfs_utimes(&f.file->f_path, times); |
---|
| 119 | + fdput(f); |
---|
101 | 120 | return error; |
---|
102 | 121 | } |
---|
103 | 122 | |
---|
.. | .. |
---|
119 | 138 | long do_utimes(int dfd, const char __user *filename, struct timespec64 *times, |
---|
120 | 139 | int flags) |
---|
121 | 140 | { |
---|
122 | | - int error = -EINVAL; |
---|
123 | | - |
---|
124 | | - if (times && (!nsec_valid(times[0].tv_nsec) || |
---|
125 | | - !nsec_valid(times[1].tv_nsec))) { |
---|
126 | | - goto out; |
---|
127 | | - } |
---|
128 | | - |
---|
129 | | - if (flags & ~AT_SYMLINK_NOFOLLOW) |
---|
130 | | - goto out; |
---|
131 | | - |
---|
132 | | - if (filename == NULL && dfd != AT_FDCWD) { |
---|
133 | | - struct fd f; |
---|
134 | | - |
---|
135 | | - if (flags & AT_SYMLINK_NOFOLLOW) |
---|
136 | | - goto out; |
---|
137 | | - |
---|
138 | | - f = fdget(dfd); |
---|
139 | | - error = -EBADF; |
---|
140 | | - if (!f.file) |
---|
141 | | - goto out; |
---|
142 | | - |
---|
143 | | - error = utimes_common(&f.file->f_path, times); |
---|
144 | | - fdput(f); |
---|
145 | | - } else { |
---|
146 | | - struct path path; |
---|
147 | | - int lookup_flags = 0; |
---|
148 | | - |
---|
149 | | - if (!(flags & AT_SYMLINK_NOFOLLOW)) |
---|
150 | | - lookup_flags |= LOOKUP_FOLLOW; |
---|
151 | | -retry: |
---|
152 | | - error = user_path_at(dfd, filename, lookup_flags, &path); |
---|
153 | | - if (error) |
---|
154 | | - goto out; |
---|
155 | | - |
---|
156 | | - error = utimes_common(&path, times); |
---|
157 | | - path_put(&path); |
---|
158 | | - if (retry_estale(error, lookup_flags)) { |
---|
159 | | - lookup_flags |= LOOKUP_REVAL; |
---|
160 | | - goto retry; |
---|
161 | | - } |
---|
162 | | - } |
---|
163 | | - |
---|
164 | | -out: |
---|
165 | | - return error; |
---|
| 141 | + if (filename == NULL && dfd != AT_FDCWD) |
---|
| 142 | + return do_utimes_fd(dfd, times, flags); |
---|
| 143 | + return do_utimes_path(dfd, filename, times, flags); |
---|
166 | 144 | } |
---|
167 | 145 | |
---|
168 | 146 | SYSCALL_DEFINE4(utimensat, int, dfd, const char __user *, filename, |
---|
169 | | - struct timespec __user *, utimes, int, flags) |
---|
| 147 | + struct __kernel_timespec __user *, utimes, int, flags) |
---|
170 | 148 | { |
---|
171 | 149 | struct timespec64 tstimes[2]; |
---|
172 | 150 | |
---|
.. | .. |
---|
184 | 162 | return do_utimes(dfd, filename, utimes ? tstimes : NULL, flags); |
---|
185 | 163 | } |
---|
186 | 164 | |
---|
| 165 | +#ifdef __ARCH_WANT_SYS_UTIME |
---|
| 166 | +/* |
---|
| 167 | + * futimesat(), utimes() and utime() are older versions of utimensat() |
---|
| 168 | + * that are provided for compatibility with traditional C libraries. |
---|
| 169 | + * On modern architectures, we always use libc wrappers around |
---|
| 170 | + * utimensat() instead. |
---|
| 171 | + */ |
---|
187 | 172 | static long do_futimesat(int dfd, const char __user *filename, |
---|
188 | | - struct timeval __user *utimes) |
---|
| 173 | + struct __kernel_old_timeval __user *utimes) |
---|
189 | 174 | { |
---|
190 | | - struct timeval times[2]; |
---|
| 175 | + struct __kernel_old_timeval times[2]; |
---|
191 | 176 | struct timespec64 tstimes[2]; |
---|
192 | 177 | |
---|
193 | 178 | if (utimes) { |
---|
.. | .. |
---|
214 | 199 | |
---|
215 | 200 | |
---|
216 | 201 | SYSCALL_DEFINE3(futimesat, int, dfd, const char __user *, filename, |
---|
217 | | - struct timeval __user *, utimes) |
---|
| 202 | + struct __kernel_old_timeval __user *, utimes) |
---|
218 | 203 | { |
---|
219 | 204 | return do_futimesat(dfd, filename, utimes); |
---|
220 | 205 | } |
---|
221 | 206 | |
---|
222 | 207 | SYSCALL_DEFINE2(utimes, char __user *, filename, |
---|
223 | | - struct timeval __user *, utimes) |
---|
| 208 | + struct __kernel_old_timeval __user *, utimes) |
---|
224 | 209 | { |
---|
225 | 210 | return do_futimesat(AT_FDCWD, filename, utimes); |
---|
226 | 211 | } |
---|
227 | 212 | |
---|
228 | | -#ifdef CONFIG_COMPAT |
---|
| 213 | +SYSCALL_DEFINE2(utime, char __user *, filename, struct utimbuf __user *, times) |
---|
| 214 | +{ |
---|
| 215 | + struct timespec64 tv[2]; |
---|
| 216 | + |
---|
| 217 | + if (times) { |
---|
| 218 | + if (get_user(tv[0].tv_sec, ×->actime) || |
---|
| 219 | + get_user(tv[1].tv_sec, ×->modtime)) |
---|
| 220 | + return -EFAULT; |
---|
| 221 | + tv[0].tv_nsec = 0; |
---|
| 222 | + tv[1].tv_nsec = 0; |
---|
| 223 | + } |
---|
| 224 | + return do_utimes(AT_FDCWD, filename, times ? tv : NULL, 0); |
---|
| 225 | +} |
---|
| 226 | +#endif |
---|
| 227 | + |
---|
| 228 | +#ifdef CONFIG_COMPAT_32BIT_TIME |
---|
229 | 229 | /* |
---|
230 | 230 | * Not all architectures have sys_utime, so implement this in terms |
---|
231 | 231 | * of sys_utimes. |
---|
232 | 232 | */ |
---|
233 | | -COMPAT_SYSCALL_DEFINE2(utime, const char __user *, filename, |
---|
234 | | - struct compat_utimbuf __user *, t) |
---|
| 233 | +#ifdef __ARCH_WANT_SYS_UTIME32 |
---|
| 234 | +SYSCALL_DEFINE2(utime32, const char __user *, filename, |
---|
| 235 | + struct old_utimbuf32 __user *, t) |
---|
235 | 236 | { |
---|
236 | 237 | struct timespec64 tv[2]; |
---|
237 | 238 | |
---|
.. | .. |
---|
244 | 245 | } |
---|
245 | 246 | return do_utimes(AT_FDCWD, filename, t ? tv : NULL, 0); |
---|
246 | 247 | } |
---|
| 248 | +#endif |
---|
247 | 249 | |
---|
248 | | -COMPAT_SYSCALL_DEFINE4(utimensat, unsigned int, dfd, const char __user *, filename, struct compat_timespec __user *, t, int, flags) |
---|
| 250 | +SYSCALL_DEFINE4(utimensat_time32, unsigned int, dfd, const char __user *, filename, struct old_timespec32 __user *, t, int, flags) |
---|
249 | 251 | { |
---|
250 | 252 | struct timespec64 tv[2]; |
---|
251 | 253 | |
---|
252 | 254 | if (t) { |
---|
253 | | - if (compat_get_timespec64(&tv[0], &t[0]) || |
---|
254 | | - compat_get_timespec64(&tv[1], &t[1])) |
---|
| 255 | + if (get_old_timespec32(&tv[0], &t[0]) || |
---|
| 256 | + get_old_timespec32(&tv[1], &t[1])) |
---|
255 | 257 | return -EFAULT; |
---|
256 | 258 | |
---|
257 | 259 | if (tv[0].tv_nsec == UTIME_OMIT && tv[1].tv_nsec == UTIME_OMIT) |
---|
.. | .. |
---|
260 | 262 | return do_utimes(dfd, filename, t ? tv : NULL, flags); |
---|
261 | 263 | } |
---|
262 | 264 | |
---|
| 265 | +#ifdef __ARCH_WANT_SYS_UTIME32 |
---|
263 | 266 | static long do_compat_futimesat(unsigned int dfd, const char __user *filename, |
---|
264 | | - struct compat_timeval __user *t) |
---|
| 267 | + struct old_timeval32 __user *t) |
---|
265 | 268 | { |
---|
266 | 269 | struct timespec64 tv[2]; |
---|
267 | 270 | |
---|
.. | .. |
---|
280 | 283 | return do_utimes(dfd, filename, t ? tv : NULL, 0); |
---|
281 | 284 | } |
---|
282 | 285 | |
---|
283 | | -COMPAT_SYSCALL_DEFINE3(futimesat, unsigned int, dfd, |
---|
| 286 | +SYSCALL_DEFINE3(futimesat_time32, unsigned int, dfd, |
---|
284 | 287 | const char __user *, filename, |
---|
285 | | - struct compat_timeval __user *, t) |
---|
| 288 | + struct old_timeval32 __user *, t) |
---|
286 | 289 | { |
---|
287 | 290 | return do_compat_futimesat(dfd, filename, t); |
---|
288 | 291 | } |
---|
289 | 292 | |
---|
290 | | -COMPAT_SYSCALL_DEFINE2(utimes, const char __user *, filename, struct compat_timeval __user *, t) |
---|
| 293 | +SYSCALL_DEFINE2(utimes_time32, const char __user *, filename, struct old_timeval32 __user *, t) |
---|
291 | 294 | { |
---|
292 | 295 | return do_compat_futimesat(AT_FDCWD, filename, t); |
---|
293 | 296 | } |
---|
294 | 297 | #endif |
---|
| 298 | +#endif |
---|