提交 974a9f0b 编写于 作者: L Linus Torvalds

Use access mode instead of open flags to determine needed permissions

Way back when (in commit 834f2a4a, 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: NBill Roman <bill.roman@datalight.com>
Acked-by: NTrond Myklebust <Trond.Myklebust@netapp.com>
Acked-by: NAl Viro <viro@ZenIV.linux.org.uk>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 d0c4c9d4
...@@ -1605,7 +1605,7 @@ int may_open(struct nameidata *nd, int acc_mode, int flag) ...@@ -1605,7 +1605,7 @@ int may_open(struct nameidata *nd, int acc_mode, int flag)
if (S_ISLNK(inode->i_mode)) if (S_ISLNK(inode->i_mode))
return -ELOOP; return -ELOOP;
if (S_ISDIR(inode->i_mode) && (flag & FMODE_WRITE)) if (S_ISDIR(inode->i_mode) && (acc_mode & MAY_WRITE))
return -EISDIR; return -EISDIR;
/* /*
...@@ -1620,7 +1620,7 @@ int may_open(struct nameidata *nd, int acc_mode, int flag) ...@@ -1620,7 +1620,7 @@ int may_open(struct nameidata *nd, int acc_mode, int flag)
return -EACCES; return -EACCES;
flag &= ~O_TRUNC; flag &= ~O_TRUNC;
} else if (IS_RDONLY(inode) && (flag & FMODE_WRITE)) } else if (IS_RDONLY(inode) && (acc_mode & MAY_WRITE))
return -EROFS; return -EROFS;
error = vfs_permission(nd, acc_mode); error = vfs_permission(nd, acc_mode);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册