Skip to content

Commit

Permalink
sunrpc: Fix misplaced barrier in call_decode
Browse files Browse the repository at this point in the history
[ Upstream commit f8f7e0f ]

Fix a misplaced barrier in call_decode. The struct rpc_rqst is modified
as follows by xprt_complete_rqst:

req->rq_private_buf.len = copied;
/* Ensure all writes are done before we update */
/* req->rq_reply_bytes_recvd */
smp_wmb();
req->rq_reply_bytes_recvd = copied;

And currently read as follows by call_decode:

smp_rmb(); // misplaced
if (!req->rq_reply_bytes_recvd)
   goto out;
req->rq_rcv_buf.len = req->rq_private_buf.len;

This patch places the smp_rmb after the if to ensure that
rq_reply_bytes_recvd and rq_private_buf.len are read in order.

Fixes: 9ba8288 ("SUNRPC: Don't try to parse incomplete RPC messages")
Signed-off-by: Baptiste Lepers <baptiste.lepers@gmail.com>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
BLepers authored and gregkh committed May 19, 2021
1 parent 208af7f commit 60bb2ce
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions net/sunrpc/clnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -2459,12 +2459,6 @@ call_decode(struct rpc_task *task)
task->tk_flags &= ~RPC_CALL_MAJORSEEN;
}

/*
* Ensure that we see all writes made by xprt_complete_rqst()
* before it changed req->rq_reply_bytes_recvd.
*/
smp_rmb();

/*
* Did we ever call xprt_complete_rqst()? If not, we should assume
* the message is incomplete.
Expand All @@ -2473,6 +2467,11 @@ call_decode(struct rpc_task *task)
if (!req->rq_reply_bytes_recvd)
goto out;

/* Ensure that we see all writes made by xprt_complete_rqst()
* before it changed req->rq_reply_bytes_recvd.
*/
smp_rmb();

req->rq_rcv_buf.len = req->rq_private_buf.len;
trace_rpc_xdr_recvfrom(task, &req->rq_rcv_buf);

Expand Down

0 comments on commit 60bb2ce

Please sign in to comment.