Skip to content

Commit 0e55f63

Browse files
namjaejeonsmfrench
authored andcommitted
ksmbd: replace hardcoded hdr2_len with offsetof() in smb2_calc_max_out_buf_len()
After this commit (e2b76ab "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: [email protected] Fixes: e2b76ab ("ksmbd: add support for read compound") Signed-off-by: Namjae Jeon <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 309b44e commit 0e55f63

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

fs/smb/server/smb2pdu.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4452,8 +4452,9 @@ int smb2_query_dir(struct ksmbd_work *work)
44524452
d_info.wptr = (char *)rsp->Buffer;
44534453
d_info.rptr = (char *)rsp->Buffer;
44544454
d_info.out_buf_len =
4455-
smb2_calc_max_out_buf_len(work, 8,
4456-
le32_to_cpu(req->OutputBufferLength));
4455+
smb2_calc_max_out_buf_len(work,
4456+
offsetof(struct smb2_query_directory_rsp, Buffer),
4457+
le32_to_cpu(req->OutputBufferLength));
44574458
if (d_info.out_buf_len < 0) {
44584459
rc = -EINVAL;
44594460
goto err_out;
@@ -4720,8 +4721,9 @@ static int smb2_get_ea(struct ksmbd_work *work, struct ksmbd_file *fp,
47204721
}
47214722

47224723
buf_free_len =
4723-
smb2_calc_max_out_buf_len(work, 8,
4724-
le32_to_cpu(req->OutputBufferLength));
4724+
smb2_calc_max_out_buf_len(work,
4725+
offsetof(struct smb2_query_info_rsp, Buffer),
4726+
le32_to_cpu(req->OutputBufferLength));
47254727
if (buf_free_len < 0)
47264728
return -EINVAL;
47274729

@@ -5047,8 +5049,9 @@ static int get_file_stream_info(struct ksmbd_work *work,
50475049
file_info = (struct smb2_file_stream_info *)rsp->Buffer;
50485050

50495051
buf_free_len =
5050-
smb2_calc_max_out_buf_len(work, 8,
5051-
le32_to_cpu(req->OutputBufferLength));
5052+
smb2_calc_max_out_buf_len(work,
5053+
offsetof(struct smb2_query_info_rsp, Buffer),
5054+
le32_to_cpu(req->OutputBufferLength));
50525055
if (buf_free_len < 0)
50535056
goto out;
50545057

@@ -8206,8 +8209,9 @@ int smb2_ioctl(struct ksmbd_work *work)
82068209
buffer = (char *)req + le32_to_cpu(req->InputOffset);
82078210

82088211
cnt_code = le32_to_cpu(req->CtlCode);
8209-
ret = smb2_calc_max_out_buf_len(work, 48,
8210-
le32_to_cpu(req->MaxOutputResponse));
8212+
ret = smb2_calc_max_out_buf_len(work,
8213+
offsetof(struct smb2_ioctl_rsp, Buffer),
8214+
le32_to_cpu(req->MaxOutputResponse));
82118215
if (ret < 0) {
82128216
rsp->hdr.Status = STATUS_INVALID_PARAMETER;
82138217
goto out;

0 commit comments

Comments
 (0)