From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Hobin Woo <hobin.woo@samsung.com>,
Sungjong Seo <sj1557.seo@samsung.com>,
Namjae Jeon <linkinjeon@kernel.org>,
Yoonho Shin <yoonho.shin@samsung.com>,
Steve French <stfrench@microsoft.com>,
Sasha Levin <sashal@kernel.org>,
sfrench@samba.org, linux-cifs@vger.kernel.org
Subject: [PATCH AUTOSEL 6.1 08/12] ksmbd: retry iterate_dir in smb2_query_dir
Date: Fri, 20 Dec 2024 12:13:13 -0500 [thread overview]
Message-ID: <20241220171317.512120-8-sashal@kernel.org> (raw)
In-Reply-To: <20241220171317.512120-1-sashal@kernel.org>
From: Hobin Woo <hobin.woo@samsung.com>
[ Upstream commit 2b904d61a97e8ba79e3bc216ba290fd7e1d85028 ]
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 the
buffer. And then an actor of caller, KSMBD, is used to fill the entries
from the buffer.
Thus, pattern searching on FUSE, files located after the 4KB could not
be found and STATUS_NO_SUCH_FILE was returned.
Signed-off-by: Hobin Woo <hobin.woo@samsung.com>
Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com>
Reviewed-by: Namjae Jeon <linkinjeon@kernel.org>
Tested-by: Yoonho Shin <yoonho.shin@samsung.com>
Acked-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
fs/smb/server/smb2pdu.c | 12 +++++++++++-
fs/smb/server/vfs.h | 1 +
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c
index cb7756469621..bdd94339725c 100644
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -3988,6 +3988,7 @@ static bool __query_dir(struct dir_context *ctx, const char *name, int namlen,
/* dot and dotdot entries are already reserved */
if (!strcmp(".", name) || !strcmp("..", name))
return true;
+ d_info->num_scan++;
if (ksmbd_share_veto_filename(priv->work->tcon->share_conf, name))
return true;
if (!match_pattern(name, namlen, priv->search_pattern))
@@ -4148,8 +4149,17 @@ int smb2_query_dir(struct ksmbd_work *work)
query_dir_private.info_level = req->FileInformationClass;
dir_fp->readdir_data.private = &query_dir_private;
set_ctx_actor(&dir_fp->readdir_data.ctx, __query_dir);
-
+again:
+ d_info.num_scan = 0;
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 &&
+ d_info.out_buf_len > 0)
+ 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/fs/smb/server/vfs.h b/fs/smb/server/vfs.h
index e761dde2443e..cc47e71c4de1 100644
--- a/fs/smb/server/vfs.h
+++ b/fs/smb/server/vfs.h
@@ -43,6 +43,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;
--
2.39.5
next prev parent reply other threads:[~2024-12-20 17:13 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-20 17:13 [PATCH AUTOSEL 6.1 01/12] wifi: mac80211: wake the queues in case of failure in resume Sasha Levin
2024-12-20 17:13 ` [PATCH AUTOSEL 6.1 02/12] drm/amdkfd: Correct the migration DMA map direction Sasha Levin
2024-12-20 17:13 ` [PATCH AUTOSEL 6.1 03/12] btrfs: flush delalloc workers queue before stopping cleaner kthread during unmount Sasha Levin
2024-12-20 17:13 ` [PATCH AUTOSEL 6.1 04/12] ALSA: hda/realtek: Add new alc2xx-fixup-headset-mic model Sasha Levin
2024-12-20 17:13 ` [PATCH AUTOSEL 6.1 05/12] sound: usb: enable DSD output for ddHiFi TC44C Sasha Levin
2024-12-20 17:13 ` [PATCH AUTOSEL 6.1 06/12] sound: usb: format: don't warn that raw DSD is unsupported Sasha Levin
2024-12-20 17:13 ` [PATCH AUTOSEL 6.1 07/12] bpf: fix potential error return Sasha Levin
2024-12-20 17:13 ` Sasha Levin [this message]
2024-12-20 17:13 ` [PATCH AUTOSEL 6.1 09/12] net: usb: qmi_wwan: add Telit FE910C04 compositions Sasha Levin
2024-12-20 17:13 ` [PATCH AUTOSEL 6.1 10/12] Bluetooth: hci_core: Fix sleeping function called from invalid context Sasha Levin
2024-12-20 17:13 ` [PATCH AUTOSEL 6.1 11/12] irqchip/gic: Correct declaration of *percpu_base pointer in union gic_base Sasha Levin
2024-12-20 17:13 ` [PATCH AUTOSEL 6.1 12/12] ARC: build: Try to guess GCC variant of cross compiler Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241220171317.512120-8-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=hobin.woo@samsung.com \
--cc=linkinjeon@kernel.org \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sfrench@samba.org \
--cc=sj1557.seo@samsung.com \
--cc=stable@vger.kernel.org \
--cc=stfrench@microsoft.com \
--cc=yoonho.shin@samsung.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®