[linux-cifs-client] [PATCH 4/7] [CIFS] disable most mode changes on non-unix/non-cifsacl mounts

Jeff Layton jlayton at redhat.com
Mon May 5 19:16:25 GMT 2008

CIFS currently allows you to change the mode of an inode on a share that
doesn't have unix extensions enabled, and isn't using cifsacl. The inode
in this case *only* has its mode changed in memory on the client. This
is problematic since it can change any time the inode is purged from the

This patch makes cifs_setattr silently ignore most mode changes when
unix extensions and cifsacl support are not enabled. The exception to

When a mode change would remove all write access to an inode we turn on
the ATTR_READONLY bit on the server and remove all write bits from the
inode's mode in memory.

When a mode change would add a write bit to an inode that previously had
them all turned off, it turns off the ATTR_READONLY bit on the server,
and resets the mode back to what it would normally be (generally, the
file_mode or dir_mode of the share).

Signed-off-by: Jeff Layton <jlayton at redhat.com>
 fs/cifs/inode.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c
index 5a2a503..b42f68e 100644
--- a/fs/cifs/inode.c
+++ b/fs/cifs/inode.c
@@ -1578,6 +1578,7 @@ int cifs_setattr(struct dentry *direntry, struct iattr *attrs)
 				time_buf.Attributes =
 					cpu_to_le32(cifsInode->cifsAttrs |
+				attrs->ia_mode = inode->i_mode & ~S_IWUGO;
 		} else if (cifsInode->cifsAttrs & ATTR_READONLY) {
 			/* If file is readonly on server, we would
@@ -1590,6 +1591,16 @@ int cifs_setattr(struct dentry *direntry, struct iattr *attrs)
 			/* Windows ignores set to zero */
 			if (time_buf.Attributes == 0)
 				time_buf.Attributes |= cpu_to_le32(ATTR_NORMAL);
+			/* reset local inode permissions to normal */
+			attrs->ia_mode &= ~(S_IALLUGO);
+			if (S_ISDIR(inode->i_mode))
+				attrs->ia_mode |= cifs_sb->mnt_dir_mode;
+			else
+				attrs->ia_mode |= cifs_sb->mnt_file_mode;
+		} else {
+			/* ignore mode change - ATTR_READONLY hasn't changed */
+			attrs->ia_valid &= ~ATTR_MODE;

More information about the linux-cifs-client mailing list