Skip to content

Commit 4cc5b44

Browse files
edumazetdavem330
authored andcommitted
inetpeer: fix RCU lookup()
Excess of seafood or something happened while I cooked the commit adding RB tree to inetpeer. Of course, RCU rules need to be respected or bad things can happen. In this particular loop, we need to read *pp once per iteration, not twice. Fixes: b145425 ("inetpeer: remove AVL implementation in favor of RB tree") Reported-by: John Sperbeck <jsperbeck@google.com> Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent bbd9644 commit 4cc5b44

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

net/ipv4/inetpeer.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,18 @@ static struct inet_peer *lookup(const struct inetpeer_addr *daddr,
102102
struct rb_node **parent_p,
103103
struct rb_node ***pp_p)
104104
{
105-
struct rb_node **pp, *parent;
105+
struct rb_node **pp, *parent, *next;
106106
struct inet_peer *p;
107107

108108
pp = &base->rb_root.rb_node;
109109
parent = NULL;
110-
while (*pp) {
110+
while (1) {
111111
int cmp;
112112

113-
parent = rcu_dereference_raw(*pp);
113+
next = rcu_dereference_raw(*pp);
114+
if (!next)
115+
break;
116+
parent = next;
114117
p = rb_entry(parent, struct inet_peer, rb_node);
115118
cmp = inetpeer_addr_cmp(daddr, &p->daddr);
116119
if (cmp == 0) {

0 commit comments

Comments
 (0)