netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ying Xue <ying.xue@windriver.com>
To: <netdev@vger.kernel.org>
Cc: <eric.dumazet@gmail.com>, <alexei@purestorage.com>,
	<joern@purestorage.com>, <ja@ssi.bg>, <davem@davemloft.net>
Subject: [PATCH net-next 1/6] net: fix a double free issue for neighbour entry
Date: Fri, 15 May 2015 14:55:41 +0800	[thread overview]
Message-ID: <1431672946-300-2-git-send-email-ying.xue@windriver.com> (raw)
In-Reply-To: <1431672946-300-1-git-send-email-ying.xue@windriver.com>

Calling __ipv4_neigh_lookup_noref() inside rcu_read_lock_bh() can
guarantee that its searched neighbour entry is not freed before RCU
grace period, but it cannot ensure that its obtained neighbour will
be freed shortly. Exactly saying, it cannot prevent neigh_destroy()
from being executed on another context at the same time. For example,
if ip_finish_output2() continues to deliver a SKB with a neighbour
entry whose refcount is zero, neigh_add_timer() may be called in
neigh_resolve_output() subsequently. As a result, neigh_add_timer()
takes refcount on the neighbour that already had a refcount of zero.
When the neighbour refcount is put before the timer's handler is
exited, neigh_destroy() is called again, meaning crash happens at the
moment.

To prevent the issue from occurring, we must check whether the refcount
of a neighbour searched by __ipv4_neigh_lookup_noref() is decremented
to zero or not. If it's zero, we should create a new one.

Reported-by: Joern Engel <joern@logfs.org>
Signed-off-by: Ying Xue <ying.xue@windriver.com>
---
 net/ipv4/ip_output.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index 2acc5dc..580dd4d 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -200,7 +200,7 @@ static inline int ip_finish_output2(struct sock *sk, struct sk_buff *skb)
 	rcu_read_lock_bh();
 	nexthop = (__force u32) rt_nexthop(rt, ip_hdr(skb)->daddr);
 	neigh = __ipv4_neigh_lookup_noref(dev, nexthop);
-	if (unlikely(!neigh))
+	if (unlikely(!neigh || !atomic_read(&neigh->refcnt)))
 		neigh = __neigh_create(&arp_tbl, &nexthop, dev, false);
 	if (!IS_ERR(neigh)) {
 		int res = dst_neigh_output(dst, neigh, skb);
-- 
1.7.9.5

  reply	other threads:[~2015-05-15  6:56 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-15  6:55 [PATCH net-next 0/6] neigh cleanups and fixes Ying Xue
2015-05-15  6:55 ` Ying Xue [this message]
2015-05-15  6:55 ` [PATCH net-next 2/6] neigh: fix a possible leak issue of neigh entry Ying Xue
2015-05-15 12:12   ` Eric Dumazet
2015-05-15 15:39     ` David Miller
2015-05-18  3:24       ` Ying Xue
2015-05-18  4:58         ` Eric Dumazet
2015-05-18  5:55           ` Ying Xue
2015-05-18 12:54             ` Eric Dumazet
2015-05-15  6:55 ` [PATCH net-next 3/6] neigh: don't delete neighbour time in neigh_destroy Ying Xue
2015-05-15  6:55 ` [PATCH net-next 4/6] neigh: align the usage of neigh timer with one of sock timer Ying Xue
2015-05-15  6:55 ` [PATCH net-next 5/6] neigh: neigh dead and timer variables should be protected under its lock Ying Xue
2015-05-15  6:55 ` [PATCH net-next 6/6] neigh: use standard interface to modify timer Ying Xue
2015-05-15 12:14 ` [PATCH net-next 0/6] neigh cleanups and fixes Eric Dumazet
2015-05-15 15:40   ` David Miller
2015-05-18  3:30   ` Ying Xue

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=1431672946-300-2-git-send-email-ying.xue@windriver.com \
    --to=ying.xue@windriver.com \
    --cc=alexei@purestorage.com \
    --cc=davem@davemloft.net \
    --cc=eric.dumazet@gmail.com \
    --cc=ja@ssi.bg \
    --cc=joern@purestorage.com \
    --cc=netdev@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).