[PATCH v2 4/5] 9p/virtio: set REQ_STATUS_SENT after adding a zero-copy request

From: Lianjie Wang

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


p9_virtio_zc_request() sets REQ_STATUS_SENT before adding the request to
the virtqueue. If the wait for the ring is interrupted by a fatal
signal, it drops the virtio transport's reference to the request, since
the reply won't come, and returns -ERESTARTSYS. p9_client_zc_rpc()
flushes the request on -ERESTARTSYS, and p9_client_flush() calls
p9_virtio_cancelled() for a request in REQ_STATUS_SENT, which can drop
the reference again:

refcount_t: underflow; use-after-free.
WARNING: lib/refcount.c:37 at refcount_warn_saturate+0x84/0xd0, CPU#3: dd/314
Call Trace:
p9_req_put+0xe5/0x190
p9_client_zc_rpc+0x537/0x980
p9_client_read_once+0x237/0x6c0
p9_client_read+0x9d/0x140

Fix this by setting REQ_STATUS_SENT after virtqueue_add_sgs() succeeds,
so p9_virtio_cancelled() is not called for a request outside the
virtqueue. The status is set under chan->lock, before req_done() can
set REQ_STATUS_RCVD.

This patch is assisted by Claude Fable 5.2.

Fixes: 728356dedeff ("9p: Add refcount to p9_req_t")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lianjie Wang <lian@xxxxxxxxxxxxxxxxxx>
---
v2:
- New patch.

net/9p/trans_virtio.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c
index 8d9555e64490e..6d1e6093db095 100644
--- a/net/9p/trans_virtio.c
+++ b/net/9p/trans_virtio.c
@@ -467,7 +467,6 @@ p9_virtio_zc_request(struct p9_client *client, struct p9_req_t *req,
inlen = n;
}
}
- WRITE_ONCE(req->status, REQ_STATUS_SENT);
req_retry_pinned:
spin_lock_irqsave(&chan->lock, flags);

@@ -526,6 +525,7 @@ p9_virtio_zc_request(struct p9_client *client, struct p9_req_t *req,
goto err_out;
}
}
+ WRITE_ONCE(req->status, REQ_STATUS_SENT);
virtqueue_kick(chan->vq);
spin_unlock_irqrestore(&chan->lock, flags);
kicked = 1;
--
2.56.1