Skip to content

Commit 87ed500

Browse files
Trond MyklebustTrond Myklebust
authored andcommitted
SUNRPC: Ensure we release the socket write lock if the rpc_task exits early
If the rpc_task exits while holding the socket write lock before it has allocated an rpc slot, then the usual mechanism for releasing the write lock in xprt_release() is defeated. The problem occurs if the call to xprt_lock_write() initially fails, so that the rpc_task is put on the xprt->sending wait queue. If the task exits after being assigned the lock by __xprt_lock_write_func, but before it has retried the call to xprt_lock_and_alloc_slot(), then it calls xprt_release() while holding the write lock, but will immediately exit due to the test for task->tk_rqstp != NULL. Reported-by: Chris Perl <[email protected]> Signed-off-by: Trond Myklebust <[email protected]> Cc: [email protected] [>= 3.1]
1 parent d287b87 commit 87ed500

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

net/sunrpc/sched.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -972,8 +972,7 @@ static void rpc_async_release(struct work_struct *work)
972972

973973
static void rpc_release_resources_task(struct rpc_task *task)
974974
{
975-
if (task->tk_rqstp)
976-
xprt_release(task);
975+
xprt_release(task);
977976
if (task->tk_msg.rpc_cred) {
978977
put_rpccred(task->tk_msg.rpc_cred);
979978
task->tk_msg.rpc_cred = NULL;

net/sunrpc/xprt.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,10 +1136,18 @@ static void xprt_request_init(struct rpc_task *task, struct rpc_xprt *xprt)
11361136
void xprt_release(struct rpc_task *task)
11371137
{
11381138
struct rpc_xprt *xprt;
1139-
struct rpc_rqst *req;
1139+
struct rpc_rqst *req = task->tk_rqstp;
11401140

1141-
if (!(req = task->tk_rqstp))
1141+
if (req == NULL) {
1142+
if (task->tk_client) {
1143+
rcu_read_lock();
1144+
xprt = rcu_dereference(task->tk_client->cl_xprt);
1145+
if (xprt->snd_task == task)
1146+
xprt_release_write(xprt, task);
1147+
rcu_read_unlock();
1148+
}
11421149
return;
1150+
}
11431151

11441152
xprt = req->rq_xprt;
11451153
if (task->tk_ops->rpc_count_stats != NULL)

0 commit comments

Comments
 (0)