]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
cifs: Remove intermediate object of failed create SFU call
authorPali Rohár <pali@kernel.org>
Wed, 25 Dec 2024 13:00:39 +0000 (14:00 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 17 Feb 2025 09:05:03 +0000 (10:05 +0100)
commit 25f6184e24b3991eae977a29ecf27d537cc930b2 upstream.

Check if the server honored ATTR_SYSTEM flag by CREATE_OPTION_SPECIAL
option. If not then server does not support ATTR_SYSTEM and newly
created file is not SFU compatible, which means that the call failed.

If CREATE was successful but either setting ATTR_SYSTEM failed or
writing type/data information failed then remove the intermediate
object created by CREATE. Otherwise intermediate empty object stay
on the server.

This ensures that if the creating of SFU files with system attribute is
unsupported by the server then no empty file stay on the server as a result
of unsupported operation.

This is for example case with Samba server and Linux tmpfs storage without
enabled xattr support (where Samba stores ATTR_SYSTEM bit).

Cc: stable@vger.kernel.org
Signed-off-by: Pali Rohár <pali@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/smb/client/smb2ops.c

index 6bacf754b57efd5c8f91f259ec1159a285ebe412..cf68a093fd103303bb9ef52d4ae00f1ae5b7d9ec 100644 (file)
@@ -5104,6 +5104,7 @@ int __cifs_sfu_make_node(unsigned int xid, struct inode *inode,
 {
        struct TCP_Server_Info *server = tcon->ses->server;
        struct cifs_open_parms oparms;
+       struct cifs_open_info_data idata;
        struct cifs_io_parms io_parms = {};
        struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
        struct cifs_fid fid;
@@ -5173,10 +5174,20 @@ int __cifs_sfu_make_node(unsigned int xid, struct inode *inode,
                             CREATE_OPTION_SPECIAL, ACL_NO_MODE);
        oparms.fid = &fid;
 
-       rc = server->ops->open(xid, &oparms, &oplock, NULL);
+       rc = server->ops->open(xid, &oparms, &oplock, &idata);
        if (rc)
                goto out;
 
+       /*
+        * Check if the server honored ATTR_SYSTEM flag by CREATE_OPTION_SPECIAL
+        * option. If not then server does not support ATTR_SYSTEM and newly
+        * created file is not SFU compatible, which means that the call failed.
+        */
+       if (!(le32_to_cpu(idata.fi.Attributes) & ATTR_SYSTEM)) {
+               rc = -EOPNOTSUPP;
+               goto out_close;
+       }
+
        if (type_len + data_len > 0) {
                io_parms.pid = current->tgid;
                io_parms.tcon = tcon;
@@ -5191,8 +5202,18 @@ int __cifs_sfu_make_node(unsigned int xid, struct inode *inode,
                                             iov, ARRAY_SIZE(iov)-1);
        }
 
+out_close:
        server->ops->close(xid, tcon, &fid);
 
+       /*
+        * If CREATE was successful but either setting ATTR_SYSTEM failed or
+        * writing type/data information failed then remove the intermediate
+        * object created by CREATE. Otherwise intermediate empty object stay
+        * on the server.
+        */
+       if (rc)
+               server->ops->unlink(xid, tcon, full_path, cifs_sb, NULL);
+
 out:
        kfree(symname_utf16);
        return rc;