]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
smb/client: always return a value for FS_IOC_GETFLAGS
authorHuiwen He <hehuiwen@kylinos.cn>
Mon, 8 Jun 2026 15:57:29 +0000 (23:57 +0800)
committerSteve French <stfrench@microsoft.com>
Sun, 14 Jun 2026 20:12:23 +0000 (15:12 -0500)
Currently, repeated lsattr calls on a regular CIFS file without the
compressed attribute may show random flags:

$ touch test.bin
$ lsattr test.bin
s-S-ia-A-EjI---------m test.bin
$ lsattr test.bin
------d-cEjI---------m test.bin

The lsattr reproducer depends on the previous contents of its userspace
buffer, so it may not reproduce on every setup. A deterministic
reproducer is to initialize the ioctl argument before FS_IOC_GETFLAGS
on a file without the compressed attribute:

        int flags = 0x7fffffff;
        ioctl(fd, FS_IOC_GETFLAGS, &flags);

On an affected kernel, flags remains 0x7fffffff. With the fix, it is
set to 0.

This happens because when the cached inode does not have the compressed
bit set, the CIFS fallback path in FS_IOC_GETFLAGS returns success
without calling put_user() to write the zero flags value into the user
buffer. As a result, the caller observes stale contents from its own
buffer.

Fix this by always writing the visible flags value back to the user
buffer before returning success, even when the value is zero.

Fixes: 64a5cfa6db94 ("Allow setting per-file compression via SMB2/3")
Signed-off-by: Huiwen He <hehuiwen@kylinos.cn>
Reviewed-by: ChenXiaoSong <chenxiaosong@kylinos.cn>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/smb/client/ioctl.c

index 17408bb8ab65bf1727fbc944ede5d9e2c622d28c..746d70091f3d1d22223b90776e0cfb6d9ce32006 100644 (file)
@@ -392,13 +392,11 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)
                        }
 #endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
 #endif /* CONFIG_CIFS_POSIX */
-                       rc = 0;
-                       if (CIFS_I(inode)->cifsAttrs & ATTR_COMPRESSED) {
-                               /* add in the compressed bit */
-                               ExtAttrBits = FS_COMPR_FL;
-                               rc = put_user(ExtAttrBits & FS_FL_USER_VISIBLE,
-                                             (int __user *)arg);
-                       }
+                       if (CIFS_I(inode)->cifsAttrs & FILE_ATTRIBUTE_COMPRESSED)
+                               ExtAttrBits |= FS_COMPR_FL;
+
+                       rc = put_user(ExtAttrBits & FS_FL_USER_VISIBLE,
+                                     (int __user *)arg);
                        break;
                case FS_IOC_SETFLAGS:
                        if (pSMBFile == NULL)