From: Jason Baron <jbaron@akamai.com>
To: davem@davemloft.net, jiri@resnulli.us, xiyou.wangcong@gmail.com,
jhs@mojatatu.com
Cc: netdev@vger.kernel.org, soukjin.bae@samsung.com,
Eric Dumazet <edumazet@google.com>
Subject: [PATCH net] net: sched: correct flower port blocking
Date: Thu, 13 Feb 2020 15:28:19 -0500 [thread overview]
Message-ID: <1581625699-24457-1-git-send-email-jbaron@akamai.com> (raw)
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>
Signed-off-by: Jason Baron <jbaron@akamai.com>
---
include/linux/skbuff.h | 8 ++++++++
net/sched/cls_flower.c | 1 +
2 files changed, 9 insertions(+)
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index ca8806b..f953bfa 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -1288,6 +1288,14 @@ bool __skb_flow_dissect(const struct net *net,
void *data, __be16 proto, int nhoff, int hlen,
unsigned int flags);
+static inline void
+skb_flow_dissect_init_key(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));
+}
+
static inline bool skb_flow_dissect(const struct sk_buff *skb,
struct flow_dissector *flow_dissector,
void *target_container, unsigned int flags)
diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c
index f9c0d1e..b0a534b 100644
--- a/net/sched/cls_flower.c
+++ b/net/sched/cls_flower.c
@@ -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) {
+ skb_flow_dissect_init_key(&skb_key.control, &skb_key.basic);
fl_clear_masked_range(&skb_key, mask);
skb_flow_dissect_meta(skb, &mask->dissector, &skb_key);
--
2.7.4
next reply other threads:[~2020-02-13 20:31 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-13 20:28 Jason Baron [this message]
2020-02-13 22:50 ` [PATCH net] net: sched: correct flower port blocking Cong Wang
2020-02-14 16:20 ` [PATCH v2 " Jason Baron
2020-02-17 3:08 ` David Miller
2020-02-17 3:18 ` David Miller
2020-02-17 20:38 ` [PATCH v3 " Jason Baron
2020-02-18 5:33 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1581625699-24457-1-git-send-email-jbaron@akamai.com \
--to=jbaron@akamai.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=netdev@vger.kernel.org \
--cc=soukjin.bae@samsung.com \
--cc=xiyou.wangcong@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).