sunrpc: clear rq_procinfo in svc_release_rqst to prevent double-free
Subsystems (4)
A message that is not in the archive (sent off-list or not yet received): [email protected]
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.
--- net/sunrpc/svc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/sunrpc/svc.c +3 -1
@@ -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
Quoted 36 lines · Ren Wei
From: Luxiao Xu <[email protected]>
The
svc_release_rqst()function unconditionally callsrqstp->rq_procinfo->pc_release. However,svc_process_common()does not clearrq_procinfowhen 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_procinfois 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_procinfoto NULL immediately after executing the release hook insvc_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")Reported-by Yuan Tan <[email protected]>Reported-by Yifan Wu <[email protected]>Reported-by Juefei Pu <[email protected]>Reported-by Xin Liu <[email protected]>Signed-off-by Luxiao Xu <[email protected]>Signed-off-by Ren Wei <[email protected]>--- net/sunrpc/svc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)net/sunrpc/svc.c +0
-0@@ -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
-1const 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 ; + } }/**
Chuck Lever
maintainerQuoted 49 lines · Ren Wei
From: Luxiao Xu <[email protected]>
The
svc_release_rqst()function unconditionally callsrqstp->rq_procinfo->pc_release. However,svc_process_common()does not clearrq_procinfowhen 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_procinfois 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_procinfoto NULL immediately after executing the release hook insvc_release_rqst(), ensuring that stale procedure hooks cannot be re-triggered on early errors.Fixes d9adbb6e10bf ("sunrpc: delay pc_release callback until after thereply is sent")
Reported-by Yuan Tan <[email protected]>Reported-by Yifan Wu <[email protected]>Reported-by Juefei Pu <[email protected]>Reported-by Xin Liu <[email protected]>Signed-off-by Luxiao Xu <[email protected]>Signed-off-by Ren Wei <[email protected]>--- net/sunrpc/svc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)net/sunrpc/svc.c +3
-1@@ -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