]> Git Repo - linux.git/commitdiff
ksmbd: Annotate struct copychunk_ioctl_req with __counted_by_le()
authorThorsten Blum <[email protected]>
Wed, 25 Sep 2024 09:03:13 +0000 (11:03 +0200)
committerSteve French <[email protected]>
Tue, 1 Oct 2024 19:50:51 +0000 (14:50 -0500)
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]>
fs/smb/server/smb2pdu.c
fs/smb/server/smb2pdu.h

index f28346fad89402caa75a8cfa326e621b008b9e85..797b0f24097be84615a27bf4af62b17290519064 100644 (file)
@@ -7562,7 +7562,6 @@ static int fsctl_copychunk(struct ksmbd_work *work,
        ci_rsp->TotalBytesWritten =
                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);
        if (chunk_count == 0)
                goto out;
@@ -7570,12 +7569,12 @@ static int fsctl_copychunk(struct ksmbd_work *work,
 
        /* verify the SRV_COPYCHUNK_COPY packet */
        if (chunk_count > ksmbd_server_side_copy_max_chunk_count() ||
-           input_count < offsetof(struct copychunk_ioctl_req, Chunks) +
-            chunk_count * sizeof(struct srv_copychunk)) {
+           input_count < struct_size(ci_req, Chunks, chunk_count)) {
                rsp->hdr.Status = STATUS_INVALID_PARAMETER;
                return -EINVAL;
        }
 
+       chunks = &ci_req->Chunks[0];
        for (i = 0; i < chunk_count; i++) {
                if (le32_to_cpu(chunks[i].Length) == 0 ||
                    le32_to_cpu(chunks[i].Length) > ksmbd_server_side_copy_max_chunk_size())
index 73aff20e22d014ff129efda0f28ba53b0da87502..649dacf7e8c4935b62216ba58ee6810bda0ac3b1 100644 (file)
@@ -190,13 +190,6 @@ struct resume_key_ioctl_rsp {
        __u8 Context[4]; /* ignored, Windows sets to 4 bytes of zero */
 } __packed;
 
-struct copychunk_ioctl_req {
-       __le64 ResumeKey[3];
-       __le32 ChunkCount;
-       __le32 Reserved;
-       __u8 Chunks[]; /* array of srv_copychunk */
-} __packed;
-
 struct srv_copychunk {
        __le64 SourceOffset;
        __le64 TargetOffset;
@@ -204,6 +197,13 @@ struct srv_copychunk {
        __le32 Reserved;
 } __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 {
        __le32 ChunksWritten;
        __le32 ChunkBytesWritten;
This page took 0.055263 seconds and 4 git commands to generate.