From patchwork Sun Oct 7 11:26:05 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [net,3/6] ipv4: add check if nh_pcpu_rth_output is allocated Date: Sun, 07 Oct 2012 01:26:05 -0000 From: Julian Anastasov X-Patchwork-Id: 189803 Message-Id: <1349609168-9848-4-git-send-email-ja@ssi.bg> To: netdev@vger.kernel.org Avoid NULL ptr dereference and caching if nh_pcpu_rth_output is not allocated. Signed-off-by: Julian Anastasov --- 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),