]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
net: sched: correct flower port blocking
authorJason Baron <jbaron@akamai.com>
Mon, 17 Feb 2020 20:38:09 +0000 (15:38 -0500)
committerDavid S. Miller <davem@davemloft.net>
Tue, 18 Feb 2020 05:33:28 +0000 (21:33 -0800)
tc flower rules that are based on src or dst port blocking are sometimes
ineffective due to uninitialized stack data. __skb_flow_dissect() extracts
ports from the skb for tc flower to match against. However, the port
dissection is not done when when the FLOW_DIS_IS_FRAGMENT bit is set in
key_control->flags. All callers of __skb_flow_dissect(), zero-out the
key_control field except for fl_classify() as used by the flower
classifier. Thus, the FLOW_DIS_IS_FRAGMENT may be set on entry to
__skb_flow_dissect(), since key_control is allocated on the stack
and may not be initialized.

Since key_basic and key_control are present for all flow keys, let's
make sure they are initialized.

Fixes: 62230715fd24 ("flow_dissector: do not dissect l4 ports for fragments")
Co-developed-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Acked-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: Jason Baron <jbaron@akamai.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/flow_dissector.h
net/sched/cls_flower.c

index e9391e877f9a11d630eb95f0fb4924b967c4cbd7..62838391582760a6e4101a2c9dde0b3dd9922218 100644 (file)
@@ -5,6 +5,7 @@
 #include <linux/types.h>
 #include <linux/in6.h>
 #include <linux/siphash.h>
+#include <linux/string.h>
 #include <uapi/linux/if_ether.h>
 
 struct sk_buff;
@@ -348,4 +349,12 @@ struct bpf_flow_dissector {
        void                    *data_end;
 };
 
+static inline void
+flow_dissector_init_keys(struct flow_dissector_key_control *key_control,
+                        struct flow_dissector_key_basic *key_basic)
+{
+       memset(key_control, 0, sizeof(*key_control));
+       memset(key_basic, 0, sizeof(*key_basic));
+}
+
 #endif
index 7e54d2ab52547bde8dc4b5e6adee5693063c4061..d32d4233d33748c302600a229d207dcab3644266 100644 (file)
@@ -305,6 +305,7 @@ static int fl_classify(struct sk_buff *skb, const struct tcf_proto *tp,
        struct cls_fl_filter *f;
 
        list_for_each_entry_rcu(mask, &head->masks, list) {
+               flow_dissector_init_keys(&skb_key.control, &skb_key.basic);
                fl_clear_masked_range(&skb_key, mask);
 
                skb_flow_dissect_meta(skb, &mask->dissector, &skb_key);