diff --git a/smb2pdu.c b/smb2pdu.c index 3efd5177..eb555f0d 100644 --- a/smb2pdu.c +++ b/smb2pdu.c @@ -4443,6 +4443,7 @@ static int __query_dir(struct dir_context *ctx, const char *name, int namlen, #else return 0; #endif + d_info->num_scan++; if (ksmbd_share_veto_filename(priv->work->tcon->share_conf, name)) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0) return true; @@ -4637,7 +4638,15 @@ int smb2_query_dir(struct ksmbd_work *work) dir_fp->readdir_data.private = &query_dir_private; set_ctx_actor(&dir_fp->readdir_data.ctx, __query_dir); +again: rc = iterate_dir(dir_fp->filp, &dir_fp->readdir_data.ctx); + /* + * num_entry can be 0 if the directory iteration stops before reaching + * the end of the directory and no file is matched with the search + * pattern. + */ + if (rc >= 0 && !d_info.num_entry && d_info.num_scan) + goto again; /* * req->OutputBufferLength is too small to contain even one entry. * In this case, it immediately returns OutputBufferLength 0 to client. diff --git a/vfs.h b/vfs.h index 728016cb..65776d8b 100644 --- a/vfs.h +++ b/vfs.h @@ -85,6 +85,7 @@ struct ksmbd_dir_info { char *rptr; int name_len; int out_buf_len; + int num_scan; int num_entry; int data_count; int last_entry_offset;