All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] netfilter: nf_flow_table: fix big-endian integer overflow
@ 2019-12-10 20:24 Arnd Bergmann
  2019-12-11 22:04 ` Pablo Neira Ayuso
  2019-12-20  1:10 ` Pablo Neira Ayuso
  0 siblings, 2 replies; 3+ messages in thread
From: Arnd Bergmann @ 2019-12-10 20:24 UTC (permalink / raw)
  To: Pablo Neira Ayuso, Jozsef Kadlecsik, Florian Westphal, David S. Miller
  Cc: Arnd Bergmann, wenxu, netfilter-devel, coreteam, netdev, linux-kernel

In some configurations, gcc reports an integer overflow:

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

From what I can tell, we want the upper 16 bits of these constants,
so they need to be shifted in cpu-endian mode.

Fixes: c29f74e0df7a ("netfilter: nf_flow_table: hardware offload support")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
I'm not sure if this is the correct fix, please check carefully
---
 net/netfilter/nf_flow_table_offload.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c
index c54c9a6cc981..24543c45d501 100644
--- a/net/netfilter/nf_flow_table_offload.c
+++ b/net/netfilter/nf_flow_table_offload.c
@@ -77,7 +77,7 @@ 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;
+		mask->tcp.flags = cpu_to_be16(be32_to_cpu(TCP_FLAG_RST | TCP_FLAG_FIN) >> 16);
 		match->dissector.used_keys |= BIT(FLOW_DISSECTOR_KEY_TCP);
 		break;
 	case IPPROTO_UDP:
-- 
2.20.0


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

* Re: [PATCH] netfilter: nf_flow_table: fix big-endian integer overflow
  2019-12-10 20:24 [PATCH] netfilter: nf_flow_table: fix big-endian integer overflow Arnd Bergmann
@ 2019-12-11 22:04 ` Pablo Neira Ayuso
  2019-12-20  1:10 ` Pablo Neira Ayuso
  1 sibling, 0 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2019-12-11 22:04 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Jozsef Kadlecsik, Florian Westphal, David S. Miller, wenxu,
	netfilter-devel, coreteam, netdev, linux-kernel

Hi Arnd,

On Tue, Dec 10, 2019 at 09:24:28PM +0100, Arnd Bergmann wrote:
> In some configurations, gcc reports an integer overflow:
> 
> net/netfilter/nf_flow_table_offload.c: In function 'nf_flow_rule_match':
> net/netfilter/nf_flow_table_offload.c:80:21: error: unsigned conversion from 'int' to '__be16' {aka 'short unsigned int'} changes value from '327680' to '0' [-Werror=overflow]
>    mask->tcp.flags = TCP_FLAG_RST | TCP_FLAG_FIN;
>                      ^~~~~~~~~~~~
> 
> From what I can tell, we want the upper 16 bits of these constants,
> so they need to be shifted in cpu-endian mode.
> 
> Fixes: c29f74e0df7a ("netfilter: nf_flow_table: hardware offload support")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> I'm not sure if this is the correct fix, please check carefully

Thanks. I posted this one:

https://patchwork.ozlabs.org/patch/1206384/

The flow dissector matching on tcp flags seems also broken on big-endian.

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

* Re: [PATCH] netfilter: nf_flow_table: fix big-endian integer overflow
  2019-12-10 20:24 [PATCH] netfilter: nf_flow_table: fix big-endian integer overflow Arnd Bergmann
  2019-12-11 22:04 ` Pablo Neira Ayuso
@ 2019-12-20  1:10 ` Pablo Neira Ayuso
  1 sibling, 0 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2019-12-20  1:10 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Jozsef Kadlecsik, Florian Westphal, David S. Miller, wenxu,
	netfilter-devel, coreteam, netdev, linux-kernel

On Tue, Dec 10, 2019 at 09:24:28PM +0100, Arnd Bergmann wrote:
> In some configurations, gcc reports an integer overflow:
> 
> net/netfilter/nf_flow_table_offload.c: In function 'nf_flow_rule_match':
> net/netfilter/nf_flow_table_offload.c:80:21: error: unsigned conversion from 'int' to '__be16' {aka 'short unsigned int'} changes value from '327680' to '0' [-Werror=overflow]
>    mask->tcp.flags = TCP_FLAG_RST | TCP_FLAG_FIN;
>                      ^~~~~~~~~~~~
> 
> From what I can tell, we want the upper 16 bits of these constants,
> so they need to be shifted in cpu-endian mode.
> 
> Fixes: c29f74e0df7a ("netfilter: nf_flow_table: hardware offload support")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Applied, thanks.

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

end of thread, other threads:[~2019-12-20  1:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-10 20:24 [PATCH] netfilter: nf_flow_table: fix big-endian integer overflow Arnd Bergmann
2019-12-11 22:04 ` Pablo Neira Ayuso
2019-12-20  1:10 ` Pablo Neira Ayuso

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.