From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: VeroFess <coderzeng@hotmail.com>,
Namjae Jeon <linkinjeon@kernel.org>,
Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.1.y] smb: server: size directory name conversion buffer correctly
Date: Thu, 5 Nov 2026 12:50:24 -0500 [thread overview]
Message-ID: <20261105175003.2184217-1-sashal@kernel.org> (raw)
In-Reply-To: <2026110424-hypnoses-average-6482@gregkh>
From: VeroFess <coderzeng@hotmail.com>
[ Upstream commit f1f37834eaba5904103af1f18afe3510c7e9dc71 ]
A 2048-byte ASCII directory name needs 4098 bytes when converted to
UTF-16, including the terminator. ksmbd_convert_dir_info_name() caps
its allocation at PATH_MAX and writes past the end of that buffer.
Allocate space for one UTF-16 code unit per input byte plus the
terminator. Use kmalloc_array() to check the size calculation.
Fixes: e2f34481b24d ("cifsd: add server-side procedures for SMB3")
Cc: stable@vger.kernel.org
Assisted-by: gpt 6 sol with daybreak blue
Signed-off-by: VeroFess <coderzeng@hotmail.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
[ sashal: used GFP_KERNEL instead of KSMBD_DEFAULT_GFP for kmalloc_array() ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
fs/smb/server/misc.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/fs/smb/server/misc.c b/fs/smb/server/misc.c
index 98da57bb5fd29..ea6eccbe81bb9 100644
--- a/fs/smb/server/misc.c
+++ b/fs/smb/server/misc.c
@@ -289,12 +289,13 @@ char *ksmbd_convert_dir_info_name(struct ksmbd_dir_info *d_info,
int *conv_len)
{
char *conv;
- int sz = min(4 * d_info->name_len, PATH_MAX);
- if (!sz)
+ if (d_info->name_len <= 0)
return NULL;
- conv = kmalloc(sz, GFP_KERNEL);
+ /* One UTF-16 code unit per input byte, plus the terminating NUL. */
+ conv = kmalloc_array((size_t)d_info->name_len + 1,
+ sizeof(__le16), GFP_KERNEL);
if (!conv)
return NULL;
@@ -303,7 +304,6 @@ char *ksmbd_convert_dir_info_name(struct ksmbd_dir_info *d_info,
d_info->name_len, local_nls, 0);
*conv_len *= 2;
- /* We allocate buffer twice bigger than needed. */
conv[*conv_len] = 0x00;
conv[*conv_len + 1] = 0x00;
return conv;
--
2.53.0
prev parent reply other threads:[~2026-11-05 17:50 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 18:29 FAILED: patch "[PATCH] smb: server: size directory name conversion buffer correctly" failed to apply to 6.1-stable tree gregkh
2026-11-05 17:50 ` Sasha Levin [this message]
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=20261105175003.2184217-1-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=coderzeng@hotmail.com \
--cc=linkinjeon@kernel.org \
--cc=stable@vger.kernel.org \
/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