Commit 94f826b8076e2cb92242061e92f21b5baa3eccc2

Authored by Eric Dumazet
Committed by David S. Miller
1 parent 50269e19ad

net: fix a potential rcu_read_lock() imbalance in rt6_fill_node()

Commit f2c31e32b378 (net: fix NULL dereferences in check_peer_redir() )
added a regression in rt6_fill_node(), leading to rcu_read_lock()
imbalance.

Thats because NLA_PUT() can make a jump to nla_put_failure label.

Fix this by using nla_put()

Many thanks to Ben Greear for his help

Reported-by: Ben Greear <greearb@candelatech.com>
Reported-by: Dave Jones <davej@redhat.com>
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Tested-by: Ben Greear <greearb@candelatech.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

Showing 1 changed file with 6 additions and 2 deletions Side-by-side Diff

... ... @@ -2474,8 +2474,12 @@
2474 2474  
2475 2475 rcu_read_lock();
2476 2476 n = dst_get_neighbour_noref(&rt->dst);
2477   - if (n)
2478   - NLA_PUT(skb, RTA_GATEWAY, 16, &n->primary_key);
  2477 + if (n) {
  2478 + if (nla_put(skb, RTA_GATEWAY, 16, &n->primary_key) < 0) {
  2479 + rcu_read_unlock();
  2480 + goto nla_put_failure;
  2481 + }
  2482 + }
2479 2483 rcu_read_unlock();
2480 2484  
2481 2485 if (rt->dst.dev)