xfrm: avoid possible oopse in xfrm_alloc_dst
authorHiroaki SHIMODA <shimoda.hiroaki@gmail.com>
Fri, 11 Feb 2011 07:08:33 +0000 (23:08 -0800)
committerDavid S. Miller <davem@davemloft.net>
Fri, 11 Feb 2011 07:08:33 +0000 (23:08 -0800)
Commit 80c802f3073e84 (xfrm: cache bundles instead of policies for
outgoing flows) introduced possible oopse when dst_alloc returns NULL.

Signed-off-by: Hiroaki SHIMODA <shimoda.hiroaki@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/xfrm/xfrm_policy.c

index 8b3ef404c79441bb47e4b15225bf7eb39c0d9501..6459588befc33fc58baa4f341b04f95e7a675bca 100644 (file)
@@ -1340,10 +1340,13 @@ static inline struct xfrm_dst *xfrm_alloc_dst(struct net *net, int family)
        default:
                BUG();
        }
-       xdst = dst_alloc(dst_ops) ?: ERR_PTR(-ENOBUFS);
+       xdst = dst_alloc(dst_ops);
        xfrm_policy_put_afinfo(afinfo);
 
-       xdst->flo.ops = &xfrm_bundle_fc_ops;
+       if (likely(xdst))
+               xdst->flo.ops = &xfrm_bundle_fc_ops;
+       else
+               xdst = ERR_PTR(-ENOBUFS);
 
        return xdst;
 }