Commit 5e9a0fe4 authored by Jianbo Liu's avatar Jianbo Liu Committed by David S. Miller

net/sched: flower: Fix null pointer dereference when run tc vlan command

Zahari issued tc vlan command without setting vlan_ethtype, which will
crash kernel. To avoid this, we must check tb[TCA_FLOWER_KEY_VLAN_ETH_TYPE]
is not null before use it.
Also we don't need to dump vlan_ethtype or cvlan_ethtype in this case.

Fixes: d64efd09 ('net/sched: flower: Add supprt for matching on QinQ vlan headers')
Signed-off-by: default avatarJianbo Liu <jianbol@mellanox.com>
Reported-by: default avatarZahari Doychev <zahari.doychev@intel.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent db560d16
......@@ -605,6 +605,7 @@ static int fl_set_key(struct net *net, struct nlattr **tb,
TCA_FLOWER_KEY_VLAN_PRIO, &key->vlan,
&mask->vlan);
if (tb[TCA_FLOWER_KEY_VLAN_ETH_TYPE]) {
ethertype = nla_get_be16(tb[TCA_FLOWER_KEY_VLAN_ETH_TYPE]);
if (eth_type_vlan(ethertype)) {
fl_set_key_vlan(tb, ethertype,
......@@ -620,6 +621,7 @@ static int fl_set_key(struct net *net, struct nlattr **tb,
key->basic.n_proto = ethertype;
mask->basic.n_proto = cpu_to_be16(~0);
}
}
} else {
key->basic.n_proto = ethertype;
mask->basic.n_proto = cpu_to_be16(~0);
......@@ -1344,6 +1346,7 @@ static int fl_dump(struct net *net, struct tcf_proto *tp, void *fh,
key->cvlan.vlan_tpid)))
goto nla_put_failure;
if (mask->basic.n_proto) {
if (mask->cvlan.vlan_tpid) {
if (nla_put_be16(skb, TCA_FLOWER_KEY_CVLAN_ETH_TYPE,
key->basic.n_proto))
......@@ -1353,6 +1356,7 @@ static int fl_dump(struct net *net, struct tcf_proto *tp, void *fh,
key->basic.n_proto))
goto nla_put_failure;
}
}
if ((key->basic.n_proto == htons(ETH_P_IP) ||
key->basic.n_proto == htons(ETH_P_IPV6)) &&
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment