Skip to content

Commit 65ca7a3

Browse files
namjaejeonsmfrench
authored andcommitted
ksmbd: handle smb2 query dir request for OutputBufferLength that is too small
We found the issue that ksmbd return STATUS_NO_MORE_FILES response even though there are still dentries that needs to be read while file read/write test using framtest utils. windows client send smb2 query dir request included OutputBufferLength(128) that is too small to contain even one entry. This patch make ksmbd immediately returns OutputBufferLength of response as zero to client. Signed-off-by: Namjae Jeon <[email protected]> Reviewed-by: Hyunchul Lee <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent ee1b055 commit 65ca7a3

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

fs/ksmbd/smb2pdu.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3938,6 +3938,12 @@ int smb2_query_dir(struct ksmbd_work *work)
39383938
set_ctx_actor(&dir_fp->readdir_data.ctx, __query_dir);
39393939

39403940
rc = iterate_dir(dir_fp->filp, &dir_fp->readdir_data.ctx);
3941+
/*
3942+
* req->OutputBufferLength is too small to contain even one entry.
3943+
* In this case, it immediately returns OutputBufferLength 0 to client.
3944+
*/
3945+
if (!d_info.out_buf_len && !d_info.num_entry)
3946+
goto no_buf_len;
39413947
if (rc == 0)
39423948
restart_ctx(&dir_fp->readdir_data.ctx);
39433949
if (rc == -ENOSPC)
@@ -3964,10 +3970,12 @@ int smb2_query_dir(struct ksmbd_work *work)
39643970
rsp->Buffer[0] = 0;
39653971
inc_rfc1001_len(work->response_buf, 9);
39663972
} else {
3973+
no_buf_len:
39673974
((struct file_directory_info *)
39683975
((char *)rsp->Buffer + d_info.last_entry_offset))
39693976
->NextEntryOffset = 0;
3970-
d_info.data_count -= d_info.last_entry_off_align;
3977+
if (d_info.data_count >= d_info.last_entry_off_align)
3978+
d_info.data_count -= d_info.last_entry_off_align;
39713979

39723980
rsp->StructureSize = cpu_to_le16(9);
39733981
rsp->OutputBufferOffset = cpu_to_le16(72);

0 commit comments

Comments
 (0)