Skip to content

Commit

Permalink
ksmbd: retry iterate_dir in smb2_query_dir
Browse files Browse the repository at this point in the history
Some file systems do not ensure that the single call of iterate_dir
reaches the end of the directory. For example, FUSE fetches entries from
a daemon using 4KB buffer and stops fetching if entries exceed 4KB.
Pattern searching on FUSE, the file located after the 4KB can not be
found and STATUS_NO_SUCH_FILE will be returned.

Signed-off-by: Hobin Woo <[email protected]>
Signed-off-by: Namjae Jeon <[email protected]>
  • Loading branch information
Hobin Woo authored and namjaejeon committed Dec 4, 2024
1 parent 2fc566b commit 9bb3615
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions smb2pdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions vfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9bb3615

Please sign in to comment.