Skip to content

Commit

Permalink
Use access mode instead of open flags to determine needed permissions
Browse files Browse the repository at this point in the history
Way back when (in commit 834f2a4, aka
"VFS: Allow the filesystem to return a full file pointer on open intent"
to be exact), Trond changed the open logic to keep track of the original
flags to a file open, in order to pass down the the intent of a dentry
lookup to the low-level filesystem.

However, when doing that reorganization, it changed the meaning of
namei_flags, and thus inadvertently changed the test of access mode for
directories (and RO filesystem) to use the wrong flag.  So fix those
test back to use access mode ("acc_mode") rather than the open flag
("flag").

Issue noticed by Bill Roman at Datalight.

Reported-and-tested-by: Bill Roman <bill.roman@datalight.com>
Acked-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Acked-by: Al Viro <viro@ZenIV.linux.org.uk>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Linus Torvalds committed Jan 12, 2008
1 parent d0c4c9d commit 974a9f0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions fs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -1605,7 +1605,7 @@ int may_open(struct nameidata *nd, int acc_mode, int flag)
if (S_ISLNK(inode->i_mode))
return -ELOOP;

if (S_ISDIR(inode->i_mode) && (flag & FMODE_WRITE))
if (S_ISDIR(inode->i_mode) && (acc_mode & MAY_WRITE))
return -EISDIR;

/*
Expand All @@ -1620,7 +1620,7 @@ int may_open(struct nameidata *nd, int acc_mode, int flag)
return -EACCES;

flag &= ~O_TRUNC;
} else if (IS_RDONLY(inode) && (flag & FMODE_WRITE))
} else if (IS_RDONLY(inode) && (acc_mode & MAY_WRITE))
return -EROFS;

error = vfs_permission(nd, acc_mode);
Expand Down

0 comments on commit 974a9f0

Please sign in to comment.