From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 45ED9DF71; Mon, 6 Jan 2025 15:38:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736177906; cv=none; b=UHvz1bmg2i52woQ31KNBIxjS29lTbYUaxuBfIa0Rx+wEyTa3Bcux4iCeycdD91kpUh3cDo+Wmpa0TNI03D8ZwIl/f1oYuwvqpcT8sxI5OL7R2VO6vxGak7fbbHs+IE0tBMIlZsPOfSddwJh0Kkf5GIDPphWwHQSsVaViQMkzAYo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736177906; c=relaxed/simple; bh=LTj8nTSQ3QHfN3aQyDwgwCQ+5AquuJvTBGjox1KkLOo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eVABM4UE/HHBVF8hnqq/7VoPYKIjd/Mbij/Tq/QCX4QVG7YUu4fnZvJ8gPWHEtMQsmRNhyfDJ27ifZEW0qkRdGSspp6t7bJ/BZfTesWSxoOvKKpGLBnTr0vMKNbqpOG99bPw3rehfTlKttq37+BygcxOVXvhEp9SM7MWUMbjJp8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=JMF4PU9K; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="JMF4PU9K" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF9B8C4CED2; Mon, 6 Jan 2025 15:38:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1736177906; bh=LTj8nTSQ3QHfN3aQyDwgwCQ+5AquuJvTBGjox1KkLOo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JMF4PU9KW3j97tAIrchdJ3cq0dBgC3EjM2K4Sss+h9Vl6AedMWfLgnftT6r/f5au8 V3woi5xVjnJMgQrCydqJJ2/dU8ZH9snV/gyHSbZfzwNrqvd10ceVEXGEuEsqxBcRR7 QPUS15CmNrnj/tonj32K4Qq1xoRGK0+9HsbB1lm4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Hobin Woo , Sungjong Seo , Namjae Jeon , Yoonho Shin , Steve French , Sasha Levin Subject: [PATCH 6.12 097/156] ksmbd: retry iterate_dir in smb2_query_dir Date: Mon, 6 Jan 2025 16:16:23 +0100 Message-ID: <20250106151145.380808157@linuxfoundation.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106151141.738050441@linuxfoundation.org> References: <20250106151141.738050441@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Hobin Woo [ 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 Reviewed-by: Sungjong Seo Reviewed-by: Namjae Jeon Tested-by: Yoonho Shin Acked-by: Namjae Jeon Signed-off-by: Steve French Signed-off-by: Sasha Levin --- 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 7d01dd313351..aef5a1b7c490 100644 --- a/fs/smb/server/smb2pdu.c +++ b/fs/smb/server/smb2pdu.c @@ -4224,6 +4224,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)) @@ -4384,8 +4385,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 cb76f4b5bafe..06903024a2d8 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