Skip to content

Commit

Permalink
ksmbd: fix wrong allocation size update in smb2_open()
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
namjaejeon committed Dec 22, 2023
1 parent 9141a3a commit 0590dfa
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions smb2pdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -2571,7 +2571,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 = compat_ksmbd_vfs_set_dos_attrib_xattr(path, &da, false);
rc = compat_ksmbd_vfs_set_dos_attrib_xattr(path, &da, true);
if (rc)
ksmbd_debug(SMB, "failed to store file attribute into xattr\n");
}
Expand Down Expand Up @@ -3361,23 +3361,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 LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0)
if (file_present || created)
ksmbd_vfs_kern_path_unlock(&parent_path, &path);
Expand Down Expand Up @@ -3483,6 +3466,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);
Expand Down

0 comments on commit 0590dfa

Please sign in to comment.