* FAILED: patch "[PATCH] smb: client: do not let the server grow a write subrequest" failed to apply to 6.18-stable tree
@ 2026-12-02 13:55 gregkh
2026-12-04 5:23 ` [PATCH 6.18.y 1/2] cifs: make retry logic in read/write path consistent with other paths Sasha Levin
0 siblings, 1 reply; 3+ messages in thread
From: gregkh @ 2026-12-02 13:55 UTC (permalink / raw)
To: ozgunkultekin, linkinjeon, pc; +Cc: stable
The patch below does not apply to the 6.18-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y
git checkout FETCH_HEAD
git cherry-pick -x f834c81f108f8bdb0e3aa8375a536fb6dda56c70
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<stable@vger.kernel.org>' --in-reply-to '2026120211-barge-cope-7560@gregkh' --subject-prefix 'PATCH 6.18.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From f834c81f108f8bdb0e3aa8375a536fb6dda56c70 Mon Sep 17 00:00:00 2001
From: ozgun kultekin <ozgunkultekin@gmail.com>
Date: Tue, 17 Nov 2026 16:21:59 -0800
Subject: [PATCH] smb: client: do not let the server grow a write subrequest
smb2_writev_callback() takes the byte count from the SMB2 WRITE
response, masks it with 0xFFFF if it is larger than the request (for
old OS/2 servers), and then copies it into wdata->subreq.len. A server
can return a count that is still larger than the request after the
mask, for example 0x8002 for a 5-byte write or 0xFFFF for a 4 KiB
write, and the subrequest then covers data that was never sent.
netfs uses the subrequest length to decide how far the write collector
may advance. With a grown subrequest the collector moves collected_to
past the data that was issued: netfs_writeback_unlock_folios() walks
folio_queue slots that were never filled, and
rolling_buffer_delete_spent() frees folio_queue segments that later
in-flight subrequests still use. This is a use-after-free that a
malicious or broken server triggers from an ordinary write:
BUG: KASAN: slab-use-after-free in netfs_limit_iter+0xed4/0x1040
Read of size 1 at addr ff11000010561511 by task kworker/u8:4/63
Workqueue: events_unbound netfs_write_collection_worker
netfs_limit_iter+0xed4/0x1040
netfs_retry_writes+0x1410/0x1e90
netfs_write_collection+0x2647/0x3880
netfs_write_collection_worker+0x1cd/0x3e0
Allocated by task 141:
netfs_folioq_alloc+0x39a/0x470
rolling_buffer_init+0x29/0xc0
netfs_create_write_req+0x12f/0x840
Freed by task 42:
rolling_buffer_delete_spent+0xb1/0x220
netfs_write_collection+0x1f62/0x3880
Never change the subrequest length from the response. If the count is
still larger than the request after the mask, fail the write with -EIO
and record it with a new write_overlarge trace point, like the read
path does with read_overlarge. A short count still returns -ENOSPC as
before.
The folio_queue form of the use-after-free exists since
commit cd0277ed0c18 ("netfs: Use new folio_queue data type and
iterator instead of xarray iter").
Fixes: 3ee1a1fc3981 ("cifs: Cut over to using netfslib")
Cc: stable@vger.kernel.org
Signed-off-by: ozgun kultekin <ozgunkultekin@gmail.com>
Reviewed-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Paulo Alcantara <pc@manguebit.org>
diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c
index b26bfb4bd91a..2f05ba613f34 100644
--- a/fs/smb/client/smb2pdu.c
+++ b/fs/smb/client/smb2pdu.c
@@ -5181,14 +5181,23 @@ smb2_writev_callback(struct TCP_Server_Info *server, struct mid_q_entry *mid)
if (written > wdata->subreq.len)
written &= 0xFFFF;
+ /*
+ * The server must not report more bytes than were sent. netfs
+ * uses the subrequest length to work out which folios this
+ * write has finished with, so it must not be changed here.
+ */
+ if (written > wdata->subreq.len) {
+ result = smb_EIO2(smb_eio_trace_write_overlarge,
+ written, wdata->subreq.len);
+ break;
+ }
+
cifs_stats_bytes_written(tcon, written);
- if (written < wdata->subreq.len) {
+ if (written < wdata->subreq.len)
result = -ENOSPC;
- } else if (written > 0) {
- wdata->subreq.len = written;
+ else if (written > 0)
__set_bit(NETFS_SREQ_MADE_PROGRESS, &wdata->subreq.flags);
- }
break;
case MID_REQUEST_SUBMITTED:
trace_netfs_sreq(&wdata->subreq, netfs_sreq_trace_io_req_submitted);
diff --git a/fs/smb/client/trace.h b/fs/smb/client/trace.h
index 5331ce6dc8b3..18760a81949c 100644
--- a/fs/smb/client/trace.h
+++ b/fs/smb/client/trace.h
@@ -153,6 +153,7 @@
EM(smb_eio_trace_user_iter, "user_iter") \
EM(smb_eio_trace_write_bad_buf_type, "write_bad_buf_type") \
EM(smb_eio_trace_write_mid_state_unknown, "write_mid_state_unknown") \
+ EM(smb_eio_trace_write_overlarge, "write_overlarge") \
EM(smb_eio_trace_write_rsp_malformed, "write_rsp_malformed") \
E_(smb_eio_trace_write_too_far, "write_too_far")
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 6.18.y 1/2] cifs: make retry logic in read/write path consistent with other paths
2026-12-02 13:55 FAILED: patch "[PATCH] smb: client: do not let the server grow a write subrequest" failed to apply to 6.18-stable tree gregkh
@ 2026-12-04 5:23 ` Sasha Levin
2026-12-04 5:23 ` [PATCH 6.18.y 2/2] smb: client: do not let the server grow a write subrequest Sasha Levin
0 siblings, 1 reply; 3+ messages in thread
From: Sasha Levin @ 2026-12-04 5:23 UTC (permalink / raw)
To: stable; +Cc: Shyam Prasad N, David Howells, Steve French, Sasha Levin
From: Shyam Prasad N <sprasad@microsoft.com>
[ Upstream commit 2c1238a7477a2e76a49161937fc20a04c74dbd76 ]
Today in most other code paths in cifs.ko, the decision of whether
to retry a command depends on two mount options: retrans and hard.
However, the read/write code paths diverged from this and would only
retry if the error returned was -EAGAIN. However, there are other
replayable errors in cifs.ko, for which is_replayable_errors helper
was written. This change makes read/write codepaths consistent with
other code-paths.
This change also does the following:
1. The SMB2 read/write code diverged significantly (presumably since
they were changed during netfs refactor at different times). This
changes the response verification logic to be consistent.
2. Moves the netfs tracepoints to slightly different locations in order
to make debugging easier.
Cc: David Howells <dhowells@redhat.com>
Signed-off-by: Shyam Prasad N <sprasad@microsoft.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
Stable-dep-of: f834c81f108f ("smb: client: do not let the server grow a write subrequest")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
fs/smb/client/cifsglob.h | 2 +
fs/smb/client/smb2pdu.c | 79 ++++++++++++++++++++++++++++++++++++----
2 files changed, 74 insertions(+), 7 deletions(-)
diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h
index 09a711268b6e2..28570dff312e7 100644
--- a/fs/smb/client/cifsglob.h
+++ b/fs/smb/client/cifsglob.h
@@ -1508,6 +1508,8 @@ struct cifs_io_subrequest {
int result;
bool have_xid;
bool replay;
+ unsigned int retries; /* number of retries so far */
+ unsigned int cur_sleep; /* time to sleep before replay */
struct kvec iov[2];
struct TCP_Server_Info *server;
#ifdef CONFIG_CIFS_SMB_DIRECT
diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c
index 17230f94eea3b..b858eab40732f 100644
--- a/fs/smb/client/smb2pdu.c
+++ b/fs/smb/client/smb2pdu.c
@@ -4683,9 +4683,19 @@ smb2_readv_callback(struct mid_q_entry *mid)
iov_iter_truncate(&rqst.rq_iter, rdata->got_bytes);
rc = smb2_verify_signature(&rqst, server);
- if (rc)
+ if (rc) {
cifs_tcon_dbg(VFS, "SMB signature verification returned error = %d\n",
- rc);
+ rc);
+ rdata->subreq.error = rc;
+ rdata->result = rc;
+
+ if (is_replayable_error(rc)) {
+ trace_netfs_sreq(&rdata->subreq, netfs_sreq_trace_io_retry_needed);
+ __set_bit(NETFS_SREQ_NEED_RETRY, &rdata->subreq.flags);
+ } else
+ trace_netfs_sreq(&rdata->subreq, netfs_sreq_trace_io_bad);
+ } else
+ trace_netfs_sreq(&rdata->subreq, netfs_sreq_trace_io_progress);
}
/* FIXME: should this be counted toward the initiating task? */
task_io_account_read(rdata->got_bytes);
@@ -4766,6 +4776,14 @@ smb2_readv_callback(struct mid_q_entry *mid)
if (rdata->got_bytes)
__set_bit(NETFS_SREQ_MADE_PROGRESS, &rdata->subreq.flags);
}
+
+ /* see if we need to retry */
+ if (is_replayable_error(rdata->result) &&
+ smb2_should_replay(tcon,
+ &rdata->retries,
+ &rdata->cur_sleep))
+ rdata->replay = true;
+
trace_smb3_rw_credits(rreq_debug_id, subreq_debug_index, rdata->credits.value,
server->credits, server->in_flight,
0, cifs_trace_rw_credits_read_response_clear);
@@ -4814,7 +4832,7 @@ smb2_async_readv(struct cifs_io_subrequest *rdata)
rc = smb2_new_read_req(
(void **) &buf, &total_len, &io_parms, rdata, 0, 0);
if (rc)
- return rc;
+ goto out;
if (smb3_encryption_required(io_parms.tcon))
flags |= CIFS_TRANSFORM_REQ;
@@ -4826,6 +4844,13 @@ smb2_async_readv(struct cifs_io_subrequest *rdata)
shdr = (struct smb2_hdr *)buf;
+ if (rdata->replay) {
+ /* Back-off before retry */
+ if (rdata->cur_sleep)
+ msleep(rdata->cur_sleep);
+ smb2_set_replay(server, &rqst);
+ }
+
if (rdata->credits.value > 0) {
shdr->CreditCharge = cpu_to_le16(DIV_ROUND_UP(io_parms.length,
SMB2_MAX_BUFFER_SIZE));
@@ -4861,6 +4886,17 @@ smb2_async_readv(struct cifs_io_subrequest *rdata)
async_readv_out:
cifs_small_buf_release(buf);
+
+out:
+ /* if the send error is retryable, let netfs know about it */
+ if (is_replayable_error(rc) &&
+ smb2_should_replay(tcon,
+ &rdata->retries,
+ &rdata->cur_sleep)) {
+ trace_netfs_sreq(&rdata->subreq, netfs_sreq_trace_io_retry_needed);
+ __set_bit(NETFS_SREQ_NEED_RETRY, &rdata->subreq.flags);
+ }
+
return rc;
}
@@ -4995,14 +5031,20 @@ smb2_writev_callback(struct mid_q_entry *mid)
switch (mid->mid_state) {
case MID_RESPONSE_RECEIVED:
- trace_netfs_sreq(&wdata->subreq, netfs_sreq_trace_io_progress);
credits.value = le16_to_cpu(rsp->hdr.CreditRequest);
credits.instance = server->reconnect_instance;
result = smb2_check_receive(mid, server, 0);
if (result != 0) {
- trace_netfs_sreq(&wdata->subreq, netfs_sreq_trace_io_bad);
+ if (is_replayable_error(result)) {
+ trace_netfs_sreq(&wdata->subreq, netfs_sreq_trace_io_retry_needed);
+ __set_bit(NETFS_SREQ_NEED_RETRY, &wdata->subreq.flags);
+ } else {
+ wdata->subreq.error = result;
+ trace_netfs_sreq(&wdata->subreq, netfs_sreq_trace_io_bad);
+ }
break;
}
+ trace_netfs_sreq(&wdata->subreq, netfs_sreq_trace_io_progress);
written = le32_to_cpu(rsp->DataLength);
/*
@@ -5017,7 +5059,7 @@ smb2_writev_callback(struct mid_q_entry *mid)
cifs_stats_bytes_written(tcon, written);
if (written < wdata->subreq.len) {
- wdata->result = -ENOSPC;
+ result = -ENOSPC;
} else if (written > 0) {
wdata->subreq.len = written;
__set_bit(NETFS_SREQ_MADE_PROGRESS, &wdata->subreq.flags);
@@ -5058,6 +5100,7 @@ smb2_writev_callback(struct mid_q_entry *mid)
}
#endif
if (result) {
+ wdata->result = result;
cifs_stats_fail_inc(tcon, SMB2_WRITE_HE);
trace_smb3_write_err(wdata->rreq->debug_id,
wdata->subreq.debug_index,
@@ -5080,6 +5123,14 @@ smb2_writev_callback(struct mid_q_entry *mid)
server->credits, server->in_flight,
0, cifs_trace_rw_credits_write_response_clear);
wdata->credits.value = 0;
+
+ /* see if we need to retry */
+ if (is_replayable_error(wdata->result) &&
+ smb2_should_replay(tcon,
+ &wdata->retries,
+ &wdata->cur_sleep))
+ wdata->replay = true;
+
cifs_write_subrequest_terminated(wdata, result ?: written);
release_mid(mid);
trace_smb3_rw_credits(rreq_debug_id, subreq_debug_index, 0,
@@ -5198,8 +5249,12 @@ smb2_async_writev(struct cifs_io_subrequest *wdata)
}
#endif
- if (wdata->subreq.retry_count > 0)
+ if (wdata->replay) {
+ /* Back-off before retry */
+ if (wdata->cur_sleep)
+ msleep(wdata->cur_sleep);
smb2_set_replay(server, &rqst);
+ }
cifs_dbg(FYI, "async write at %llu %u bytes iter=%zx\n",
io_parms->offset, io_parms->length, iov_iter_count(&wdata->subreq.io_iter));
@@ -5245,6 +5300,16 @@ smb2_async_writev(struct cifs_io_subrequest *wdata)
async_writev_out:
cifs_small_buf_release(req);
out:
+ /* if the send error is retryable, let netfs know about it */
+ if (is_replayable_error(rc) &&
+ smb2_should_replay(tcon,
+ &wdata->retries,
+ &wdata->cur_sleep)) {
+ wdata->replay = true;
+ trace_netfs_sreq(&wdata->subreq, netfs_sreq_trace_io_retry_needed);
+ __set_bit(NETFS_SREQ_NEED_RETRY, &wdata->subreq.flags);
+ }
+
if (rc) {
trace_smb3_rw_credits(wdata->rreq->debug_id,
wdata->subreq.debug_index,
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 6.18.y 2/2] smb: client: do not let the server grow a write subrequest
2026-12-04 5:23 ` [PATCH 6.18.y 1/2] cifs: make retry logic in read/write path consistent with other paths Sasha Levin
@ 2026-12-04 5:23 ` Sasha Levin
0 siblings, 0 replies; 3+ messages in thread
From: Sasha Levin @ 2026-12-04 5:23 UTC (permalink / raw)
To: stable; +Cc: ozgun kultekin, Namjae Jeon, Paulo Alcantara, Sasha Levin
From: ozgun kultekin <ozgunkultekin@gmail.com>
[ Upstream commit f834c81f108f8bdb0e3aa8375a536fb6dda56c70 ]
smb2_writev_callback() takes the byte count from the SMB2 WRITE
response, masks it with 0xFFFF if it is larger than the request (for
old OS/2 servers), and then copies it into wdata->subreq.len. A server
can return a count that is still larger than the request after the
mask, for example 0x8002 for a 5-byte write or 0xFFFF for a 4 KiB
write, and the subrequest then covers data that was never sent.
netfs uses the subrequest length to decide how far the write collector
may advance. With a grown subrequest the collector moves collected_to
past the data that was issued: netfs_writeback_unlock_folios() walks
folio_queue slots that were never filled, and
rolling_buffer_delete_spent() frees folio_queue segments that later
in-flight subrequests still use. This is a use-after-free that a
malicious or broken server triggers from an ordinary write:
BUG: KASAN: slab-use-after-free in netfs_limit_iter+0xed4/0x1040
Read of size 1 at addr ff11000010561511 by task kworker/u8:4/63
Workqueue: events_unbound netfs_write_collection_worker
netfs_limit_iter+0xed4/0x1040
netfs_retry_writes+0x1410/0x1e90
netfs_write_collection+0x2647/0x3880
netfs_write_collection_worker+0x1cd/0x3e0
Allocated by task 141:
netfs_folioq_alloc+0x39a/0x470
rolling_buffer_init+0x29/0xc0
netfs_create_write_req+0x12f/0x840
Freed by task 42:
rolling_buffer_delete_spent+0xb1/0x220
netfs_write_collection+0x1f62/0x3880
Never change the subrequest length from the response. If the count is
still larger than the request after the mask, fail the write with -EIO
and record it with a new write_overlarge trace point, like the read
path does with read_overlarge. A short count still returns -ENOSPC as
before.
The folio_queue form of the use-after-free exists since
commit cd0277ed0c18 ("netfs: Use new folio_queue data type and
iterator instead of xarray iter").
Fixes: 3ee1a1fc3981 ("cifs: Cut over to using netfslib")
Cc: stable@vger.kernel.org
Signed-off-by: ozgun kultekin <ozgunkultekin@gmail.com>
Reviewed-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Paulo Alcantara <pc@manguebit.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
fs/smb/client/smb2pdu.c | 17 +++++++++++++----
fs/smb/client/trace.h | 1 +
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c
index b858eab40732f..5b6813885f3e5 100644
--- a/fs/smb/client/smb2pdu.c
+++ b/fs/smb/client/smb2pdu.c
@@ -5056,14 +5056,23 @@ smb2_writev_callback(struct mid_q_entry *mid)
if (written > wdata->subreq.len)
written &= 0xFFFF;
+ /*
+ * The server must not report more bytes than were sent. netfs
+ * uses the subrequest length to work out which folios this
+ * write has finished with, so it must not be changed here.
+ */
+ if (written > wdata->subreq.len) {
+ result = smb_EIO2(smb_eio_trace_write_overlarge,
+ written, wdata->subreq.len);
+ break;
+ }
+
cifs_stats_bytes_written(tcon, written);
- if (written < wdata->subreq.len) {
+ if (written < wdata->subreq.len)
result = -ENOSPC;
- } else if (written > 0) {
- wdata->subreq.len = written;
+ else if (written > 0)
__set_bit(NETFS_SREQ_MADE_PROGRESS, &wdata->subreq.flags);
- }
break;
case MID_REQUEST_SUBMITTED:
trace_netfs_sreq(&wdata->subreq, netfs_sreq_trace_io_req_submitted);
diff --git a/fs/smb/client/trace.h b/fs/smb/client/trace.h
index 670612d1a4497..39b5ffe902510 100644
--- a/fs/smb/client/trace.h
+++ b/fs/smb/client/trace.h
@@ -150,6 +150,7 @@
EM(smb_eio_trace_user_iter, "user_iter") \
EM(smb_eio_trace_write_bad_buf_type, "write_bad_buf_type") \
EM(smb_eio_trace_write_mid_state_unknown, "write_mid_state_unknown") \
+ EM(smb_eio_trace_write_overlarge, "write_overlarge") \
EM(smb_eio_trace_write_rsp_malformed, "write_rsp_malformed") \
E_(smb_eio_trace_write_too_far, "write_too_far")
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-04 5:23 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 13:55 FAILED: patch "[PATCH] smb: client: do not let the server grow a write subrequest" failed to apply to 6.18-stable tree gregkh
2026-12-04 5:23 ` [PATCH 6.18.y 1/2] cifs: make retry logic in read/write path consistent with other paths Sasha Levin
2026-12-04 5:23 ` [PATCH 6.18.y 2/2] smb: client: do not let the server grow a write subrequest Sasha Levin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox