Skip to content

Commit

Permalink
fs: return EPERM on immutable inode
Browse files Browse the repository at this point in the history
In most cases, EPERM is returned on immutable inode, and there're only a
few places returning EACCES. I noticed this when running LTP on
overlayfs, setxattr03 failed due to unexpected EACCES on immutable
inode.

So converting all EACCES to EPERM on immutable inode.

Acked-by: Dave Chinner <[email protected]>
Signed-off-by: Eryu Guan <[email protected]>
Signed-off-by: Al Viro <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
guaneryu authored and torvalds committed Aug 7, 2016
1 parent fe64f32 commit 337684a
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion fs/gfs2/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1800,7 +1800,7 @@ int gfs2_permission(struct inode *inode, int mask)
}

if ((mask & MAY_WRITE) && IS_IMMUTABLE(inode))
error = -EACCES;
error = -EPERM;
else
error = generic_permission(inode, mask);
if (gfs2_holder_initialized(&i_gh))
Expand Down
2 changes: 1 addition & 1 deletion fs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ int __inode_permission(struct inode *inode, int mask)
* Nobody gets write access to an immutable file.
*/
if (IS_IMMUTABLE(inode))
return -EACCES;
return -EPERM;

/*
* Updating mtime will likely cause i_uid and i_gid to be
Expand Down
3 changes: 2 additions & 1 deletion fs/utimes.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@ static int utimes_common(struct path *path, struct timespec *times)
* then we need to check permissions, because
* inode_change_ok() won't do it.
*/
error = -EACCES;
error = -EPERM;
if (IS_IMMUTABLE(inode))
goto mnt_drop_write_and_out;

error = -EACCES;
if (!inode_owner_or_capable(inode)) {
error = inode_permission(inode, MAY_WRITE);
if (error)
Expand Down
2 changes: 1 addition & 1 deletion fs/xfs/xfs_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ xfs_open_by_handle(
}

if ((fmode & FMODE_WRITE) && IS_IMMUTABLE(inode)) {
error = -EACCES;
error = -EPERM;
goto out_dput;
}

Expand Down

0 comments on commit 337684a

Please sign in to comment.