* [PATCH] ksmbd: fix heap out-of-bounds write in SMB2_CREATE context stacking
@ 2026-10-08 17:05 Henry Martin
2026-10-09 2:35 ` Namjae Jeon
0 siblings, 1 reply; 2+ messages in thread
From: Henry Martin @ 2026-10-08 17:05 UTC (permalink / raw)
To: Namjae Jeon, Sergey Senozhatsky, Tom Talpey, ChenXiaoSong, Gael Blivet
Cc: linux-cifs, linux-kernel, Henry Martin
smb2_open() appends up to six create contexts (lease, mxac, disk_id,
durable, posix, aapl) back-to-back without checking the total length
against work->response_sz. A non-compound SMB2_CREATE only gets the
448-byte small response buffer, which also carries the 4-byte rfc1002
length word, leaving 292 bytes for contexts. The AAPL response alone
occupies 128 fixed bytes, so a client stacking contexts (up to 416)
overruns the kmalloc-512 object into the adjacent allocation with a
deterministic zero-fill.
Compute the worst-case context total from the per-dialect
conn->vals->create_*_size table and grow the response buffer to fit
before writing any context, so legitimate requests keep working
unchanged.
This vulnerability was discovered by Tencent CodeBuddy Security.
Fixes: 8f1b796ff1135 ("ksmbd: add AAPL kAAPL_SERVER_QUERY create context support")
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
---
fs/smb/server/smb2pdu.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c
index 6b8809f67b926..e18e6b630f757 100644
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -5162,6 +5162,52 @@ int smb2_open(struct ksmbd_work *work)
rsp->CreateContextsLength = 0;
iov_len = offsetof(struct smb2_create_rsp, Buffer);
+ /*
+ * The create contexts below are appended back-to-back with no
+ * length check, while a non-compound CREATE only gets the 448-byte
+ * small response buffer; a client stacking lease+mxac+disk_id+
+ * durable+posix+AAPL contexts overruns it (the AAPL response alone
+ * memsets 128 fixed bytes). Compute the worst-case total and grow
+ * the buffer before writing any context. Note that response_buf
+ * also carries the 4-byte rfc1002 length word before the SMB2
+ * header.
+ */
+ {
+ size_t ctx_max = 0;
+ size_t need;
+ void *nbuf;
+
+ if (opinfo && opinfo->is_lease)
+ ctx_max += conn->vals->create_lease_size;
+ if (maximal_access_ctxt)
+ ctx_max += conn->vals->create_mxac_size;
+ if (query_disk_id)
+ ctx_max += conn->vals->create_disk_id_size;
+ if (durable_rsp && dh_info.type == DURABLE_REQ_V2)
+ ctx_max += conn->vals->create_durable_v2_size;
+ else if (durable_rsp && dh_info.type == DURABLE_REQ)
+ ctx_max += conn->vals->create_durable_size;
+ if (posix_ctxt)
+ ctx_max += conn->vals->create_posix_size;
+ if (aapl_ctxt)
+ ctx_max += conn->vals->create_aapl_size;
+
+ need = 4 + offsetof(struct smb2_create_rsp, Buffer) + ctx_max;
+ if (need > work->response_sz) {
+ nbuf = kvzalloc(need, KSMBD_DEFAULT_GFP);
+ if (!nbuf) {
+ rc = -ENOMEM;
+ goto err_out;
+ }
+ memcpy(nbuf, work->response_buf,
+ 4 + offsetof(struct smb2_create_rsp, Buffer));
+ kvfree(work->response_buf);
+ work->response_buf = nbuf;
+ work->response_sz = need;
+ rsp = smb_get_msg(work->response_buf);
+ }
+ }
+
/* If lease is request send lease context response */
if (opinfo && opinfo->is_lease) {
struct create_context *lease_ccontext;
--
2.43.7
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] ksmbd: fix heap out-of-bounds write in SMB2_CREATE context stacking
2026-10-08 17:05 [PATCH] ksmbd: fix heap out-of-bounds write in SMB2_CREATE context stacking Henry Martin
@ 2026-10-09 2:35 ` Namjae Jeon
0 siblings, 0 replies; 2+ messages in thread
From: Namjae Jeon @ 2026-10-09 2:35 UTC (permalink / raw)
To: Henry Martin
Cc: Sergey Senozhatsky, Tom Talpey, ChenXiaoSong, Gael Blivet,
linux-cifs, linux-kernel
On Fri, Oct 9, 2026 at 2:05 AM Henry Martin <bsdhenrymartin@gmail.com> wrote:
>
> smb2_open() appends up to six create contexts (lease, mxac, disk_id,
> durable, posix, aapl) back-to-back without checking the total length
> against work->response_sz. A non-compound SMB2_CREATE only gets the
> 448-byte small response buffer, which also carries the 4-byte rfc1002
> length word, leaving 292 bytes for contexts. The AAPL response alone
> occupies 128 fixed bytes, so a client stacking contexts (up to 416)
> overruns the kmalloc-512 object into the adjacent allocation with a
> deterministic zero-fill.
>
> Compute the worst-case context total from the per-dialect
> conn->vals->create_*_size table and grow the response buffer to fit
> before writing any context, so legitimate requests keep working
> unchanged.
>
> This vulnerability was discovered by Tencent CodeBuddy Security.
>
> Fixes: 8f1b796ff1135 ("ksmbd: add AAPL kAAPL_SERVER_QUERY create context support")
> Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
Please check the following patch in #ksmbd-for-next branch.
https://git.kernel.org/pub/scm/linux/kernel/git/linkinjeon/smb.git/commit/?id=4ceeaa7b1a1a022ee329c4068339b3f44c1514a2
Thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-09 2:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-08 17:05 [PATCH] ksmbd: fix heap out-of-bounds write in SMB2_CREATE context stacking Henry Martin
2026-10-09 2:35 ` Namjae Jeon
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®