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 28142146D6B; Mon, 6 Jan 2025 15:22:40 +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=1736176960; cv=none; b=hIvB0BiwYd0AR+FunKuIVYqht8uKQD61pvrsTLHWLvZal3faSQDN/XWy6qHsVg1oH45UmJz+XppRPojTrt6B5AB20tnGab/kBxoc/LBXT2buA5oln7Bs/Hyc/S1f9iRV++hw96bLdu3dvyMGHsGheDiPLOUXrdQL2ZaqeWU2OL8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736176960; c=relaxed/simple; bh=VCspxvwjvG0Wi0gU0Z/bhDhZPlPwP72R/X0UHcrP+Q0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o4g5rTEsAN0wdQ3Gskr754xc3fTkp+0rNTQr/bM+kdULh48sh7fAlOzmQ6jVDPNxLMvu8pZmA1yhDeu+au/PBVpXjFEtLEsQ4TCQw7CE6sxKkWjmW67UuyumQfycetwHpUWrpKlhHLaHHUp5WEvxMYIN5eXVf6gr4nQKMJJtXn0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=hzWaNshA; 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="hzWaNshA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A23D9C4CED2; Mon, 6 Jan 2025 15:22:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1736176960; bh=VCspxvwjvG0Wi0gU0Z/bhDhZPlPwP72R/X0UHcrP+Q0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hzWaNshAa2OB5itB/FdAHZX8eT7cGhMmxkiTNNw4NiP8zUKuGnEqAa26b2viV4uVd IhSlnb0DtqdGQBt7CRnXzBqv7CghqnAIX13cSkSfSWKFRgWvKnOz/zR4UuCyI7M0JB oILy/v0EQ8ZS1hbK55qJIIt2GEg0jW00grd8kCWY= 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.1 60/81] ksmbd: retry iterate_dir in smb2_query_dir Date: Mon, 6 Jan 2025 16:16:32 +0100 Message-ID: <20250106151131.700051944@linuxfoundation.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106151129.433047073@linuxfoundation.org> References: <20250106151129.433047073@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-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 96d441ca511d..71478a590e83 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