Commit 1a1d7724 authored by Dave Chinner's avatar Dave Chinner Committed by Ben Myers

xfs: Fix open flag handling in open_by_handle code

Sparse identified some unsafe handling of open flags in the xfs open
by handle ioctl code. Update the code to use the correct access
macros to ensure that we handle the open flags correctly.
Signed-off-by: default avatarDave Chinner <dchinner@redhat.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarMark Tinguely <tinguely@sgi.com>
Signed-off-by: default avatarBen Myers <bpm@sgi.com>
parent 5575acc7
...@@ -209,6 +209,7 @@ xfs_open_by_handle( ...@@ -209,6 +209,7 @@ xfs_open_by_handle(
struct file *filp; struct file *filp;
struct inode *inode; struct inode *inode;
struct dentry *dentry; struct dentry *dentry;
fmode_t fmode;
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return -XFS_ERROR(EPERM); return -XFS_ERROR(EPERM);
...@@ -228,26 +229,21 @@ xfs_open_by_handle( ...@@ -228,26 +229,21 @@ xfs_open_by_handle(
hreq->oflags |= O_LARGEFILE; hreq->oflags |= O_LARGEFILE;
#endif #endif
/* Put open permission in namei format. */
permflag = hreq->oflags; permflag = hreq->oflags;
if ((permflag+1) & O_ACCMODE) fmode = OPEN_FMODE(permflag);
permflag++;
if (permflag & O_TRUNC)
permflag |= 2;
if ((!(permflag & O_APPEND) || (permflag & O_TRUNC)) && if ((!(permflag & O_APPEND) || (permflag & O_TRUNC)) &&
(permflag & FMODE_WRITE) && IS_APPEND(inode)) { (fmode & FMODE_WRITE) && IS_APPEND(inode)) {
error = -XFS_ERROR(EPERM); error = -XFS_ERROR(EPERM);
goto out_dput; goto out_dput;
} }
if ((permflag & FMODE_WRITE) && IS_IMMUTABLE(inode)) { if ((fmode & FMODE_WRITE) && IS_IMMUTABLE(inode)) {
error = -XFS_ERROR(EACCES); error = -XFS_ERROR(EACCES);
goto out_dput; goto out_dput;
} }
/* Can't write directories. */ /* Can't write directories. */
if (S_ISDIR(inode->i_mode) && (permflag & FMODE_WRITE)) { if (S_ISDIR(inode->i_mode) && (fmode & FMODE_WRITE)) {
error = -XFS_ERROR(EISDIR); error = -XFS_ERROR(EISDIR);
goto out_dput; goto out_dput;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment