Skip to content

Commit 9c02404

Browse files
committed
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()
2 parents 20c2474 + 9c38339 commit 9c02404

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

fs/smb/server/smb2pdu.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4883,7 +4883,7 @@ static void get_file_alternate_info(struct ksmbd_work *work,
48834883
spin_unlock(&dentry->d_lock);
48844884
file_info->FileNameLength = cpu_to_le32(conv_len);
48854885
rsp->OutputBufferLength =
4886-
cpu_to_le32(sizeof(struct smb2_file_alt_name_info) + conv_len);
4886+
cpu_to_le32(struct_size(file_info, FileName, conv_len));
48874887
}
48884888

48894889
static int get_file_stream_info(struct ksmbd_work *work,
@@ -7562,20 +7562,19 @@ static int fsctl_copychunk(struct ksmbd_work *work,
75627562
ci_rsp->TotalBytesWritten =
75637563
cpu_to_le32(ksmbd_server_side_copy_max_total_size());
75647564

7565-
chunks = (struct srv_copychunk *)&ci_req->Chunks[0];
75667565
chunk_count = le32_to_cpu(ci_req->ChunkCount);
75677566
if (chunk_count == 0)
75687567
goto out;
75697568
total_size_written = 0;
75707569

75717570
/* verify the SRV_COPYCHUNK_COPY packet */
75727571
if (chunk_count > ksmbd_server_side_copy_max_chunk_count() ||
7573-
input_count < offsetof(struct copychunk_ioctl_req, Chunks) +
7574-
chunk_count * sizeof(struct srv_copychunk)) {
7572+
input_count < struct_size(ci_req, Chunks, chunk_count)) {
75757573
rsp->hdr.Status = STATUS_INVALID_PARAMETER;
75767574
return -EINVAL;
75777575
}
75787576

7577+
chunks = &ci_req->Chunks[0];
75797578
for (i = 0; i < chunk_count; i++) {
75807579
if (le32_to_cpu(chunks[i].Length) == 0 ||
75817580
le32_to_cpu(chunks[i].Length) > ksmbd_server_side_copy_max_chunk_size())

fs/smb/server/smb2pdu.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,20 +190,20 @@ struct resume_key_ioctl_rsp {
190190
__u8 Context[4]; /* ignored, Windows sets to 4 bytes of zero */
191191
} __packed;
192192

193-
struct copychunk_ioctl_req {
194-
__le64 ResumeKey[3];
195-
__le32 ChunkCount;
196-
__le32 Reserved;
197-
__u8 Chunks[]; /* array of srv_copychunk */
198-
} __packed;
199-
200193
struct srv_copychunk {
201194
__le64 SourceOffset;
202195
__le64 TargetOffset;
203196
__le32 Length;
204197
__le32 Reserved;
205198
} __packed;
206199

200+
struct copychunk_ioctl_req {
201+
__le64 ResumeKey[3];
202+
__le32 ChunkCount;
203+
__le32 Reserved;
204+
struct srv_copychunk Chunks[] __counted_by_le(ChunkCount);
205+
} __packed;
206+
207207
struct copychunk_ioctl_rsp {
208208
__le32 ChunksWritten;
209209
__le32 ChunkBytesWritten;

fs/smb/server/transport_rdma.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,8 +1405,8 @@ static int smb_direct_rdma_xmit(struct smb_direct_transport *t,
14051405
/* build rdma_rw_ctx for each descriptor */
14061406
desc_buf = buf;
14071407
for (i = 0; i < desc_num; i++) {
1408-
msg = kzalloc(offsetof(struct smb_direct_rdma_rw_msg, sg_list) +
1409-
sizeof(struct scatterlist) * SG_CHUNK_SIZE, GFP_KERNEL);
1408+
msg = kzalloc(struct_size(msg, sg_list, SG_CHUNK_SIZE),
1409+
GFP_KERNEL);
14101410
if (!msg) {
14111411
ret = -ENOMEM;
14121412
goto out;

0 commit comments

Comments
 (0)