Skip to content

Commit d3f8727

Browse files
idoschdavem330
authored andcommitted
net/sched: flower: Ensure both minimum and maximum ports are specified
The kernel does not currently validate that both the minimum and maximum ports of a port range are specified. This can lead user space to think that a filter matching on a port range was successfully added, when in fact it was not. For example, with a patched (buggy) iproute2 that only sends the minimum port, the following commands do not return an error: # tc filter add dev swp1 ingress pref 1 proto ip flower ip_proto udp src_port 100-200 action pass # tc filter add dev swp1 ingress pref 1 proto ip flower ip_proto udp dst_port 100-200 action pass # tc filter show dev swp1 ingress filter protocol ip pref 1 flower chain 0 filter protocol ip pref 1 flower chain 0 handle 0x1 eth_type ipv4 ip_proto udp not_in_hw action order 1: gact action pass random type none pass val 0 index 1 ref 1 bind 1 filter protocol ip pref 1 flower chain 0 handle 0x2 eth_type ipv4 ip_proto udp not_in_hw action order 1: gact action pass random type none pass val 0 index 2 ref 1 bind 1 Fix by returning an error unless both ports are specified: # tc filter add dev swp1 ingress pref 1 proto ip flower ip_proto udp src_port 100-200 action pass Error: Both min and max source ports must be specified. We have an error talking to the kernel # tc filter add dev swp1 ingress pref 1 proto ip flower ip_proto udp dst_port 100-200 action pass Error: Both min and max destination ports must be specified. We have an error talking to the kernel Fixes: 5c72299 ("net: sched: cls_flower: Classify packets using port ranges") Signed-off-by: Ido Schimmel <[email protected]> Reviewed-by: Petr Machata <[email protected]> Acked-by: Jamal Hadi Salim <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b6c9ebd commit d3f8727

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

net/sched/cls_flower.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,16 @@ static int fl_set_key_port_range(struct nlattr **tb, struct fl_flow_key *key,
812812
TCA_FLOWER_KEY_PORT_SRC_MAX, &mask->tp_range.tp_max.src,
813813
TCA_FLOWER_UNSPEC, sizeof(key->tp_range.tp_max.src));
814814

815+
if (mask->tp_range.tp_min.dst != mask->tp_range.tp_max.dst) {
816+
NL_SET_ERR_MSG(extack,
817+
"Both min and max destination ports must be specified");
818+
return -EINVAL;
819+
}
820+
if (mask->tp_range.tp_min.src != mask->tp_range.tp_max.src) {
821+
NL_SET_ERR_MSG(extack,
822+
"Both min and max source ports must be specified");
823+
return -EINVAL;
824+
}
815825
if (mask->tp_range.tp_min.dst && mask->tp_range.tp_max.dst &&
816826
ntohs(key->tp_range.tp_max.dst) <=
817827
ntohs(key->tp_range.tp_min.dst)) {

0 commit comments

Comments
 (0)