tipc: Fix tipc_sk_reinit handling of -EAGAIN
Subsystems (3)
PATCH 1/1 tipc: Fix tipc_sk_reinit handling of -EAGAIN
In reply to a message not in the archiveHi,
In 9dbbfb0ab6680c6a85609041011484e6658e7d3c function tipc_sk_reinit had additional logic added to loop in the event that function rhashtable_walk_next() returned -EAGAIN. No worries.
However, if rhashtable_walk_start returns -EAGAIN, it does "continue", and therefore skips the call to rhashtable_walk_stop(). That has the effect of calling rcu_read_lock() without its paired call to rcu_read_unlock(). Since rcu_read_lock() may be nested, the problem may not be apparent for a while, especially since resize events may be rare. But the comments to rhashtable_walk_start() state:
* ...Note that we take the RCU lock in all
* cases including when we return an error. So you must always call
* rhashtable_walk_stop to clean up.
This patch replaces the continue with a goto and label to ensure a matching call to rhashtable_walk_stop().
---
net/tipc/socket.c +3 -3
@@ -2255,8 +2255,8 @@ void tipc_sk_reinit(struct net *net) do { tsk = ERR_PTR(rhashtable_walk_start(&iter)); - if (tsk) - continue; + if (IS_ERR(tsk)) + goto walk_stop; while ((tsk = rhashtable_walk_next(&iter)) && !IS_ERR(tsk)) { spin_lock_bh(&tsk->sk.sk_lock.slock);
@@ -2265,7 +2265,7 @@ void tipc_sk_reinit(struct net *net)msg_set_orignode (msg, tn->own_addr);spin_unlock_bh (&tsk->sk.sk_lock.slock); } - +walk_stop:rhashtable_walk_stop (&iter); }while (tsk ==ERR_PTR (-EAGAIN )); }
Quoted 13 lines · Bob Peterson
Hi,
In
9dbbfb0ab6680c6a85609041011484e6658e7d3cfunctiontipc_sk_reinithad additional logic added to loop in the event that functionrhashtable_walk_next()returned-EAGAIN. No worries.However, if
rhashtable_walk_startreturns-EAGAIN, it does "continue", and therefore skips the call torhashtable_walk_stop(). That has the effect of callingrcu_read_lock()without its paired call torcu_read_unlock(). Sincercu_read_lock()may be nested, the problem may not be apparent for a while, especially since resize events may be rare. But the comments torhashtable_walk_start()state:
Quoted 8 lines
* ...Note that we take the RCU lock in all
* cases including when we return an error. So you must always call
*rhashtable_walk_stopto clean up.This patch replaces the continue with a goto and label to ensure a matching call to
rhashtable_walk_stop().Signed-off-by Bob Peterson <[email protected]>
Thanks for catching this!
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
David Miller
maintainerFrom: Bob Peterson <[email protected]>
Date: Wed, 23 Aug 2017 10:43:02 -0400 (EDT)
Quoted 11 lines
In
9dbbfb0ab6680c6a85609041011484e6658e7d3cfunctiontipc_sk_reinithad additional logic added to loop in the event that functionrhashtable_walk_next()returned-EAGAIN. No worries.However, if
rhashtable_walk_startreturns-EAGAIN, it does "continue", and therefore skips the call torhashtable_walk_stop(). That has the effect of callingrcu_read_lock()without its paired call torcu_read_unlock(). Sincercu_read_lock()may be nested, the problem may not be apparent for a while, especially since resize events may be rare. But the comments torhashtable_walk_start()state:
Quoted 8 lines
* ...Note that we take the RCU lock in all
* cases including when we return an error. So you must always call
*rhashtable_walk_stopto clean up.This patch replaces the continue with a goto and label to ensure a matching call to
rhashtable_walk_stop().Signed-off-by Bob Peterson <[email protected]>
Applied and queued up for -stable, thanks.