Commit 9c02404b authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'v6.12-rc1-ksmbd-fixes' of git://git.samba.org/ksmbd

Pull smb server fixes from Steve French:

 - small cleanup patches leveraging struct size to improve access bounds checking

* tag 'v6.12-rc1-ksmbd-fixes' of git://git.samba.org/ksmbd:
  ksmbd: Use struct_size() to improve smb_direct_rdma_xmit()
  ksmbd: Annotate struct copychunk_ioctl_req with __counted_by_le()
  ksmbd: Use struct_size() to improve get_file_alternate_info()
parents 20c2474f 9c383396
...@@ -4883,7 +4883,7 @@ static void get_file_alternate_info(struct ksmbd_work *work, ...@@ -4883,7 +4883,7 @@ static void get_file_alternate_info(struct ksmbd_work *work,
spin_unlock(&dentry->d_lock); spin_unlock(&dentry->d_lock);
file_info->FileNameLength = cpu_to_le32(conv_len); file_info->FileNameLength = cpu_to_le32(conv_len);
rsp->OutputBufferLength = rsp->OutputBufferLength =
cpu_to_le32(sizeof(struct smb2_file_alt_name_info) + conv_len); cpu_to_le32(struct_size(file_info, FileName, conv_len));
} }
static int get_file_stream_info(struct ksmbd_work *work, static int get_file_stream_info(struct ksmbd_work *work,
...@@ -7562,7 +7562,6 @@ static int fsctl_copychunk(struct ksmbd_work *work, ...@@ -7562,7 +7562,6 @@ static int fsctl_copychunk(struct ksmbd_work *work,
ci_rsp->TotalBytesWritten = ci_rsp->TotalBytesWritten =
cpu_to_le32(ksmbd_server_side_copy_max_total_size()); cpu_to_le32(ksmbd_server_side_copy_max_total_size());
chunks = (struct srv_copychunk *)&ci_req->Chunks[0];
chunk_count = le32_to_cpu(ci_req->ChunkCount); chunk_count = le32_to_cpu(ci_req->ChunkCount);
if (chunk_count == 0) if (chunk_count == 0)
goto out; goto out;
...@@ -7570,12 +7569,12 @@ static int fsctl_copychunk(struct ksmbd_work *work, ...@@ -7570,12 +7569,12 @@ static int fsctl_copychunk(struct ksmbd_work *work,
/* verify the SRV_COPYCHUNK_COPY packet */ /* verify the SRV_COPYCHUNK_COPY packet */
if (chunk_count > ksmbd_server_side_copy_max_chunk_count() || if (chunk_count > ksmbd_server_side_copy_max_chunk_count() ||
input_count < offsetof(struct copychunk_ioctl_req, Chunks) + input_count < struct_size(ci_req, Chunks, chunk_count)) {
chunk_count * sizeof(struct srv_copychunk)) {
rsp->hdr.Status = STATUS_INVALID_PARAMETER; rsp->hdr.Status = STATUS_INVALID_PARAMETER;
return -EINVAL; return -EINVAL;
} }
chunks = &ci_req->Chunks[0];
for (i = 0; i < chunk_count; i++) { for (i = 0; i < chunk_count; i++) {
if (le32_to_cpu(chunks[i].Length) == 0 || if (le32_to_cpu(chunks[i].Length) == 0 ||
le32_to_cpu(chunks[i].Length) > ksmbd_server_side_copy_max_chunk_size()) le32_to_cpu(chunks[i].Length) > ksmbd_server_side_copy_max_chunk_size())
......
...@@ -190,13 +190,6 @@ struct resume_key_ioctl_rsp { ...@@ -190,13 +190,6 @@ struct resume_key_ioctl_rsp {
__u8 Context[4]; /* ignored, Windows sets to 4 bytes of zero */ __u8 Context[4]; /* ignored, Windows sets to 4 bytes of zero */
} __packed; } __packed;
struct copychunk_ioctl_req {
__le64 ResumeKey[3];
__le32 ChunkCount;
__le32 Reserved;
__u8 Chunks[]; /* array of srv_copychunk */
} __packed;
struct srv_copychunk { struct srv_copychunk {
__le64 SourceOffset; __le64 SourceOffset;
__le64 TargetOffset; __le64 TargetOffset;
...@@ -204,6 +197,13 @@ struct srv_copychunk { ...@@ -204,6 +197,13 @@ struct srv_copychunk {
__le32 Reserved; __le32 Reserved;
} __packed; } __packed;
struct copychunk_ioctl_req {
__le64 ResumeKey[3];
__le32 ChunkCount;
__le32 Reserved;
struct srv_copychunk Chunks[] __counted_by_le(ChunkCount);
} __packed;
struct copychunk_ioctl_rsp { struct copychunk_ioctl_rsp {
__le32 ChunksWritten; __le32 ChunksWritten;
__le32 ChunkBytesWritten; __le32 ChunkBytesWritten;
......
...@@ -1405,8 +1405,8 @@ static int smb_direct_rdma_xmit(struct smb_direct_transport *t, ...@@ -1405,8 +1405,8 @@ static int smb_direct_rdma_xmit(struct smb_direct_transport *t,
/* build rdma_rw_ctx for each descriptor */ /* build rdma_rw_ctx for each descriptor */
desc_buf = buf; desc_buf = buf;
for (i = 0; i < desc_num; i++) { for (i = 0; i < desc_num; i++) {
msg = kzalloc(offsetof(struct smb_direct_rdma_rw_msg, sg_list) + msg = kzalloc(struct_size(msg, sg_list, SG_CHUNK_SIZE),
sizeof(struct scatterlist) * SG_CHUNK_SIZE, GFP_KERNEL); GFP_KERNEL);
if (!msg) { if (!msg) {
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment