Skip to content

Commit

Permalink
SUNRPC: Fix suspicious RCU usage
Browse files Browse the repository at this point in the history
We need to hold the rcu_read_lock() when calling rcu_dereference(),
otherwise we can't guarantee that the object being dereferenced still
exists.

Fixes: 39e5d2d ("SUNRPC search xprt switch for sockaddr")
Signed-off-by: Anna Schumaker <[email protected]>
  • Loading branch information
amschuma-ntap committed Nov 7, 2016
1 parent 68a5640 commit bb29dd8
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions net/sunrpc/clnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -2753,14 +2753,18 @@ EXPORT_SYMBOL_GPL(rpc_cap_max_reconnect_timeout);

void rpc_clnt_xprt_switch_put(struct rpc_clnt *clnt)
{
rcu_read_lock();
xprt_switch_put(rcu_dereference(clnt->cl_xpi.xpi_xpswitch));
rcu_read_unlock();
}
EXPORT_SYMBOL_GPL(rpc_clnt_xprt_switch_put);

void rpc_clnt_xprt_switch_add_xprt(struct rpc_clnt *clnt, struct rpc_xprt *xprt)
{
rcu_read_lock();
rpc_xprt_switch_add_xprt(rcu_dereference(clnt->cl_xpi.xpi_xpswitch),
xprt);
rcu_read_unlock();
}
EXPORT_SYMBOL_GPL(rpc_clnt_xprt_switch_add_xprt);

Expand All @@ -2770,9 +2774,8 @@ bool rpc_clnt_xprt_switch_has_addr(struct rpc_clnt *clnt,
struct rpc_xprt_switch *xps;
bool ret;

xps = rcu_dereference(clnt->cl_xpi.xpi_xpswitch);

rcu_read_lock();
xps = rcu_dereference(clnt->cl_xpi.xpi_xpswitch);
ret = rpc_xprt_switch_has_addr(xps, sap);
rcu_read_unlock();
return ret;
Expand Down

0 comments on commit bb29dd8

Please sign in to comment.