]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commitdiff
net_sched: fix use of uninitialized ethertype variable in cls_flower
authorArnd Bergmann <arnd@arndb.de>
Fri, 26 Aug 2016 15:25:45 +0000 (17:25 +0200)
committerDavid S. Miller <davem@davemloft.net>
Mon, 29 Aug 2016 04:30:23 +0000 (00:30 -0400)
The addition of VLAN support caused a possible use of uninitialized
data if we encounter a zero TCA_FLOWER_KEY_ETH_TYPE key, as pointed
out by "gcc -Wmaybe-uninitialized":

net/sched/cls_flower.c: In function 'fl_change':
net/sched/cls_flower.c:366:22: error: 'ethertype' may be used uninitialized in this function [-Werror=maybe-uninitialized]

This changes the code to only set the ethertype field if it
was nonzero, as before the patch.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Fixes: 9399ae9a6cb2 ("net_sched: flower: Add vlan support")
Cc: Hadar Hen Zion <hadarh@mellanox.com>
Cc: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/sched/cls_flower.c

index 532ab67513437400983f1007dcea89c79ede64cc..cf9ad5b508899d4fb0ba812a84647a916c3d5f31 100644 (file)
@@ -353,18 +353,19 @@ static int fl_set_key(struct net *net, struct nlattr **tb,
                       mask->eth.src, TCA_FLOWER_KEY_ETH_SRC_MASK,
                       sizeof(key->eth.src));
 
-       if (tb[TCA_FLOWER_KEY_ETH_TYPE])
+       if (tb[TCA_FLOWER_KEY_ETH_TYPE]) {
                ethertype = nla_get_be16(tb[TCA_FLOWER_KEY_ETH_TYPE]);
 
-       if (ethertype == htons(ETH_P_8021Q)) {
-               fl_set_key_vlan(tb, &key->vlan, &mask->vlan);
-               fl_set_key_val(tb, &key->basic.n_proto,
-                              TCA_FLOWER_KEY_VLAN_ETH_TYPE,
-                              &mask->basic.n_proto, TCA_FLOWER_UNSPEC,
-                              sizeof(key->basic.n_proto));
-       } else {
-               key->basic.n_proto = ethertype;
-               mask->basic.n_proto = cpu_to_be16(~0);
+               if (ethertype == htons(ETH_P_8021Q)) {
+                       fl_set_key_vlan(tb, &key->vlan, &mask->vlan);
+                       fl_set_key_val(tb, &key->basic.n_proto,
+                                      TCA_FLOWER_KEY_VLAN_ETH_TYPE,
+                                      &mask->basic.n_proto, TCA_FLOWER_UNSPEC,
+                                      sizeof(key->basic.n_proto));
+               } else {
+                       key->basic.n_proto = ethertype;
+                       mask->basic.n_proto = cpu_to_be16(~0);
+               }
        }
 
        if (key->basic.n_proto == htons(ETH_P_IP) ||