Skip to contentSkip to conversation

sunrpc: clear rq_procinfo in svc_release_rqst to prevent double-free

PATCH In review Ren Wei 3 participants 3 messages May 20 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Ren Wei

author
#1 lore raw

PATCH 1/1 sunrpc: clear rq_procinfo in svc_release_rqst to prevent double-free

From: Luxiao Xu <[email protected]>

The svc_release_rqst() function unconditionally calls rqstp->rq_procinfo->pc_release. However, svc_process_common() does not clear rq_procinfo when a worker thread starts processing a new request.

If a previous RPC selected a procedure with a non-idempotent release hook, and the subsequent RPC takes an early error path before a new rq_procinfo is installed (e.g., due to an oversized RPC fragment, bad auth, or unknown program), the stale release hook will run against reused state from the earlier RPC. This leads to a double-free or use-after-free vulnerability.

Fix this by setting rqstp->rq_procinfo to NULL immediately after executing the release hook in svc_release_rqst(), ensuring that stale procedure hooks cannot be re-triggered on early errors.

Fixes d9adbb6e10bf ("sunrpc: delay pc_release callback until after the reply is sent")
---
 net/sunrpc/svc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/sunrpc/svc.c +3 -1
index d8ccb8e4b5c2..0332f05e7061 100644
@@ -1572,8 +1572,10 @@ static void svc_release_rqst(struct svc_rqst *rqstp)
 {
 	const struct svc_procedure *procp = rqstp->rq_procinfo;
 
-	if (procp && procp->pc_release)
+	if (procp && procp->pc_release) {
 		procp->pc_release(rqstp);
+		rqstp->rq_procinfo = NULL;
+	}
 }
 
 /**
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/1
#2 lore raw
Quoted 36 lines · Ren Wei

From: Luxiao Xu <[email protected]>

The svc_release_rqst() function unconditionally calls rqstp->rq_procinfo->pc_release. However, svc_process_common() does not clear rq_procinfo when a worker thread starts processing a new request.

If a previous RPC selected a procedure with a non-idempotent release hook, and the subsequent RPC takes an early error path before a new rq_procinfo is installed (e.g., due to an oversized RPC fragment, bad auth, or unknown program), the stale release hook will run against reused state from the earlier RPC. This leads to a double-free or use-after-free vulnerability.

Fix this by setting rqstp->rq_procinfo to NULL immediately after executing the release hook in svc_release_rqst(), ensuring that stale procedure hooks cannot be re-triggered on early errors.

Fixes d9adbb6e10bf ("sunrpc: delay pc_release callback until after the reply is sent")
---
 net/sunrpc/svc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/sunrpc/svc.c +0 -0
index d8ccb8e4b5c2..0332f05e7061 100644
@@ -1572,8 +1572,10 @@ static void svc_release_rqst(struct svc_rqst *rqstp)
 {

net/sunrpc/svc.c static void svc_release_rqst(struct svc_rqst *rqstp) · line 1581

Quoted 10 lines
net/sunrpc/svc.c +3 -1
 	const struct svc_procedure *procp = rqstp->rq_procinfo;
 
-	if (procp && procp->pc_release)
+	if (procp && procp->pc_release) {
 		procp->pc_release(rqstp);
+		rqstp->rq_procinfo = NULL;
+	}
 }
 
 /**
maintainer
#3 lore raw
In reply to Ren Wei
Quoted 49 lines · Ren Wei

From: Luxiao Xu <[email protected]>

The svc_release_rqst() function unconditionally calls rqstp->rq_procinfo->pc_release. However, svc_process_common() does not clear rq_procinfo when a worker thread starts processing a new request.

If a previous RPC selected a procedure with a non-idempotent release hook, and the subsequent RPC takes an early error path before a new rq_procinfo is installed (e.g., due to an oversized RPC fragment, bad auth, or unknown program), the stale release hook will run against reused state from the earlier RPC. This leads to a double-free or use-after-free vulnerability.

Fix this by setting rqstp->rq_procinfo to NULL immediately after executing the release hook in svc_release_rqst(), ensuring that stale procedure hooks cannot be re-triggered on early errors.

Fixes d9adbb6e10bf ("sunrpc: delay pc_release callback until after the

reply is sent")

---
 net/sunrpc/svc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/sunrpc/svc.c +3 -1
index d8ccb8e4b5c2..0332f05e7061 100644
@@ -1572,8 +1572,10 @@ static void svc_release_rqst(struct svc_rqst *rqstp)
 {
 	const struct svc_procedure *procp = rqstp->rq_procinfo;
 
-	if (procp && procp->pc_release)
+	if (procp && procp->pc_release) {
 		procp->pc_release(rqstp);
+		rqstp->rq_procinfo = NULL;
+	}
 }
 
 /**
Signature · 1 line
2.43.0

We should harden this fix a bit by extending it so that:

- svc_release_rqst() /always/ clears rq_procinfo after the optional pc_release() call, not only when pc_release exists.
- svc_process() clears rq_procinfo at request entry before early decode/drop paths.
- svc_process_bc() does the same before its early backchannel decode return.

That makes the lifecycle explicit: each request starts with no selected proc, pg_init_request() installs one, svc_release_rqst() consumes it. It guarantees that the error flows in svc_process() won't encounter a non-NULL rq_procinfo pointer when there is nothing to release.

Can you respin your patch with those changes?

Signature · 1 line
Chuck Lever