mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] 9p/xen: fix refcount leak in p9_xen_response() on wrong tag
@ 2026-08-04 21:35 Yifei Gao
  2026-08-05  0:06 ` Stefano Stabellini
  2026-08-06 14:42 ` [PATCH v2] " Yifei Gao
  0 siblings, 2 replies; 5+ messages in thread
From: Yifei Gao @ 2026-08-04 21:35 UTC (permalink / raw)
  To: Eric Van Hensbergen, Latchesar Ionkov, Dominique Martinet, v9fs
  Cc: Christian Schoenebeck, Juergen Gross, Boris Ostrovsky,
	Stefano Stabellini, xen-devel, linux-kernel, Yifei Gao, stable

p9_xen_response() looks up the request for an incoming reply with
p9_tag_lookup(), which takes a reference on the returned p9_req_t. When
the tag does not resolve to a request in REQ_STATUS_SENT, the function
warns and continues the loop without dropping that reference, permanently
leaking the p9_req_t and its msize buffers. The reply header, including
the tag, is supplied by the backend, so a malicious or buggy 9P backend
can leak kernel memory on every crafted response.

Drop the reference before continuing, mirroring the equivalent path in
trans_fd.c.

Fixes: f66c72bea129 ("xen/9pfs: receive responses")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Yifei Gao <gyf161023@gmail.com>
---
 net/9p/trans_xen.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/9p/trans_xen.c b/net/9p/trans_xen.c
index f9fb2db7a066..8eea0da8797f 100644
--- a/net/9p/trans_xen.c
+++ b/net/9p/trans_xen.c
@@ -203,6 +203,8 @@ static void p9_xen_response(struct work_struct *work)
 		req = p9_tag_lookup(priv->client, h.tag);
 		if (!req || req->status != REQ_STATUS_SENT) {
 			dev_warn(&priv->dev->dev, "Wrong req tag=%x\n", h.tag);
+			if (req)
+				p9_req_put(priv->client, req);
 			cons += h.size;
 			virt_mb();
 			ring->intf->in_cons = cons;
-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] 9p/xen: fix refcount leak in p9_xen_response() on wrong tag
  2026-08-04 21:35 [PATCH] 9p/xen: fix refcount leak in p9_xen_response() on wrong tag Yifei Gao
@ 2026-08-05  0:06 ` Stefano Stabellini
  2026-08-05  7:13   ` Jürgen Groß
  2026-08-06 14:42 ` [PATCH v2] " Yifei Gao
  1 sibling, 1 reply; 5+ messages in thread
From: Stefano Stabellini @ 2026-08-05  0:06 UTC (permalink / raw)
  To: Yifei Gao
  Cc: Eric Van Hensbergen, Latchesar Ionkov, Dominique Martinet, v9fs,
	Christian Schoenebeck, Juergen Gross, Boris Ostrovsky,
	Stefano Stabellini, xen-devel, linux-kernel, stable

On Tue, 4 Aug 2026, Yifei Gao wrote:
> p9_xen_response() looks up the request for an incoming reply with
> p9_tag_lookup(), which takes a reference on the returned p9_req_t. When
> the tag does not resolve to a request in REQ_STATUS_SENT, the function
> warns and continues the loop without dropping that reference, permanently
> leaking the p9_req_t and its msize buffers. The reply header, including
> the tag, is supplied by the backend, so a malicious or buggy 9P backend
> can leak kernel memory on every crafted response.

Most backend are trusted, including this. So I would avoid "malicious".


> Drop the reference before continuing, mirroring the equivalent path in
> trans_fd.c.
 
It doesn't look like trans_fd.c behaves like this patch?


> Fixes: f66c72bea129 ("xen/9pfs: receive responses")

This should be 728356dedeff

Aside from the above, the code change looks correct

Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>


> Cc: stable@vger.kernel.org
> Assisted-by: Claude:claude-opus-4-8
> Signed-off-by: Yifei Gao <gyf161023@gmail.com>
> ---
>  net/9p/trans_xen.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/net/9p/trans_xen.c b/net/9p/trans_xen.c
> index f9fb2db7a066..8eea0da8797f 100644
> --- a/net/9p/trans_xen.c
> +++ b/net/9p/trans_xen.c
> @@ -203,6 +203,8 @@ static void p9_xen_response(struct work_struct *work)
>  		req = p9_tag_lookup(priv->client, h.tag);
>  		if (!req || req->status != REQ_STATUS_SENT) {
>  			dev_warn(&priv->dev->dev, "Wrong req tag=%x\n", h.tag);
> +			if (req)
> +				p9_req_put(priv->client, req);
>  			cons += h.size;
>  			virt_mb();
>  			ring->intf->in_cons = cons;
> -- 
> 2.43.0
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] 9p/xen: fix refcount leak in p9_xen_response() on wrong tag
  2026-08-05  0:06 ` Stefano Stabellini
