Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit 3374f06

Browse files
Steve Frenchgregkh
Steve French
authored andcommittedOct 10, 2024
smb3: fix incorrect mode displayed for read-only files
commit 2f3017e upstream. Commands like "chmod 0444" mark a file readonly via the attribute flag (when mapping of mode bits into the ACL are not set, or POSIX extensions are not negotiated), but they were not reported correctly for stat of directories (they were reported ok for files and for "ls"). See example below: root:~# ls /mnt2 -l total 12 drwxr-xr-x 2 root root 0 Sep 21 18:03 normaldir -rwxr-xr-x 1 root root 0 Sep 21 23:24 normalfile dr-xr-xr-x 2 root root 0 Sep 21 17:55 readonly-dir -r-xr-xr-x 1 root root 209716224 Sep 21 18:15 readonly-file root:~# stat -c %a /mnt2/readonly-dir 755 root:~# stat -c %a /mnt2/readonly-file 555 This fixes the stat of directories when ATTR_READONLY is set (in cases where the mode can not be obtained other ways). root:~# stat -c %a /mnt2/readonly-dir 555 Cc: stable@vger.kernel.org Signed-off-by: Steve French <stfrench@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4729732 commit 3374f06

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed
 

‎fs/smb/client/inode.c

+11-8
Original file line numberDiff line numberDiff line change
@@ -779,10 +779,6 @@ static void cifs_open_info_to_fattr(struct cifs_fattr *fattr,
779779
fattr->cf_mode = S_IFREG | cifs_sb->ctx->file_mode;
780780
fattr->cf_dtype = DT_REG;
781781

782-
/* clear write bits if ATTR_READONLY is set */
783-
if (fattr->cf_cifsattrs & ATTR_READONLY)
784-
fattr->cf_mode &= ~(S_IWUGO);
785-
786782
/*
787783
* Don't accept zero nlink from non-unix servers unless
788784
* delete is pending. Instead mark it as unknown.
@@ -795,6 +791,10 @@ static void cifs_open_info_to_fattr(struct cifs_fattr *fattr,
795791
}
796792
}
797793

794+
/* clear write bits if ATTR_READONLY is set */
795+
if (fattr->cf_cifsattrs & ATTR_READONLY)
796+
fattr->cf_mode &= ~(S_IWUGO);
797+
798798
out_reparse:
799799
if (S_ISLNK(fattr->cf_mode)) {
800800
if (likely(data->symlink_target))
@@ -1212,11 +1212,14 @@ static int cifs_get_fattr(struct cifs_open_info_data *data,
12121212
__func__, rc);
12131213
goto out;
12141214
}
1215-
}
1216-
1217-
/* fill in remaining high mode bits e.g. SUID, VTX */
1218-
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL)
1215+
} else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL)
1216+
/* fill in remaining high mode bits e.g. SUID, VTX */
12191217
cifs_sfu_mode(fattr, full_path, cifs_sb, xid);
1218+
else if (!(tcon->posix_extensions))
1219+
/* clear write bits if ATTR_READONLY is set */
1220+
if (fattr->cf_cifsattrs & ATTR_READONLY)
1221+
fattr->cf_mode &= ~(S_IWUGO);
1222+
12201223

12211224
/* check for Minshall+French symlinks */
12221225
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS) {

0 commit comments

Comments
 (0)