]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ksmbd: fix wrong allocation size update in smb2_open()
authorNamjae Jeon <linkinjeon@kernel.org>
Wed, 27 Dec 2023 10:26:05 +0000 (19:26 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 5 Jan 2024 14:13:37 +0000 (15:13 +0100)
[ Upstream commit a9f106c765c12d2f58aa33431bd8ce8e9d8a404a ]

When client send SMB2_CREATE_ALLOCATION_SIZE create context, ksmbd update
old size to ->AllocationSize in smb2 create response. ksmbd_vfs_getattr()
should be called after it to get updated stat result.

Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/ksmbd/smb2pdu.c

index e1c640ed7acc31452af6ccad5453901f3211a058..8875c04e83827e4d62e997bc2bccc8d30b603d43 100644 (file)
@@ -2516,7 +2516,7 @@ static void smb2_new_xattrs(struct ksmbd_tree_connect *tcon, const struct path *
        da.flags = XATTR_DOSINFO_ATTRIB | XATTR_DOSINFO_CREATE_TIME |
                XATTR_DOSINFO_ITIME;
 
-       rc = ksmbd_vfs_set_dos_attrib_xattr(mnt_user_ns(path->mnt), path, &da, false);
+       rc = ksmbd_vfs_set_dos_attrib_xattr(mnt_user_ns(path->mnt), path, &da, true);
        if (rc)
                ksmbd_debug(SMB, "failed to store file attribute into xattr\n");
 }
@@ -3182,23 +3182,6 @@ int smb2_open(struct ksmbd_work *work)
                goto err_out;
        }
 
-       rc = ksmbd_vfs_getattr(&path, &stat);
-       if (rc)
-               goto err_out;
-
-       if (stat.result_mask & STATX_BTIME)
-               fp->create_time = ksmbd_UnixTimeToNT(stat.btime);
-       else
-               fp->create_time = ksmbd_UnixTimeToNT(stat.ctime);
-       if (req->FileAttributes || fp->f_ci->m_fattr == 0)
-               fp->f_ci->m_fattr =
-                       cpu_to_le32(smb2_get_dos_mode(&stat, le32_to_cpu(req->FileAttributes)));
-
-       if (!created)
-               smb2_update_xattrs(tcon, &path, fp);
-       else
-               smb2_new_xattrs(tcon, &path, fp);
-
        if (file_present || created)
                ksmbd_vfs_kern_path_unlock(&parent_path, &path);
 
@@ -3299,6 +3282,23 @@ int smb2_open(struct ksmbd_work *work)
                }
        }
 
+       rc = ksmbd_vfs_getattr(&path, &stat);
+       if (rc)
+               goto err_out1;
+
+       if (stat.result_mask & STATX_BTIME)
+               fp->create_time = ksmbd_UnixTimeToNT(stat.btime);
+       else
+               fp->create_time = ksmbd_UnixTimeToNT(stat.ctime);
+       if (req->FileAttributes || fp->f_ci->m_fattr == 0)
+               fp->f_ci->m_fattr =
+                       cpu_to_le32(smb2_get_dos_mode(&stat, le32_to_cpu(req->FileAttributes)));
+
+       if (!created)
+               smb2_update_xattrs(tcon, &path, fp);
+       else
+               smb2_new_xattrs(tcon, &path, fp);
+
        memcpy(fp->client_guid, conn->ClientGUID, SMB2_CLIENT_GUID_SIZE);
 
        rsp->StructureSize = cpu_to_le16(89);