diff options
author | Michael Kerrisk <mtk.manpages@googlemail.com> | 2008-06-10 00:16:08 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2008-06-23 08:43:04 -0400 |
commit | 4cca92264e61a90b43fc4e076cd25b7f4e16dc61 (patch) | |
tree | f7472b3dc27101761b92bb05ffff7785a73317f3 /fs/utimes.c | |
parent | 94c70b9ba7e9c1036284e779e2fef5be89021533 (diff) |
[patch for 2.6.26 3/4] vfs: utimensat(): fix error checking for {UTIME_NOW,UTIME_OMIT} case
The POSIX.1 draft spec for utimensat() says:
Only a process with the effective user ID equal to the
user ID of the file or with appropriate privileges may use
futimens() or utimensat() with a non-null times argument
that does not have both tv_nsec fields set to UTIME_NOW
and does not have both tv_nsec fields set to UTIME_OMIT.
If this condition is violated, then the error EPERM should result.
However, the current implementation does not generate EPERM if
one tv_nsec field is UTIME_NOW while the other is UTIME_OMIT.
It should give this error for that case.
This patch:
a) Repairs that problem.
b) Removes the now unneeded nsec_special() helper function.
c) Adds some comments to explain the checks that are being
performed.
Thanks to Miklos, who provided comments on the previous iteration
of this patch. As a result, this version is a little simpler and
and its logic is better structured.
Miklos suggested an alternative idea, migrating the
is_owner_or_cap() checks into fs/attr.c:inode_change_ok() via
the use of an ATTR_OWNER_CHECK flag. Maybe we could do that
later, but for now I've gone with this version, which is
IMO simpler, and can be more easily read as being correct.
Acked-by: Miklos Szeredi <miklos@szeredi.hu>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Ulrich Drepper <drepper@redhat.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/utimes.c')
-rw-r--r-- | fs/utimes.c | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/fs/utimes.c b/fs/utimes.c index d466bc587e6e..118d1c3241be 100644 --- a/fs/utimes.c +++ b/fs/utimes.c | |||
@@ -40,14 +40,9 @@ asmlinkage long sys_utime(char __user *filename, struct utimbuf __user *times) | |||
40 | 40 | ||
41 | #endif | 41 | #endif |
42 | 42 | ||
43 | static bool nsec_special(long nsec) | ||
44 | { | ||
45 | return nsec == UTIME_OMIT || nsec == UTIME_NOW; | ||
46 | } | ||
47 | |||
48 | static bool nsec_valid(long nsec) | 43 | static bool nsec_valid(long nsec) |
49 | { | 44 | { |
50 | if (nsec_special(nsec)) | 45 | if (nsec == UTIME_OMIT || nsec == UTIME_NOW) |
51 | return true; | 46 | return true; |
52 | 47 | ||
53 | return nsec >= 0 && nsec <= 999999999; | 48 | return nsec >= 0 && nsec <= 999999999; |
@@ -106,7 +101,7 @@ long do_utimes(int dfd, char __user *filename, struct timespec *times, int flags | |||
106 | times[1].tv_nsec == UTIME_NOW) | 101 | times[1].tv_nsec == UTIME_NOW) |
107 | times = NULL; | 102 | times = NULL; |
108 | 103 | ||
109 | /* Don't worry, the checks are done in inode_change_ok() */ | 104 | /* In most cases, the checks are done in inode_change_ok() */ |
110 | newattrs.ia_valid = ATTR_CTIME | ATTR_MTIME | ATTR_ATIME; | 105 | newattrs.ia_valid = ATTR_CTIME | ATTR_MTIME | ATTR_ATIME; |
111 | if (times) { | 106 | if (times) { |
112 | error = -EPERM; | 107 | error = -EPERM; |
@@ -128,15 +123,26 @@ long do_utimes(int dfd, char __user *filename, struct timespec *times, int flags | |||
128 | newattrs.ia_mtime.tv_nsec = times[1].tv_nsec; | 123 | newattrs.ia_mtime.tv_nsec = times[1].tv_nsec; |
129 | newattrs.ia_valid |= ATTR_MTIME_SET; | 124 | newattrs.ia_valid |= ATTR_MTIME_SET; |
130 | } | 125 | } |
131 | } | ||
132 | 126 | ||
133 | /* | 127 | /* |
134 | * If times is NULL or both times are either UTIME_OMIT or | 128 | * For the UTIME_OMIT/UTIME_NOW and UTIME_NOW/UTIME_OMIT |
135 | * UTIME_NOW, then need to check permissions, because | 129 | * cases, we need to make an extra check that is not done by |
136 | * inode_change_ok() won't do it. | 130 | * inode_change_ok(). |
137 | */ | 131 | */ |
138 | if (!times || (nsec_special(times[0].tv_nsec) && | 132 | if (((times[0].tv_nsec == UTIME_NOW && |
139 | nsec_special(times[1].tv_nsec))) { | 133 | times[1].tv_nsec == UTIME_OMIT) |
134 | || | ||
135 | (times[0].tv_nsec == UTIME_OMIT && | ||
136 | times[1].tv_nsec == UTIME_NOW)) | ||
137 | && !is_owner_or_cap(inode)) | ||
138 | goto mnt_drop_write_and_out; | ||
139 | } else { | ||
140 | |||
141 | /* | ||
142 | * If times is NULL (or both times are UTIME_NOW), | ||
143 | * then we need to check permissions, because | ||
144 | * inode_change_ok() won't do it. | ||
145 | */ | ||
140 | error = -EACCES; | 146 | error = -EACCES; |
141 | if (IS_IMMUTABLE(inode)) | 147 | if (IS_IMMUTABLE(inode)) |
142 | goto mnt_drop_write_and_out; | 148 | goto mnt_drop_write_and_out; |