gfs2: Update setattr permission checks
Andreas Gruenbacher
maintainerPATCH 1/1 gfs2: Update setattr permission checks
Update the permission checks in gfs2_setattr to match those in notify_change. Previously, attempts to set the timestamps of an append-only files to the current time were always denied.
Combines mainline commits beb29e058c35a and f2b20f6ee8423.
Fixes xfstest generic/079.
--- fs/gfs2/inode.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)
fs/gfs2/inode.c +21 -3
@@ -1929,9 +1929,27 @@ static int gfs2_setattr(struct dentry *dentry, struct iattr *attr)if (error)return error; - error = -EPERM ; -if (IS_IMMUTABLE (inode) ||IS_APPEND (inode)) - goto out; +if (attr->ia_valid & (ATTR_MODE |ATTR_UID |ATTR_GID |ATTR_TIMES_SET )) { + error = -EPERM ; +if (IS_IMMUTABLE (inode) ||IS_APPEND (inode)) + goto out; + } + +/* +* If utimes(2) and friends are called with times == NULL (or both +* times are UTIME_NOW), then we need to check for write permission +*/ +if (attr->ia_valid &ATTR_TOUCH ) { + error = -EACCES ; +if (IS_IMMUTABLE (inode)) + goto out; + +if (!inode_owner_or_capable (inode)) { + error =inode_permission (inode,MAY_WRITE ); +if (error) + goto out; + } + } error =setattr_prepare (dentry, attr);if (error)
Signature · 1 line
2.14.3
PATCH 1/1 gfs2: Update setattr permission checks
Quoted 5 lines · Andreas Gruenbacher
Update the permission checks in
gfs2_setattrto match those innotify_change. Previously, attempts to set the timestamps of an append-only files to the current time were always denied.Combines mainline commits
beb29e058c35aandf2b20f6ee8423.
Why do you need these duplicate checks? As far as I can tell all other file systems rely on notify_change to do this work for them.
If there is a good reason please factor out the checks and add EXPORT_SYMBOL_GPL helper for them that is well documented and can be used by gfs2.
fs/gfs2/inode.c static int gfs2_setattr(struct dentry *dentry, struct iattr *attr) · line 1932
Quoted 1 line
fs/gfs2/inode.c +1
-0+if (attr->ia_valid & (ATTR_MODE |ATTR_UID |ATTR_GID |ATTR_TIMES_SET )) {
Line over 80 characters, please break up.
Andreas Gruenbacher
maintainerPATCH 1/1 gfs2: Update setattr permission checks
Quoted 10 lines · Christoph Hellwig
Quoted 5 lines · Andreas Gruenbacher
Update the permission checks in
gfs2_setattrto match those innotify_change. Previously, attempts to set the timestamps of an append-only files to the current time were always denied.Combines mainline commits
beb29e058c35aandf2b20f6ee8423.Why do you need these duplicate checks? As far as I can tell all other file systems rely on
notify_changeto do this work for them.
The VFS performs its checks before the filesystem gets a chance to acquire the cluster wide lock and bring the inode up to date, so the filesystem re-checks in case the inode was stale. This kind of problem exists in several places, and there can be false negatives, which is very ugly. It might be possible to move some of the checks from notify_change into setattr_prepare to get rid of the double checking in the first place, but given that the problem exists since day one, I'm not sure if that kind of change would be even remotely acceptable.
Quoted 7 lines
If there is a good reason please factor out the checks and add
EXPORT_SYMBOL_GPLhelper for them that is well documented and can be used by gfs2.Quoted 1 line
+ if (
attr->ia_valid& (ATTR_MODE|ATTR_UID|ATTR_GID|ATTR_TIMES_SET)) {Line over 80 characters, please break up.
Andreas