Skip to contentSkip to conversation

hfs: return -EPERM for unsupported setattr changes

PATCH In review Davy Felipe 2 participants 2 messages Sep 16 – Sep 17

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hfs: return -EPERM for unsupported setattr changes

hfs_inode_setattr() rejects unsupported UID, GID and mode changes, but returns the value stored in error when the filesystem is not mounted with the quiet option.

At this point error is zero, as execution has already passed a successful setattr_prepare() call. As a result, unsupported attribute changes are incorrectly reported to userspace as successful even though the inode remains unchanged.

Return -EPERM for these operations while preserving the existing behavior for quiet mounts.

A chown test on an HFS image reproduces the problem. Without the fix, chown 1234:1234 returns success while ownership remains 0:0. With the fix, the same operation fails with EPERM and ownership remains unchanged.

---
 fs/hfs/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/hfs/inode.c +1 -1
index 2aef3c36a150..cce3a7bb95e9 100644
@@ -663,7 +663,7 @@ int hfs_inode_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
 	     ((S_ISDIR(inode->i_mode) &&
 	       (attr->ia_mode != inode->i_mode)) ||
 	      (attr->ia_mode & ~HFS_VALID_MODE_BITS)))) {
-		return hsb->s_quiet ? 0 : error;
+		return hsb->s_quiet ? 0 : -EPERM;
 	}
 
 	/* map file permissions to the closest allowable permissions in HFS */
Signature · 1 line
2.55.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 33 lines · Davy Felipe

hfs_inode_setattr() rejects unsupported UID, GID and mode changes, but returns the value stored in error when the filesystem is not mounted with the quiet option.

At this point error is zero, as execution has already passed a successful setattr_prepare() call. As a result, unsupported attribute changes are incorrectly reported to userspace as successful even though the inode remains unchanged.

Return -EPERM for these operations while preserving the existing behavior for quiet mounts.

A chown test on an HFS image reproduces the problem. Without the fix, chown 1234:1234 returns success while ownership remains 0:0. With the fix, the same operation fails with EPERM and ownership remains unchanged.

---
 fs/hfs/inode.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
fs/hfs/inode.c +0 -0
index 2aef3c36a150..cce3a7bb95e9 100644
@@ -663,7 +663,7 @@ int hfs_inode_setattr(struct mnt_idmap *idmap,
 struct dentry *dentry,

       ((S_ISDIR(inode->i_mode) && (attr->ia_mode != inode->i_mode)) || (attr->ia_mode & ~HFS_VALID_MODE_BITS)))) {

fs/hfs/inode.c +1 -1
-		return hsb->s_quiet ? 0 : error;
+		return hsb->s_quiet ? 0 : -EPERM;
Quoted 4 lines

  }

  /* map file permissions to the closest allowable permissions in HFS */

Looks good.

Thanks,
Slava.