netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Julian Anastasov <ja@ssi.bg>
To: netdev@vger.kernel.org
Subject: [PATCH net 3/6] ipv4: add check if nh_pcpu_rth_output is allocated
Date: Sun,  7 Oct 2012 14:26:05 +0300	[thread overview]
Message-ID: <1349609168-9848-4-git-send-email-ja@ssi.bg> (raw)
In-Reply-To: <1349609168-9848-1-git-send-email-ja@ssi.bg>

	Avoid NULL ptr dereference and caching if
nh_pcpu_rth_output is not allocated.

Signed-off-by: Julian Anastasov <ja@ssi.bg>
---
 net/ipv4/route.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 488a8bb..0a600cc 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -1798,18 +1798,24 @@ static struct rtable *__mkroute_output(const struct fib_result *res,
 	fnhe = NULL;
 	if (fi) {
 		struct rtable __rcu **prth;
+		struct fib_nh *nh = &FIB_RES_NH(*res);
 
-		fnhe = find_exception(&FIB_RES_NH(*res), fl4->daddr);
+		fnhe = find_exception(nh, fl4->daddr);
 		if (fnhe)
 			prth = &fnhe->fnhe_rth;
-		else
-			prth = __this_cpu_ptr(FIB_RES_NH(*res).nh_pcpu_rth_output);
+		else {
+			if (!nh->nh_pcpu_rth_output)
+				goto add;
+			prth = __this_cpu_ptr(nh->nh_pcpu_rth_output);
+		}
 		rth = rcu_dereference(*prth);
 		if (rt_cache_valid(rth)) {
 			dst_hold(&rth->dst);
 			return rth;
 		}
 	}
+
+add:
 	rth = rt_dst_alloc(dev_out,
 			   IN_DEV_CONF_GET(in_dev, NOPOLICY),
 			   IN_DEV_CONF_GET(in_dev, NOXFRM),
-- 
1.7.3.4

  parent reply	other threads:[~2012-10-07 11:20 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-07 11:26 [PATCH net 0/6] ipv4: Changes for rt_gateway Julian Anastasov
2012-10-07 11:26 ` [PATCH net 1/6] ipv4: fix sending of redirects Julian Anastasov
2012-10-08 19:16   ` David Miller
2012-10-08 20:43     ` Julian Anastasov
2012-10-08 20:41       ` David Miller
2012-10-07 11:26 ` [PATCH net 2/6] ipv4: fix forwarding for strict source routes Julian Anastasov
2012-10-07 11:26 ` Julian Anastasov [this message]
2012-10-07 13:34   ` [PATCH net 3/6] ipv4: add check if nh_pcpu_rth_output is allocated Eric Dumazet
2012-10-07 17:24     ` Julian Anastasov
2012-10-08 19:17   ` David Miller
2012-10-07 11:26 ` [PATCH net 4/6] ipv4: introduce rt_uses_gateway Julian Anastasov
2012-10-07 11:26 ` [PATCH net 5/6] ipv4: Add FLOWI_FLAG_KNOWN_NH Julian Anastasov
2012-10-07 11:26 ` [PATCH net 6/6] ipvs: fix ARP resolving for direct routing mode Julian Anastasov

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=1349609168-9848-4-git-send-email-ja@ssi.bg \
    --to=ja@ssi.bg \
    --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).