Skip to content

Commit 0801c13

Browse files
tobluxSteve French
authored andcommitted
ksmbd: Annotate struct copychunk_ioctl_req with __counted_by_le()
Add the __counted_by_le compiler attribute to the flexible array member Chunks to improve access bounds-checking via CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE. Change the data type of the flexible array member Chunks from __u8[] to struct srv_copychunk[] for ChunkCount to match the number of elements in the Chunks array. (With __u8[], each srv_copychunk would occupy 24 array entries and the __counted_by compiler attribute wouldn't be applicable.) Use struct_size() to calculate the size of the copychunk_ioctl_req. Read Chunks[0] after checking that ChunkCount is not 0. Signed-off-by: Thorsten Blum <[email protected]> Acked-by: Namjae Jeon <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 04afb0a commit 0801c13

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

fs/smb/server/smb2pdu.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

0 commit comments

Comments
 (0)