xfs
[Top] [All Lists]

[PATCH 2/8] xfs: Fix open flag handling in open_by_handle code

To: xfs@xxxxxxxxxxx
Subject: [PATCH 2/8] xfs: Fix open flag handling in open_by_handle code
From: Dave Chinner <david@xxxxxxxxxxxxx>
Date: Fri, 2 Mar 2012 15:11:41 +1100
In-reply-to: <1330661507-1121-1-git-send-email-david@xxxxxxxxxxxxx>
References: <1330661507-1121-1-git-send-email-david@xxxxxxxxxxxxx>
From: Dave Chinner <dchinner@xxxxxxxxxx>

From: Dave Chinner <dchinner@xxxxxxxxxx>

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: Dave Chinner <dchinner@xxxxxxxxxx>
---
 fs/xfs/xfs_ioctl.c |   11 +++--------
 1 files changed, 3 insertions(+), 8 deletions(-)

diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
index 76f3ca5..86c86d8 100644
--- a/fs/xfs/xfs_ioctl.c
+++ b/fs/xfs/xfs_ioctl.c
@@ -230,24 +230,19 @@ xfs_open_by_handle(
 
        /* Put open permission in namei format. */
        permflag = hreq->oflags;
-       if ((permflag+1) & O_ACCMODE)
-               permflag++;
-       if (permflag & O_TRUNC)
-               permflag |= 2;
-
        if ((!(permflag & O_APPEND) || (permflag & O_TRUNC)) &&
-           (permflag & FMODE_WRITE) && IS_APPEND(inode)) {
+           (OPEN_FMODE(permflag) & FMODE_WRITE) && IS_APPEND(inode)) {
                error = -XFS_ERROR(EPERM);
                goto out_dput;
        }
 
-       if ((permflag & FMODE_WRITE) && IS_IMMUTABLE(inode)) {
+       if ((OPEN_FMODE(permflag) & FMODE_WRITE) && IS_IMMUTABLE(inode)) {
                error = -XFS_ERROR(EACCES);
                goto out_dput;
        }
 
        /* Can't write directories. */
-       if (S_ISDIR(inode->i_mode) && (permflag & FMODE_WRITE)) {
+       if (S_ISDIR(inode->i_mode) && (OPEN_FMODE(permflag) & FMODE_WRITE)) {
                error = -XFS_ERROR(EISDIR);
                goto out_dput;
        }
-- 
1.7.9

<Prev in Thread] Current Thread [Next in Thread>