lwtunnel: check return value of nla_nest_start
authorPan Bian <bianpan2016@163.com>
Sun, 23 Apr 2017 06:28:37 +0000 (14:28 +0800)
committerDavid S. Miller <davem@davemloft.net>
Mon, 24 Apr 2017 19:51:30 +0000 (15:51 -0400)
Function nla_nest_start() may return a NULL pointer on error. However,
in function lwtunnel_fill_encap(), the return value of nla_nest_start()
is not validated before it is used. This patch checks the return value
of nla_nest_start() against NULL.

Signed-off-by: Pan Bian <bianpan2016@163.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/core/lwtunnel.c

index b5888190223c4d3978639c81fdec3a19dd6ee8f2..5cbed381622977abb03f211011a2c83366cd5e1f 100644 (file)
@@ -214,6 +214,8 @@ int lwtunnel_fill_encap(struct sk_buff *skb, struct lwtunnel_state *lwtstate)
 
        ret = -EOPNOTSUPP;
        nest = nla_nest_start(skb, RTA_ENCAP);
+       if (!nest)
+               goto nla_put_failure;
        rcu_read_lock();
        ops = rcu_dereference(lwtun_encaps[lwtstate->type]);
        if (likely(ops && ops->fill_encap))