[PATCH v2 3/5] 9p: bound the zero-copy reply after a fatal signal

From: Lianjie Wang

Date: Mon Nov 23 2026 - 15:43:13 EST


When a fatal signal interrupts p9_virtio_zc_request() while it waits
for the reply to a zero-copy TREAD or TREADDIR, the device can still
answer the request before the RFLUSH, and p9_client_zc_rpc() parses that
reply. p9_virtio_zc_request() has returned by then, so the reply size is
not clamped and handle_rerror() is not called. p9_check_errors() skips
the size check for zero-copy requests, so it parses the error string of
an oversized reply past the end of rc.sdata:

BUG: KASAN: slab-out-of-bounds in p9pdu_readf+0x151e/0x1c50
Read of size 8179 at addr ffff8880043f8009 by task zc9p/155
Call Trace:
p9pdu_readf+0x151e/0x1c50
p9_check_errors+0x23d/0x510
p9_client_zc_rpc+0x4f0/0x970
p9_client_read_once+0x237/0x6c0

Also, p9_check_errors() parses the error string from rc.sdata, where the
device wrote only the header, so p9_errstr2errno() can print
uninitialized memory.

Fix this by accepting such a reply only when it fits within the part of
rc.sdata posted for the header, and by returning -ERESTARTSYS otherwise,
as p9_client_zc_rpc() already does when the device cancels the request.
A zero-copy TWRITE posts all of rc.sdata for the reply, so a late RWRITE
is still accepted.

This patch is assisted by Claude Opus 5.5.

Fixes: f615625a44c4 ("9p: handling Rerror without copy_from_iter_full()")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lianjie Wang <lian@xxxxxxxxxxxxxxxxxx>
---
v2:
- Accept a late reply within the part of rc.sdata posted for the header,
so the RWRITE of a completed write is not dropped.
v1: https://lore.kernel.org/all/20261109105251.2545764-3-lian@xxxxxxxxxxxxxxxxxx/

net/9p/client.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/net/9p/client.c b/net/9p/client.c
index e63e8c2a853df..e21d13e274691 100644
--- a/net/9p/client.c
+++ b/net/9p/client.c
@@ -707,9 +707,17 @@ static struct p9_req_t *p9_client_zc_rpc(struct p9_client *c, int8_t type,
if (c->trans_mod->cancel(c, req))
p9_client_flush(c, req);

- /* if we received the response anyway, don't signal error */
- if (READ_ONCE(req->status) == REQ_STATUS_RCVD)
- err = 0;
+ /* if we received the response anyway, don't signal error.
+ * zc_request() may have returned without clamping the size
+ * or handling RERROR/RLERROR, so only accept a response
+ * within in_hdrlen.
+ */
+ if (READ_ONCE(req->status) == REQ_STATUS_RCVD) {
+ /* echoes to wmb() in the callback */
+ smp_rmb();
+ if (req->rc.size <= in_hdrlen)
+ err = 0;
+ }
}
recalc_sigpending:
if (sigpending) {
--
2.56.1