when creating new inodes, use file_mode/dir_mode exclusively on mount without unix extensions

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Linux Kernel Mailing List
Date: Wednesday, June 11, 2008 - 6:04 pm

Gitweb:     http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=b0fd30...
Commit:     b0fd30d3e7e768aad5e398caaea6ae5a5c814eab
Parent:     4468eb3fd102cad559e51594a01cbc65b994d264
Author:     Jeff Layton <jlayton@redhat.com>
AuthorDate: Thu May 22 09:33:34 2008 -0400
Committer:  Steve French <sfrench@us.ibm.com>
CommitDate: Fri May 23 18:17:16 2008 +0000

    when creating new inodes, use file_mode/dir_mode exclusively on mount without unix extensions
    
    When CIFS creates a new inode on a mount without unix extensions, it
    temporarily assigns the mode that was passed to it in the create/mkdir
    call. Eventually, when the inode is revalidated, it changes to have the
    file_mode or dir_mode for the mount. This is confusing to users who
    expect that the mode shouldn't change this way. It's also problematic
    since only the mode is treated this way, not the uid or gid. Suppose you
    have a CIFS mount that's mounted with:
    
    uid=0,gid=0,file_mode=0666,dir_mode=0777
    
    ...if an unprivileged user comes along and does this on the mount:
    
    mkdir -m 0700 foo
    touch foo/bar
    
    ...there is a period of time where the touch will fail, since the dir
    will initially be owned by root and have mode 0700. If the user waits
    long enough, then "foo" will be revalidated and will get the correct
    dir_mode permissions.
    
    This patch changes cifs_mkdir and cifs_create to not overwrite the
    mode found by the initial cifs_get_inode_info call after the inode is
    created on the server. Legacy behavior can be reenabled with the
    new "dynperm" mount option.
    
    Signed-off-by: Jeff Layton <jlayton@redhat.com>
    Signed-off-by: Steve French <sfrench@us.ibm.com>
---
 fs/cifs/dir.c   |    4 +++-
 fs/cifs/inode.c |    7 +++++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c
index f0b5b5f..fb69c1f 100644
--- a/fs/cifs/dir.c
+++ b/fs/cifs/dir.c
@@ -260,7 +260,9 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode,
 						 buf, inode->i_sb, xid,
 						 &fileHandle);
 			if (newinode) {
-				newinode->i_mode = mode;
+				if (cifs_sb->mnt_cifs_flags &
+				    CIFS_MOUNT_DYNPERM)
+					newinode->i_mode = mode;
 				if ((oplock & CIFS_CREATE_ACTION) &&
 				    (cifs_sb->mnt_cifs_flags &
 				     CIFS_MOUNT_SET_UID)) {
diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c
index ae5bcaf..12667d6 100644
--- a/fs/cifs/inode.c
+++ b/fs/cifs/inode.c
@@ -1015,8 +1015,11 @@ mkdir_get_info:
 						CIFS_MOUNT_MAP_SPECIAL_CHR);
 			}
 			if (direntry->d_inode) {
-				direntry->d_inode->i_mode = mode;
-				direntry->d_inode->i_mode |= S_IFDIR;
+				if (cifs_sb->mnt_cifs_flags &
+				     CIFS_MOUNT_DYNPERM)
+					direntry->d_inode->i_mode =
+						(mode | S_IFDIR);
+					
 				if (cifs_sb->mnt_cifs_flags &
 				     CIFS_MOUNT_SET_UID) {
 					direntry->d_inode->i_uid =
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
when creating new inodes, use file_mode/dir_mode exclusive ..., Linux Kernel Mailing ..., (Wed Jun 11, 6:04 pm)