Linux-Next Archive on lore.kernel.org
 help / color / Atom feed
* linux-next: build warning after merge of the net-next tree
@ 2019-11-21  7:34 Stephen Rothwell
  2019-11-26 11:06 ` nf_flow on big-endian (was: Re: linux-next: build warning after merge of the net-next tree) Geert Uytterhoeven
  0 siblings, 1 reply; 4+ messages in thread
From: Stephen Rothwell @ 2019-11-21  7:34 UTC (permalink / raw)
  To: David Miller, Networking
  Cc: Linux Next Mailing List, Linux Kernel Mailing List, Pablo Neira Ayuso

[-- Attachment #1: Type: text/plain, Size: 645 bytes --]

Hi all,

[Sorry, I should have reported this earlier]

After merging the net-next tree, today's linux-next build (powerpc
allyesconfig) produced this warning:

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;
      |                     ^~~~~~~~~~~~

Introduced by commit

  c29f74e0df7a ("netfilter: nf_flow_table: hardware offload support")

-- 
Cheers,
Stephen Rothwell

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* nf_flow on big-endian (was: Re: linux-next: build warning after merge of the net-next tree)
  2019-11-21  7:34 linux-next: build warning after merge of the net-next tree Stephen Rothwell
@ 2019-11-26 11:06 ` Geert Uytterhoeven
  2019-12-07 16:41   ` Pablo Neira Ayuso
  0 siblings, 1 reply; 4+ messages in thread
From: Geert Uytterhoeven @ 2019-11-26 11:06 UTC (permalink / raw)
  To: Stephen Rothwell, Pablo Neira Ayuso
  Cc: David Miller, Networking, Linux Next Mailing List,
	Linux Kernel Mailing List, NetFilter, Jiri Pirko,
	Jozsef Kadlecsik, Florian Westphal

On Thu, Nov 21, 2019 at 8:36 AM Stephen Rothwell <sfr@canb.auug.org.au> wrote:
> After merging the net-next tree, today's linux-next build (powerpc
> allyesconfig) produced this warning:
>
> 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;
>       |                     ^~~~~~~~~~~~
>
> Introduced by commit
>
>   c29f74e0df7a ("netfilter: nf_flow_table: hardware offload support")

This is now upstream, and must be completely broken on big-endian
platforms.

The other user of the flags field looks buggy, too
(net/core/flow_dissector.c:__skb_flow_dissect_tcp()[*]):

     key_tcp->flags = (*(__be16 *) &tcp_flag_word(th) & htons(0x0FFF));

Disclaimer: I'm not familiar with the code or protocol, so below are just
my gut feelings.

     struct flow_dissector_key_tcp {
            __be16 flags;
    };

Does this have to be __be16, i.e. does it go over the wire?
If not, this should probably be __u16, and set using
"be32_to_cpu(flags) >> 16"?
If yes, "cpu_to_be16(be32_to_cpu(flags) >> 16)"?
(Ugh, needs convenience macros)

[*] ac4bb5de27010e41 ("net: flow_dissector: add support for dissection
of tcp flags")

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: nf_flow on big-endian (was: Re: linux-next: build warning after merge of the net-next tree)
  2019-11-26 11:06 ` nf_flow on big-endian (was: Re: linux-next: build warning after merge of the net-next tree) Geert Uytterhoeven
@ 2019-12-07 16:41   ` Pablo Neira Ayuso
  2019-12-08 10:33     ` Geert Uytterhoeven
  0 siblings, 1 reply; 4+ messages in thread
From: Pablo Neira Ayuso @ 2019-12-07 16:41 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Stephen Rothwell, David Miller, Networking,
	Linux Next Mailing List, Linux Kernel Mailing List, NetFilter,
	Jiri Pirko, Jozsef Kadlecsik, Florian Westphal

[-- Attachment #1: Type: text/plain, Size: 1621 bytes --]

Hi Geert,

On Tue, Nov 26, 2019 at 12:06:03PM +0100, Geert Uytterhoeven wrote:
> On Thu, Nov 21, 2019 at 8:36 AM Stephen Rothwell <sfr@canb.auug.org.au> wrote:
> > After merging the net-next tree, today's linux-next build (powerpc
> > allyesconfig) produced this warning:
> >
> > 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;
> >       |                     ^~~~~~~~~~~~
> >
> > Introduced by commit
> >
> >   c29f74e0df7a ("netfilter: nf_flow_table: hardware offload support")
> 
> This is now upstream, and must be completely broken on big-endian
> platforms.
> 
> The other user of the flags field looks buggy, too
> (net/core/flow_dissector.c:__skb_flow_dissect_tcp()[*]):
> 
>      key_tcp->flags = (*(__be16 *) &tcp_flag_word(th) & htons(0x0FFF));
> 
> Disclaimer: I'm not familiar with the code or protocol, so below are just
> my gut feelings.
> 
>      struct flow_dissector_key_tcp {
>             __be16 flags;
>     };
> 
> Does this have to be __be16, i.e. does it go over the wire?
> If not, this should probably be __u16, and set using
> "be32_to_cpu(flags) >> 16"?
> If yes, "cpu_to_be16(be32_to_cpu(flags) >> 16)"?
> (Ugh, needs convenience macros)
> 
> [*] ac4bb5de27010e41 ("net: flow_dissector: add support for dissection
> of tcp flags")

I'm attaching a tentative patch, please let me know this is fixing up
this issue there.

Thanks.

[-- Attachment #2: x.patch --]
[-- Type: text/x-diff, Size: 1674 bytes --]

diff --git a/include/net/flow_dissector.h b/include/net/flow_dissector.h
index b8c20e9f343e..30ad4e07ff52 100644
--- a/include/net/flow_dissector.h
+++ b/include/net/flow_dissector.h
@@ -189,10 +189,17 @@ struct flow_dissector_key_eth_addrs {
 
 /**
  * struct flow_dissector_key_tcp:
- * @flags: flags
+ * @flags: TCP flags (16-bit, including the initial Data offset field bits)
+ * @word: Data offset + reserved bits + TCP flags + window
  */
 struct flow_dissector_key_tcp {
-	__be16 flags;
+	union {
+		struct {
+			__be16 flags;
+			__be16 __pad;
+		};
+		__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:

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

* Re: nf_flow on big-endian (was: Re: linux-next: build warning after merge of the net-next tree)
  2019-12-07 16:41   ` Pablo Neira Ayuso
@ 2019-12-08 10:33     ` Geert Uytterhoeven
  0 siblings, 0 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2019-12-08 10:33 UTC (permalink / raw)
  To: Pablo Neira Ayuso
  Cc: Stephen Rothwell, David Miller, Networking,
	Linux Next Mailing List, Linux Kernel Mailing List, NetFilter,
	Jiri Pirko, Jozsef Kadlecsik, Florian Westphal

Hi Pablo,

On Sat, Dec 7, 2019 at 5:41 PM Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> On Tue, Nov 26, 2019 at 12:06:03PM +0100, Geert Uytterhoeven wrote:
> > On Thu, Nov 21, 2019 at 8:36 AM Stephen Rothwell <sfr@canb.auug.org.au> wrote:
> > > After merging the net-next tree, today's linux-next build (powerpc
> > > allyesconfig) produced this warning:
> > >
> > > 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;
> > >       |                     ^~~~~~~~~~~~
> > >
> > > Introduced by commit
> > >
> > >   c29f74e0df7a ("netfilter: nf_flow_table: hardware offload support")
> >
> > This is now upstream, and must be completely broken on big-endian
> > platforms.
> >
> > The other user of the flags field looks buggy, too
> > (net/core/flow_dissector.c:__skb_flow_dissect_tcp()[*]):
> >
> >      key_tcp->flags = (*(__be16 *) &tcp_flag_word(th) & htons(0x0FFF));
> >
> > Disclaimer: I'm not familiar with the code or protocol, so below are just
> > my gut feelings.
> >
> >      struct flow_dissector_key_tcp {
> >             __be16 flags;
> >     };
> >
> > Does this have to be __be16, i.e. does it go over the wire?
> > If not, this should probably be __u16, and set using
> > "be32_to_cpu(flags) >> 16"?
> > If yes, "cpu_to_be16(be32_to_cpu(flags) >> 16)"?
> > (Ugh, needs convenience macros)
> >
> > [*] ac4bb5de27010e41 ("net: flow_dissector: add support for dissection
> > of tcp flags")
>
> I'm attaching a tentative patch, please let me know this is fixing up
> this issue there.

Thanks, this looks good to me, and fixes the build warning.
For this localized change (not for the global interaction), with the nits
below fixed:
Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org>

> --- a/include/net/flow_dissector.h
> +++ b/include/net/flow_dissector.h
> @@ -189,10 +189,17 @@ struct flow_dissector_key_eth_addrs {
>
>  /**
>   * struct flow_dissector_key_tcp:
> - * @flags: flags
> + * @flags: TCP flags (16-bit, including the initial Data offset field bits)

@pad?

> + * @word: Data offset + reserved bits + TCP flags + window

flag_word

>   */
>  struct flow_dissector_key_tcp {
> -     __be16 flags;
> +     union {
> +             struct {
> +                     __be16 flags;
> +                     __be16 __pad;
> +             };
> +             __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:


Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-21  7:34 linux-next: build warning after merge of the net-next tree Stephen Rothwell
2019-11-26 11:06 ` nf_flow on big-endian (was: Re: linux-next: build warning after merge of the net-next tree) Geert Uytterhoeven
2019-12-07 16:41   ` Pablo Neira Ayuso
2019-12-08 10:33     ` Geert Uytterhoeven

Linux-Next Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-next/0 linux-next/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-next linux-next/ https://lore.kernel.org/linux-next \
		linux-next@vger.kernel.org
	public-inbox-index linux-next

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-next


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git