netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: flow_dissector: fix tcp flags dissection on big-endian
@ 2019-12-09 15:55 Pablo Neira Ayuso
  2019-12-09 16:04 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 3+ messages in thread
From: Pablo Neira Ayuso @ 2019-12-09 15:55 UTC (permalink / raw)
  To: netdev; +Cc: netfilter-devel, davem, geert, jiri

    net/netfilter/nf_flow_table_offload.c: In function 'nf_flow_rule_match':
    net/netfilter/nf_flow_table_offload.c:80:21: warning: unsigned conversion from 'int' to '__be16' {aka 'short unsigned int'} changes value from '327680' to '0' [-Woverflow]
       80 |   mask->tcp.flags = TCP_FLAG_RST | TCP_FLAG_FIN;
          |                     ^~~~~~~~~~~~

Fixes: ac4bb5de2701 ("net: flow_dissector: add support for dissection of tcp flags")
Fixes: c29f74e0df7a ("netfilter: nf_flow_table: hardware offload support")
Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
@Geert: I have removed the pad field and included the nitpick fix on the
        comment, given I have slightly updated this patch, I would prefer
        if you can provide a fresh Reviewed-by tag. Thanks.

 include/net/flow_dissector.h          | 8 ++++++--
 net/core/flow_dissector.c             | 2 +-
 net/netfilter/nf_flow_table_offload.c | 4 ++--
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/include/net/flow_dissector.h b/include/net/flow_dissector.h
index b8c20e9f343e..9ff8dac9d5ec 100644
--- a/include/net/flow_dissector.h
+++ b/include/net/flow_dissector.h
@@ -189,10 +189,14 @@ struct flow_dissector_key_eth_addrs {
 
 /**
  * struct flow_dissector_key_tcp:
- * @flags: flags
+ * @flags: TCP flags, including the initial Data offset field bits (16-bits)
+ * @flag_word: Data offset + reserved bits + TCP flags + window (32-bits)
  */
 struct flow_dissector_key_tcp {
-	__be16 flags;
+	union {
+		__be16 flags;
+		__be32 flag_word;
+	};
 };
 
 /**
diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c
index ca871657a4c4..83af4633f306 100644
--- a/net/core/flow_dissector.c
+++ b/net/core/flow_dissector.c
@@ -756,7 +756,7 @@ __skb_flow_dissect_tcp(const struct sk_buff *skb,
 	key_tcp = skb_flow_dissector_target(flow_dissector,
 					    FLOW_DISSECTOR_KEY_TCP,
 					    target_container);
-	key_tcp->flags = (*(__be16 *) &tcp_flag_word(th) & htons(0x0FFF));
+	key_tcp->flag_word = tcp_flag_word(th);
 }
 
 static void
diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c
index c94ebad78c5c..30205d57226d 100644
--- a/net/netfilter/nf_flow_table_offload.c
+++ b/net/netfilter/nf_flow_table_offload.c
@@ -87,8 +87,8 @@ static int nf_flow_rule_match(struct nf_flow_match *match,
 
 	switch (tuple->l4proto) {
 	case IPPROTO_TCP:
-		key->tcp.flags = 0;
-		mask->tcp.flags = TCP_FLAG_RST | TCP_FLAG_FIN;
+		key->tcp.flag_word = 0;
+		mask->tcp.flag_word = TCP_FLAG_RST | TCP_FLAG_FIN;
 		match->dissector.used_keys |= BIT(FLOW_DISSECTOR_KEY_TCP);
 		break;
 	case IPPROTO_UDP:
-- 
2.11.0


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

* Re: [PATCH net] net: flow_dissector: fix tcp flags dissection on big-endian
  2019-12-09 15:55 [PATCH net] net: flow_dissector: fix tcp flags dissection on big-endian Pablo Neira Ayuso
@ 2019-12-09 16:04 ` Pablo Neira Ayuso
  2019-12-09 16:06   ` Pablo Neira Ayuso
  0 siblings, 1 reply; 3+ messages in thread
From: Pablo Neira Ayuso @ 2019-12-09 16:04 UTC (permalink / raw)
  To: netdev; +Cc: netfilter-devel, davem, geert, jiri

Hi,

Please, withdraw this patch.

I can fix this by using TCPHDR_* definitions.

Thanks.

On Mon, Dec 09, 2019 at 04:55:30PM +0100, Pablo Neira Ayuso wrote:
>     net/netfilter/nf_flow_table_offload.c: In function 'nf_flow_rule_match':
>     net/netfilter/nf_flow_table_offload.c:80:21: warning: unsigned conversion from 'int' to '__be16' {aka 'short unsigned int'} changes value from '327680' to '0' [-Woverflow]
>        80 |   mask->tcp.flags = TCP_FLAG_RST | TCP_FLAG_FIN;
>           |                     ^~~~~~~~~~~~
> 
> Fixes: ac4bb5de2701 ("net: flow_dissector: add support for dissection of tcp flags")
> Fixes: c29f74e0df7a ("netfilter: nf_flow_table: hardware offload support")
> Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
> ---
> @Geert: I have removed the pad field and included the nitpick fix on the
>         comment, given I have slightly updated this patch, I would prefer
>         if you can provide a fresh Reviewed-by tag. Thanks.
> 
>  include/net/flow_dissector.h          | 8 ++++++--
>  net/core/flow_dissector.c             | 2 +-
>  net/netfilter/nf_flow_table_offload.c | 4 ++--
>  3 files changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/include/net/flow_dissector.h b/include/net/flow_dissector.h
> index b8c20e9f343e..9ff8dac9d5ec 100644
> --- a/include/net/flow_dissector.h
> +++ b/include/net/flow_dissector.h
> @@ -189,10 +189,14 @@ struct flow_dissector_key_eth_addrs {
>  
>  /**
>   * struct flow_dissector_key_tcp:
> - * @flags: flags
> + * @flags: TCP flags, including the initial Data offset field bits (16-bits)
> + * @flag_word: Data offset + reserved bits + TCP flags + window (32-bits)
>   */
>  struct flow_dissector_key_tcp {
> -	__be16 flags;
> +	union {
> +		__be16 flags;
> +		__be32 flag_word;
> +	};
>  };
>  
>  /**
> diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c
> index ca871657a4c4..83af4633f306 100644
> --- a/net/core/flow_dissector.c
> +++ b/net/core/flow_dissector.c
> @@ -756,7 +756,7 @@ __skb_flow_dissect_tcp(const struct sk_buff *skb,
>  	key_tcp = skb_flow_dissector_target(flow_dissector,
>  					    FLOW_DISSECTOR_KEY_TCP,
>  					    target_container);
> -	key_tcp->flags = (*(__be16 *) &tcp_flag_word(th) & htons(0x0FFF));
> +	key_tcp->flag_word = tcp_flag_word(th);
>  }
>  
>  static void
> diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c
> index c94ebad78c5c..30205d57226d 100644
> --- a/net/netfilter/nf_flow_table_offload.c
> +++ b/net/netfilter/nf_flow_table_offload.c
> @@ -87,8 +87,8 @@ static int nf_flow_rule_match(struct nf_flow_match *match,
>  
>  	switch (tuple->l4proto) {
>  	case IPPROTO_TCP:
> -		key->tcp.flags = 0;
> -		mask->tcp.flags = TCP_FLAG_RST | TCP_FLAG_FIN;
> +		key->tcp.flag_word = 0;
> +		mask->tcp.flag_word = TCP_FLAG_RST | TCP_FLAG_FIN;
>  		match->dissector.used_keys |= BIT(FLOW_DISSECTOR_KEY_TCP);
>  		break;
>  	case IPPROTO_UDP:
> -- 
> 2.11.0
> 

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

* Re: [PATCH net] net: flow_dissector: fix tcp flags dissection on big-endian
  2019-12-09 16:04 ` Pablo Neira Ayuso
@ 2019-12-09 16:06   ` Pablo Neira Ayuso
  0 siblings, 0 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2019-12-09 16:06 UTC (permalink / raw)
  To: netdev; +Cc: netfilter-devel, davem, geert, jiri

On Mon, Dec 09, 2019 at 05:04:30PM +0100, Pablo Neira Ayuso wrote:
> Hi,
> 
> Please, withdraw this patch.
>
> I can fix this by using TCPHDR_* definitions.

Oh actually, that's only true for my nf_flow_table_offload code.

But not for the flow dissector code, which is using tcp_flag_word().

I will revamp and send v2.

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

end of thread, other threads:[~2019-12-09 16:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-12-09 15:55 [PATCH net] net: flow_dissector: fix tcp flags dissection on big-endian Pablo Neira Ayuso
2019-12-09 16:04 ` Pablo Neira Ayuso
2019-12-09 16:06   ` Pablo Neira Ayuso

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