All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] net: sched: correct flower port blocking
@ 2020-02-13 20:28 Jason Baron
  2020-02-13 22:50 ` Cong Wang
  0 siblings, 1 reply; 7+ messages in thread
From: Jason Baron @ 2020-02-13 20:28 UTC (permalink / raw)
  To: davem, jiri, xiyou.wangcong, jhs; +Cc: netdev, soukjin.bae, Eric Dumazet

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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH net] net: sched: correct flower port blocking
  2020-02-13 20:28 [PATCH net] net: sched: correct flower port blocking Jason Baron
@ 2020-02-13 22:50 ` Cong Wang
  2020-02-14 16:20   ` [PATCH v2 " Jason Baron
  0 siblings, 1 reply; 7+ messages in thread
From: Cong Wang @ 2020-02-13 22:50 UTC (permalink / raw)
  To: Jason Baron
  Cc: David Miller, Jiri Pirko, Jamal Hadi Salim,
	Linux Kernel Network Developers, soukjin.bae, Eric Dumazet

On Thu, Feb 13, 2020 at 12:31 PM Jason Baron <jbaron@akamai.com> wrote:
>
> 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));
> +}

I think this function has nothing to do with skb, therefore it fits
better in include/net/flow_dissector.h? And remove skb prefix from
its name too.

Other than this:

Acked-by: Cong Wang <xiyou.wangcong@gmail.com>

Thanks.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 net] net: sched: correct flower port blocking
  2020-02-13 22:50 ` Cong Wang
@ 2020-02-14 16:20   ` Jason Baron
  2020-02-17  3:08     ` David Miller
  0 siblings, 1 reply; 7+ messages in thread
From: Jason Baron @ 2020-02-14 16:20 UTC (permalink / raw)
  To: davem, jiri, xiyou.wangcong, jhs; +Cc: netdev, soukjin.bae, Eric Dumazet

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>
---
v2:

-move rename to flow_dissector_init_keys() amd move to
 flow_dissector.h (Cong Wang)

 include/net/flow_dissector.h | 8 ++++++++
 net/sched/cls_flower.c       | 1 +
 2 files changed, 9 insertions(+)

diff --git a/include/net/flow_dissector.h b/include/net/flow_dissector.h
index d93017a..4bd4931 100644
--- a/include/net/flow_dissector.h
+++ b/include/net/flow_dissector.h
@@ -349,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
diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c
index f9c0d1e..b783254 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) {
+		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);
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 net] net: sched: correct flower port blocking
  2020-02-14 16:20   ` [PATCH v2 " Jason Baron
@ 2020-02-17  3:08     ` David Miller
  2020-02-17  3:18       ` David Miller
  0 siblings, 1 reply; 7+ messages in thread
From: David Miller @ 2020-02-17  3:08 UTC (permalink / raw)
  To: jbaron; +Cc: jiri, xiyou.wangcong, jhs, netdev, soukjin.bae, edumazet

From: Jason Baron <jbaron@akamai.com>
Date: Fri, 14 Feb 2020 11:20:24 -0500

> 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>

Applied and queued up for -stable.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 net] net: sched: correct flower port blocking
  2020-02-17  3:08     ` David Miller
@ 2020-02-17  3:18       ` David Miller
  2020-02-17 20:38         ` [PATCH v3 " Jason Baron
  0 siblings, 1 reply; 7+ messages in thread
From: David Miller @ 2020-02-17  3:18 UTC (permalink / raw)
  To: jbaron; +Cc: jiri, xiyou.wangcong, jhs, netdev, soukjin.bae, edumazet

From: David Miller <davem@davemloft.net>
Date: Sun, 16 Feb 2020 19:08:12 -0800 (PST)

> From: Jason Baron <jbaron@akamai.com>
> Date: Fri, 14 Feb 2020 11:20:24 -0500
> 
>> 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>
> 
> Applied and queued up for -stable.

Actually this doesn't even compile:

In file included from drivers/net/ethernet/mellanox/mlx5/core/en_tc.c:33:
./include/net/flow_dissector.h: In function ‘flow_dissector_init_keys’:
./include/net/flow_dissector.h:355:2: error: implicit declaration of function ‘memset’ [-Werror=implicit-function-declaration]
  memset(key_control, 0, sizeof(*key_control));
  ^~~~~~
./include/net/flow_dissector.h:355:2: warning: incompatible implicit declaration of built-in function ‘memset’
./include/net/flow_dissector.h:355:2: note: include ‘<string.h>’ or provide a declaration of ‘memset’
./include/net/flow_dissector.h:9:1:
+#include <string.h>
 
./include/net/flow_dissector.h:355:2:
  memset(key_control, 0, sizeof(*key_control));
  ^~~~~~

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v3 net] net: sched: correct flower port blocking
  2020-02-17  3:18       ` David Miller
@ 2020-02-17 20:38         ` Jason Baron
  2020-02-18  5:33           ` David Miller
  0 siblings, 1 reply; 7+ messages in thread
From: Jason Baron @ 2020-02-17 20:38 UTC (permalink / raw)
  To: davem, jiri, xiyou.wangcong, jhs; +Cc: netdev, soukjin.bae, Eric Dumazet

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>
---

v3:
-add include of string.h for memset() (David Miller)

v2:
-move rename to flow_dissector_init_keys() amd move to
 flow_dissector.h (Cong Wang)


 include/net/flow_dissector.h | 9 +++++++++
 net/sched/cls_flower.c       | 1 +
 2 files changed, 10 insertions(+)

diff --git a/include/net/flow_dissector.h b/include/net/flow_dissector.h
index d93017a..e03827f 100644
--- a/include/net/flow_dissector.h
+++ b/include/net/flow_dissector.h
@@ -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;
@@ -349,4 +350,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
diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c
index f9c0d1e..b783254 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) {
+		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);
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v3 net] net: sched: correct flower port blocking
  2020-02-17 20:38         ` [PATCH v3 " Jason Baron
@ 2020-02-18  5:33           ` David Miller
  0 siblings, 0 replies; 7+ messages in thread
From: David Miller @ 2020-02-18  5:33 UTC (permalink / raw)
  To: jbaron; +Cc: jiri, xiyou.wangcong, jhs, netdev, soukjin.bae, edumazet

From: Jason Baron <jbaron@akamai.com>
Date: Mon, 17 Feb 2020 15:38:09 -0500

> 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>

Applied and queued up for -stable, thanks Jason.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-02-18  5:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-13 20:28 [PATCH net] net: sched: correct flower port blocking Jason Baron
2020-02-13 22:50 ` 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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.