public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: Ben Greear <greearb@candelatech.com>
Cc: David Miller <davem@davemloft.net>,
	netdev@vger.kernel.org, gregkh@linuxfoundation.org,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Dave Jones <davej@redhat.com>
Subject: [PATCH] net: fix a potential rcu_read_lock() imbalance in rt6_fill_node()
Date: Tue, 27 Mar 2012 21:53:52 +0200	[thread overview]
Message-ID: <1332878032.3547.39.camel@edumazet-glaptop> (raw)
In-Reply-To: <1332877149.3547.24.camel@edumazet-glaptop>

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>
---
 net/ipv6/route.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 24c456e..496b627 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -2474,8 +2474,12 @@ static int rt6_fill_node(struct net *net,
 
 	rcu_read_lock();
 	n = dst_get_neighbour_noref(&rt->dst);
-	if (n)
-		NLA_PUT(skb, RTA_GATEWAY, 16, &n->primary_key);
+	if (n) {
+		if (nla_put(skb, RTA_GATEWAY, 16, &n->primary_key) < 0) {
+			rcu_read_unlock();
+			goto nla_put_failure;
+		}
+	}
 	rcu_read_unlock();
 
 	if (rt->dst.dev)

  reply	other threads:[~2012-03-27 19:53 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-26 21:43 RCU lock bug in 3.0.21 (bisected to: 682cb56a, fix NULL dereferences in check_peer_redir) Ben Greear
2012-03-26 21:49 ` David Miller
2012-03-26 21:53   ` Ben Greear
2012-03-26 23:06     ` Ben Greear
2012-03-26 23:11       ` David Miller
2012-03-26 23:39       ` Eric Dumazet
2012-03-26 23:46         ` Ben Greear
2012-03-26 23:53           ` Ben Greear
2012-03-27  0:07           ` Eric Dumazet
2012-03-27  5:11             ` Paul E. McKenney
2012-03-27  5:30               ` Ben Greear
2012-03-27 16:47                 ` Paul E. McKenney
2012-03-27 16:47         ` Ben Greear
2012-03-27 18:06           ` Eric Dumazet
2012-03-27 19:39           ` Eric Dumazet
2012-03-27 19:53             ` Eric Dumazet [this message]
2012-03-27 20:07               ` [PATCH] net: fix a potential rcu_read_lock() imbalance in rt6_fill_node() Ben Greear
2012-03-27 20:17               ` Ben Greear
2012-03-27 20:25                 ` Greg KH
2012-03-27 22:22               ` David Miller
2012-03-28  0:54                 ` John Fastabend
2012-03-28  1:27                   ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1332878032.3547.39.camel@edumazet-glaptop \
    --to=eric.dumazet@gmail.com \
    --cc=davej@redhat.com \
    --cc=davem@davemloft.net \
    --cc=greearb@candelatech.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=netdev@vger.kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox