Skip to content

Commit c2dc3e5

Browse files
Trond Myklebustamschuma-ntap
authored andcommitted
SUNRPC: Fix potential memory corruption
We really should not call rpc_wake_up_queued_task_set_status() with xprt->snd_task as an argument unless we are certain that is actually an rpc_task. Fixes: 0445f92 ("SUNRPC: Fix disconnection races") Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com> Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
1 parent d6236a9 commit c2dc3e5

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

‎include/linux/sunrpc/xprt.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ void xprt_release_write(struct rpc_xprt *, struct rpc_task *);
432432
#define XPRT_CONGESTED (9)
433433
#define XPRT_CWND_WAIT (10)
434434
#define XPRT_WRITE_SPACE (11)
435+
#define XPRT_SND_IS_COOKIE (12)
435436

436437
static inline void xprt_set_connected(struct rpc_xprt *xprt)
437438
{

‎net/sunrpc/xprt.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -775,9 +775,9 @@ void xprt_force_disconnect(struct rpc_xprt *xprt)
775775
/* Try to schedule an autoclose RPC call */
776776
if (test_and_set_bit(XPRT_LOCKED, &xprt->state) == 0)
777777
queue_work(xprtiod_workqueue, &xprt->task_cleanup);
778-
else if (xprt->snd_task)
778+
else if (xprt->snd_task && !test_bit(XPRT_SND_IS_COOKIE, &xprt->state))
779779
rpc_wake_up_queued_task_set_status(&xprt->pending,
780-
xprt->snd_task, -ENOTCONN);
780+
xprt->snd_task, -ENOTCONN);
781781
spin_unlock(&xprt->transport_lock);
782782
}
783783
EXPORT_SYMBOL_GPL(xprt_force_disconnect);
@@ -866,6 +866,7 @@ bool xprt_lock_connect(struct rpc_xprt *xprt,
866866
goto out;
867867
if (xprt->snd_task != task)
868868
goto out;
869+
set_bit(XPRT_SND_IS_COOKIE, &xprt->state);
869870
xprt->snd_task = cookie;
870871
ret = true;
871872
out:
@@ -881,6 +882,7 @@ void xprt_unlock_connect(struct rpc_xprt *xprt, void *cookie)
881882
if (!test_bit(XPRT_LOCKED, &xprt->state))
882883
goto out;
883884
xprt->snd_task =NULL;
885+
clear_bit(XPRT_SND_IS_COOKIE, &xprt->state);
884886
xprt->ops->release_xprt(xprt, NULL);
885887
xprt_schedule_autodisconnect(xprt);
886888
out:

0 commit comments

Comments
 (0)