* [PATCH] tipc: Fix tipc_sk_reinit handling of -EAGAIN
[not found] <1907606232.1152250.1503498773672.JavaMail.zimbra@redhat.com>
@ 2017-08-23 14:43 ` Bob Peterson
2017-08-24 13:10 ` Herbert Xu
2017-08-24 21:02 ` David Miller
0 siblings, 2 replies; 3+ messages in thread
From: Bob Peterson @ 2017-08-23 14:43 UTC (permalink / raw)
To: herbert, Phil Sutter, davem, netdev; +Cc: LKML
Hi,
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().
Signed-off-by: Bob Peterson <rpeterso@redhat.com>
---
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 101e3597338f..d50edd6e0019 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -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));
}
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] tipc: Fix tipc_sk_reinit handling of -EAGAIN
2017-08-23 14:43 ` [PATCH] tipc: Fix tipc_sk_reinit handling of -EAGAIN Bob Peterson
@ 2017-08-24 13:10 ` Herbert Xu
2017-08-24 21:02 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: Herbert Xu @ 2017-08-24 13:10 UTC (permalink / raw)
To: Bob Peterson; +Cc: Phil Sutter, davem, netdev, LKML
On Wed, Aug 23, 2017 at 10:43:02AM -0400, Bob Peterson wrote:
> Hi,
>
> 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().
>
> Signed-off-by: Bob Peterson <rpeterso@redhat.com>
Acked-by: Herbert Xu <herbert@gondor.apana.org.au>
Thanks for catching this!
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] tipc: Fix tipc_sk_reinit handling of -EAGAIN
2017-08-23 14:43 ` [PATCH] tipc: Fix tipc_sk_reinit handling of -EAGAIN Bob Peterson
2017-08-24 13:10 ` Herbert Xu
@ 2017-08-24 21:02 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2017-08-24 21:02 UTC (permalink / raw)
To: rpeterso; +Cc: herbert, psutter, netdev, linux-kernel
From: Bob Peterson <rpeterso@redhat.com>
Date: Wed, 23 Aug 2017 10:43:02 -0400 (EDT)
> 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().
>
> Signed-off-by: Bob Peterson <rpeterso@redhat.com>
Applied and queued up for -stable, thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-08-24 21:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <1907606232.1152250.1503498773672.JavaMail.zimbra@redhat.com>
2017-08-23 14:43 ` [PATCH] tipc: Fix tipc_sk_reinit handling of -EAGAIN Bob Peterson
2017-08-24 13:10 ` Herbert Xu
2017-08-24 21:02 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).