aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorMichael Kerrisk <mtk.manpages@googlemail.com>2008-06-10 00:16:09 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2008-06-23 08:43:52 -0400
commitc70f84417429f41519be0197a1092a53c2201f47 (patch)
tree50f5e12bc51dab519da6006e6197091e8cf00092 /fs
parent4cca92264e61a90b43fc4e076cd25b7f4e16dc61 (diff)
[patch for 2.6.26 4/4] vfs: utimensat(): fix write access check for futimens()
The POSIX.1 draft spec for futimens()/utimensat() says: Only a process with the effective user ID equal to the user ID of the file, *or with write access to the file*, or with appropriate privileges may use futimens() or utimensat() with a null pointer as the times argument or with both tv_nsec fields set to the special value UTIME_NOW. The important piece here is "with write access to the file", and this matters for futimens(), which deals with an argument that is a file descriptor referring to the file whose timestamps are being updated, The standard is saying that the "writability" check is based on the file permissions, not the access mode with which the file is opened. (This behavior is consistent with the semantics of FreeBSD's futimes().) However, Linux is currently doing the latter -- futimens(fd, times) is a library function implemented as utimensat(fd, NULL, times, 0) and within the utimensat() implementation we have the code: f = fget(dfd); // dfd is 'fd' ... if (f) { if (!(f->f_mode & FMODE_WRITE)) goto mnt_drop_write_and_out; The check should instead be based on the file permissions. Thanks to Miklos for pointing out how to do this check. Miklos also pointed out a simplification that could be made to my first version of this patch, since the checks for the pathname and file descriptor cases can now be conflated. 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')
-rw-r--r--fs/utimes.c11
1 files changed, 3 insertions, 8 deletions
diff --git a/fs/utimes.c b/fs/utimes.c
index 118d1c3241be..b6b664e7145e 100644
--- a/fs/utimes.c
+++ b/fs/utimes.c
@@ -148,14 +148,9 @@ long do_utimes(int dfd, char __user *filename, struct timespec *times, int flags
148 goto mnt_drop_write_and_out; 148 goto mnt_drop_write_and_out;
149 149
150 if (!is_owner_or_cap(inode)) { 150 if (!is_owner_or_cap(inode)) {
151 if (f) { 151 error = permission(inode, MAY_WRITE, NULL);
152 if (!(f->f_mode & FMODE_WRITE)) 152 if (error)
153 goto mnt_drop_write_and_out; 153 goto mnt_drop_write_and_out;
154 } else {
155 error = vfs_permission(&nd, MAY_WRITE);
156 if (error)
157 goto mnt_drop_write_and_out;
158 }
159 } 154 }
160 } 155 }
161 mutex_lock(&inode->i_mutex); 156 mutex_lock(&inode->i_mutex);