net: rtnl: avoid uninitialized data in IFLA_VF_VLAN_LIST handling
authorArnd Bergmann <arnd@arndb.de>
Fri, 30 Sep 2016 16:13:49 +0000 (18:13 +0200)
committerDavid S. Miller <davem@davemloft.net>
Mon, 3 Oct 2016 05:31:48 +0000 (01:31 -0400)
With the newly added support for IFLA_VF_VLAN_LIST netlink messages,
we get a warning about potential uninitialized variable use in
the parsing of the user input when enabling the -Wmaybe-uninitialized
warning:

net/core/rtnetlink.c: In function 'do_setvfinfo':
net/core/rtnetlink.c:1756:9: error: 'ivvl$' may be used uninitialized in this function [-Werror=maybe-uninitialized]

I have not been able to prove whether it is possible to arrive in
this code with an empty IFLA_VF_VLAN_LIST block, but if we do,
then ndo_set_vf_vlan gets called with uninitialized arguments.

This adds an explicit check for an empty list, making it obvious
to the reader and the compiler that this cannot happen.

Fixes: 79aab093a0b5 ("net: Update API for VF vlan protocol 802.1ad support")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Moshe Shemesh <moshe@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/core/rtnetlink.c

index 3ac8946bf2449c5634be0cf7b8352ddf67592ee5..b06d2f46b83e98c4fb6a92cefd625c2918eafdeb 100644 (file)
@@ -1753,6 +1753,9 @@ static int do_setvfinfo(struct net_device *dev, struct nlattr **tb)
 
                        len++;
                }
+               if (len == 0)
+                       return -EINVAL;
+
                err = ops->ndo_set_vf_vlan(dev, ivvl[0]->vf, ivvl[0]->vlan,
                                           ivvl[0]->qos, ivvl[0]->vlan_proto);
                if (err < 0)