]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ksmbd: replace hardcoded hdr2_len with offsetof() in smb2_calc_max_out_buf_len()
authorNamjae Jeon <linkinjeon@kernel.org>
Mon, 30 Mar 2026 14:40:42 +0000 (10:40 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 18 Apr 2026 08:33:39 +0000 (10:33 +0200)
[ Upstream commit 0e55f63dd08f09651d39e1b709a91705a8a0ddcb ]

After this commit (e2b76ab8b5c9 "ksmbd: add support for read compound"),
response buffer management was changed to use dynamic iov array.
In the new design, smb2_calc_max_out_buf_len() expects the second
argument (hdr2_len) to be the offset of ->Buffer field in the
response structure, not a hardcoded magic number.
Fix the remaining call sites to use the correct offsetof() value.

Cc: stable@vger.kernel.org
Fixes: e2b76ab8b5c9 ("ksmbd: add support for read compound")
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
[ adapted `req->CtlCode` field access to `req->CntCode` ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/ksmbd/smb2pdu.c

index f9cc39a375b59306c631c3aa1e85d96031af32c8..a8eafd498d10fe19cc6fcc5fd05ab1265dd1cd79 100644 (file)
@@ -4123,8 +4123,9 @@ int smb2_query_dir(struct ksmbd_work *work)
        d_info.wptr = (char *)rsp->Buffer;
        d_info.rptr = (char *)rsp->Buffer;
        d_info.out_buf_len =
-               smb2_calc_max_out_buf_len(work, 8,
-                                         le32_to_cpu(req->OutputBufferLength));
+               smb2_calc_max_out_buf_len(work,
+                               offsetof(struct smb2_query_directory_rsp, Buffer),
+                               le32_to_cpu(req->OutputBufferLength));
        if (d_info.out_buf_len < 0) {
                rc = -EINVAL;
                goto err_out;
@@ -4374,8 +4375,9 @@ static int smb2_get_ea(struct ksmbd_work *work, struct ksmbd_file *fp,
        }
 
        buf_free_len =
-               smb2_calc_max_out_buf_len(work, 8,
-                                         le32_to_cpu(req->OutputBufferLength));
+               smb2_calc_max_out_buf_len(work,
+                               offsetof(struct smb2_query_info_rsp, Buffer),
+                               le32_to_cpu(req->OutputBufferLength));
        if (buf_free_len < 0)
                return -EINVAL;
 
@@ -4685,8 +4687,9 @@ static void get_file_stream_info(struct ksmbd_work *work,
        file_info = (struct smb2_file_stream_info *)rsp->Buffer;
 
        buf_free_len =
-               smb2_calc_max_out_buf_len(work, 8,
-                                         le32_to_cpu(req->OutputBufferLength));
+               smb2_calc_max_out_buf_len(work,
+                               offsetof(struct smb2_query_info_rsp, Buffer),
+                               le32_to_cpu(req->OutputBufferLength));
        if (buf_free_len < 0)
                goto out;
 
@@ -7726,8 +7729,9 @@ int smb2_ioctl(struct ksmbd_work *work)
 
        buffer = (char *)req + le32_to_cpu(req->InputOffset);
        cnt_code = le32_to_cpu(req->CntCode);
-       ret = smb2_calc_max_out_buf_len(work, 48,
-                                       le32_to_cpu(req->MaxOutputResponse));
+       ret = smb2_calc_max_out_buf_len(work,
+                       offsetof(struct smb2_ioctl_rsp, Buffer),
+                       le32_to_cpu(req->MaxOutputResponse));
        if (ret < 0) {
                rsp->hdr.Status = STATUS_INVALID_PARAMETER;
                goto out;