@ 2026-08-05  7:13   ` Jürgen Groß
  0 siblings, 0 replies; 5+ messages in thread
From: Jürgen Groß @ 2026-08-05  7:13 UTC (permalink / raw)
  To: Stefano Stabellini, Yifei Gao
  Cc: Eric Van Hensbergen, Latchesar Ionkov, Dominique Martinet, v9fs,
	Christian Schoenebeck, Boris Ostrovsky, xen-devel, linux-kernel,
	stable


[-- Attachment #1.1.1: Type: text/plain, Size: 1161 bytes --]

On 05.08.26 02:06, Stefano Stabellini wrote:
> On Tue, 4 Aug 2026, Yifei Gao wrote:
>> p9_xen_response() looks up the request for an incoming reply with
>> p9_tag_lookup(), which takes a reference on the returned p9_req_t. When
>> the tag does not resolve to a request in REQ_STATUS_SENT, the function
>> warns and continues the loop without dropping that reference, permanently
>> leaking the p9_req_t and its msize buffers. The reply header, including
>> the tag, is supplied by the backend, so a malicious or buggy 9P backend
>> can leak kernel memory on every crafted response.
> 
> Most backend are trusted, including this. So I would avoid "malicious".

No, I think this is fine.

Especially with driver domains malicious backends are a thing. They should
only be capable to deliver wrong or no data to the frontend, but ideally
the frontend should not trust the backend.

Any work towards that goal is to be supported IMHO, and there are already
frontends listed in Xen's support statement following this rule, so any
violation of that principle in those frontends will be regarded to be a
security issue worth an XSA.


Juergen

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3743 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] 9p/xen: fix refcount leak in p9_xen_response() on wrong tag
  2026-08-04 21:35 [PATCH] 9p/xen: fix refcount leak in p9_xen_response() on wrong tag Yifei Gao
  2026-08-05  0:06 ` Stefano Stabellini
@ 2026-08-06 14:42 ` Yifei Gao
  2026-09-13  9:57   ` Dominique Martinet
  1 sibling, 1 reply; 5+ messages in thread
From: Yifei Gao @ 2026-08-06 14:42 UTC (permalink / raw)
  To: Eric Van Hensbergen, Latchesar Ionkov, Dominique Martinet, v9fs
  Cc: Christian Schoenebeck, Juergen Gross, Boris Ostrovsky,
	Stefano Stabellini, xen-devel, linux-kernel, stable, Yifei Gao

p9_xen_response() looks up the request for an incoming reply with
p9_tag_lookup(), which takes a reference on the returned p9_req_t. When
the tag does not resolve to a request in REQ_STATUS_SENT, the function
warns and continues the loop without dropping that reference, permanently
leaking the p9_req_t and its msize buffers. The reply header, including
the tag, is supplied by the backend, so a malicious or buggy 9P backend
can leak kernel memory on every crafted response.

Drop the reference before continuing.

Fixes: 728356dedeff ("9p: Add refcount to p9_req_t")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Yifei Gao <gyf161023@gmail.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
v2:
  - Fix Fixes: tag to reference the correct commit (728356dedeff).
  - Drop the inaccurate trans_fd.c comparison from the changelog.
  - Add Reviewed-by from Stefano.


 net/9p/trans_xen.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/9p/trans_xen.c b/net/9p/trans_xen.c
index f9fb2db7a066..8eea0da8797f 100644
--- a/net/9p/trans_xen.c
+++ b/net/9p/trans_xen.c
@@ -203,6 +203,8 @@ static void p9_xen_response(struct work_struct *work)
 		req = p9_tag_lookup(priv->client, h.tag);
 		if (!req || req->status != REQ_STATUS_SENT) {
 			dev_warn(&priv->dev->dev, "Wrong req tag=%x\n", h.tag);
+			if (req)
+				p9_req_put(priv->client, req);
 			cons += h.size;
 			virt_mb();
 			ring->intf->in_cons = cons;
-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] 9p/xen: fix refcount leak in p9_xen_response() on wrong tag
  2026-08-06 14:42 ` [PATCH v2] " Yifei Gao
@ 2026-09-13  9:57   ` Dominique Martinet
  0 siblings, 0 replies; 5+ messages in thread
From: Dominique Martinet @ 2026-09-13  9:57 UTC (permalink / raw)
  To: Yifei Gao
  Cc: Eric Van Hensbergen, Latchesar Ionkov, v9fs,
	Christian Schoenebeck, Juergen Gross, Boris Ostrovsky,
	Stefano Stabellini, xen-devel, linux-kernel, stable

Yifei Gao wrote on Thu, Aug 06, 2026 at 02:42:54PM +0000:
> p9_xen_response() looks up the request for an incoming reply with
> p9_tag_lookup(), which takes a reference on the returned p9_req_t. When
> the tag does not resolve to a request in REQ_STATUS_SENT, the function
> warns and continues the loop without dropping that reference, permanently
> leaking the p9_req_t and its msize buffers. The reply header, including
> the tag, is supplied by the backend, so a malicious or buggy 9P backend
> can leak kernel memory on every crafted response.
> 
> Drop the reference before continuing.
> 
> Fixes: 728356dedeff ("9p: Add refcount to p9_req_t")
> Cc: stable@vger.kernel.org
> Assisted-by: Claude:claude-opus-4-8
> Signed-off-by: Yifei Gao <gyf161023@gmail.com>
> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>

Thanks, I've picked this up for 7.4

If someone is interested in the 9pfs xen backend security then sashiko
had a lot of "pre-existing issues" to talk about[1]... I tend to agree
with Stefano's point of view that the 9p backend is mostly trusted
though, so I'll take patches if someone wants to spend the effort, but
won't actively be able to contribute much more.

[1] https://sashiko.dev/#/patchset/20260806144255.4167019-1-gyf161023@gmail.com

-- 
Dominique

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-09-13  9:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-04 21:35 [PATCH] 9p/xen: fix refcount leak in p9_xen_response() on wrong tag Yifei Gao
2026-08-05  0:06 ` Stefano Stabellini
2026-08-05  7:13   ` Jürgen Groß
2026-08-06 14:42 ` [PATCH v2] " Yifei Gao
2026-09-13  9:57   ` Dominique Martinet

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®