netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/11] Netfilter fixes for net
@ 2020-03-06 18:15 Pablo Neira Ayuso
  2020-03-06 18:15 ` [PATCH 01/11] netfilter: nf_conntrack: ct_cpu_seq_next should increase position index Pablo Neira Ayuso
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: Pablo Neira Ayuso @ 2020-03-06 18:15 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

Hi,

The following patchset contains Netfilter fixes for net:

1) Patches to bump position index from sysctl seq_next,
   from Vasilin Averin.

2) Release flowtable hook from error path, from Florian Westphal.

3) Patches to add missing netlink attribute validation,
   from Jakub Kicinski.

4) Missing NFTA_CHAIN_FLAGS in nf_tables_fill_chain_info().

5) Infinite loop in module autoload if extension is not available,
   from Florian Westphal.

6) Missing module ownership in inet/nat chain type definition.

You can pull these changes from:

  git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git

Thank you.

----------------------------------------------------------------

The following changes since commit f8a0fea9518c5ff7c37679504bd9eeabeae8ee36:

  docs: networking: net_failover: Fix a few typos (2020-03-03 16:07:02 -0800)

are available in the git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git HEAD

for you to fetch changes up to 6a42cefb25d8bdc1b391f4a53c78c32164eea2dd:

  netfilter: nft_chain_nat: inet family is missing module ownership (2020-03-06 18:00:43 +0100)

----------------------------------------------------------------
Florian Westphal (2):
      netfilter: nf_tables: free flowtable hooks on hook register error
      netfilter: nf_tables: fix infinite loop when expr is not available

Jakub Kicinski (3):
      netfilter: cthelper: add missing attribute validation for cthelper
      netfilter: nft_payload: add missing attribute validation for payload csum flags
      netfilter: nft_tunnel: add missing attribute validation for tunnels

Pablo Neira Ayuso (2):
      netfilter: nf_tables: dump NFTA_CHAIN_FLAGS attribute
      netfilter: nft_chain_nat: inet family is missing module ownership

Vasily Averin (4):
      netfilter: nf_conntrack: ct_cpu_seq_next should increase position index
      netfilter: synproxy: synproxy_cpu_seq_next should increase position index
      netfilter: xt_recent: recent_seq_next should increase position index
      netfilter: x_tables: xt_mttg_seq_next should increase position index

 net/netfilter/nf_conntrack_standalone.c |  2 +-
 net/netfilter/nf_synproxy_core.c        |  2 +-
 net/netfilter/nf_tables_api.c           | 22 ++++++++++++++--------
 net/netfilter/nfnetlink_cthelper.c      |  2 ++
 net/netfilter/nft_chain_nat.c           |  1 +
 net/netfilter/nft_payload.c             |  1 +
 net/netfilter/nft_tunnel.c              |  2 ++
 net/netfilter/x_tables.c                |  6 +++---
 net/netfilter/xt_recent.c               |  2 +-
 9 files changed, 26 insertions(+), 14 deletions(-)

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

* [PATCH 01/11] netfilter: nf_conntrack: ct_cpu_seq_next should increase position index
  2020-03-06 18:15 [PATCH 00/11] Netfilter fixes for net Pablo Neira Ayuso
@ 2020-03-06 18:15 ` Pablo Neira Ayuso
  2020-03-06 18:15 ` [PATCH 02/11] netfilter: synproxy: synproxy_cpu_seq_next " Pablo Neira Ayuso
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Pablo Neira Ayuso @ 2020-03-06 18:15 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

From: Vasily Averin <vvs@virtuozzo.com>

If .next function does not change position index,
following .show function will repeat output related
to current position index.

Cc: stable@vger.kernel.org
Fixes: 1f4aace60b0e ("fs/seq_file.c: simplify seq_file iteration code ...")
Link: https://bugzilla.kernel.org/show_bug.cgi?id=206283
Signed-off-by: Vasily Averin <vvs@virtuozzo.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nf_conntrack_standalone.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
index 410809c669e1..4912069627b6 100644
--- a/net/netfilter/nf_conntrack_standalone.c
+++ b/net/netfilter/nf_conntrack_standalone.c
@@ -411,7 +411,7 @@ static void *ct_cpu_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 		*pos = cpu + 1;
 		return per_cpu_ptr(net->ct.stat, cpu);
 	}
-
+	(*pos)++;
 	return NULL;
 }
 
-- 
2.11.0


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

* [PATCH 02/11] netfilter: synproxy: synproxy_cpu_seq_next should increase position index
  2020-03-06 18:15 [PATCH 00/11] Netfilter fixes for net Pablo Neira Ayuso
  2020-03-06 18:15 ` [PATCH 01/11] netfilter: nf_conntrack: ct_cpu_seq_next should increase position index Pablo Neira Ayuso
@ 2020-03-06 18:15 ` Pablo Neira Ayuso
  2020-03-06 18:15 ` [PATCH 03/11] netfilter: xt_recent: recent_seq_next " Pablo Neira Ayuso
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Pablo Neira Ayuso @ 2020-03-06 18:15 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

From: Vasily Averin <vvs@virtuozzo.com>

If .next function does not change position index,
following .show function will repeat output related
to current position index.

Cc: stable@vger.kernel.org
Fixes: 1f4aace60b0e ("fs/seq_file.c: simplify seq_file iteration code ...")
Link: https://bugzilla.kernel.org/show_bug.cgi?id=206283
Signed-off-by: Vasily Averin <vvs@virtuozzo.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nf_synproxy_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/netfilter/nf_synproxy_core.c b/net/netfilter/nf_synproxy_core.c
index b0930d4aba22..b9cbe1e2453e 100644
--- a/net/netfilter/nf_synproxy_core.c
+++ b/net/netfilter/nf_synproxy_core.c
@@ -267,7 +267,7 @@ static void *synproxy_cpu_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 		*pos = cpu + 1;
 		return per_cpu_ptr(snet->stats, cpu);
 	}
-
+	(*pos)++;
 	return NULL;
 }
 
-- 
2.11.0


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

* [PATCH 03/11] netfilter: xt_recent: recent_seq_next should increase position index
  2020-03-06 18:15 [PATCH 00/11] Netfilter fixes for net Pablo Neira Ayuso
  2020-03-06 18:15 ` [PATCH 01/11] netfilter: nf_conntrack: ct_cpu_seq_next should increase position index Pablo Neira Ayuso
  2020-03-06 18:15 ` [PATCH 02/11] netfilter: synproxy: synproxy_cpu_seq_next " Pablo Neira Ayuso
@ 2020-03-06 18:15 ` Pablo Neira Ayuso
  2020-03-06 18:15 ` [PATCH 04/11] netfilter: x_tables: xt_mttg_seq_next " Pablo Neira Ayuso
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Pablo Neira Ayuso @ 2020-03-06 18:15 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

From: Vasily Averin <vvs@virtuozzo.com>

If .next function does not change position index,
following .show function will repeat output related
to current position index.

Without the patch:
 # dd if=/proc/net/xt_recent/SSH # original file outpt
 src=127.0.0.4 ttl: 0 last_seen: 6275444819 oldest_pkt: 1 6275444819
 src=127.0.0.2 ttl: 0 last_seen: 6275438906 oldest_pkt: 1 6275438906
 src=127.0.0.3 ttl: 0 last_seen: 6275441953 oldest_pkt: 1 6275441953
 0+1 records in
 0+1 records out
 204 bytes copied, 6.1332e-05 s, 3.3 MB/s

Read after lseek into middle of last line (offset 140 in example below)
generates expected end of last line and then unexpected whole last line
once again

 # dd if=/proc/net/xt_recent/SSH bs=140 skip=1
 dd: /proc/net/xt_recent/SSH: cannot skip to specified offset
 127.0.0.3 ttl: 0 last_seen: 6275441953 oldest_pkt: 1 6275441953
 src=127.0.0.3 ttl: 0 last_seen: 6275441953 oldest_pkt: 1 6275441953
 0+1 records in
 0+1 records out
 132 bytes copied, 6.2487e-05 s, 2.1 MB/s

Cc: stable@vger.kernel.org
Fixes: 1f4aace60b0e ("fs/seq_file.c: simplify seq_file iteration code ...")
Link: https://bugzilla.kernel.org/show_bug.cgi?id=206283
Signed-off-by: Vasily Averin <vvs@virtuozzo.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/xt_recent.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
index 0a9708004e20..225a7ab6d79a 100644
--- a/net/netfilter/xt_recent.c
+++ b/net/netfilter/xt_recent.c
@@ -492,12 +492,12 @@ static void *recent_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 	const struct recent_entry *e = v;
 	const struct list_head *head = e->list.next;
 
+	(*pos)++;
 	while (head == &t->iphash[st->bucket]) {
 		if (++st->bucket >= ip_list_hash_size)
 			return NULL;
 		head = t->iphash[st->bucket].next;
 	}
-	(*pos)++;
 	return list_entry(head, struct recent_entry, list);
 }
 
-- 
2.11.0


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

* [PATCH 04/11] netfilter: x_tables: xt_mttg_seq_next should increase position index
  2020-03-06 18:15 [PATCH 00/11] Netfilter fixes for net Pablo Neira Ayuso
                   ` (2 preceding siblings ...)
  2020-03-06 18:15 ` [PATCH 03/11] netfilter: xt_recent: recent_seq_next " Pablo Neira Ayuso
@ 2020-03-06 18:15 ` Pablo Neira Ayuso
  2020-03-06 18:15 ` [PATCH 05/11] netfilter: nf_tables: free flowtable hooks on hook register error Pablo Neira Ayuso
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Pablo Neira Ayuso @ 2020-03-06 18:15 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

From: Vasily Averin <vvs@virtuozzo.com>

If .next function does not change position index,
following .show function will repeat output related
to current position index.

Without patch:
 # dd if=/proc/net/ip_tables_matches  # original file output
 conntrack
 conntrack
 conntrack
 recent
 recent
 icmp
 udplite
 udp
 tcp
 0+1 records in
 0+1 records out
 65 bytes copied, 5.4074e-05 s, 1.2 MB/s

 # dd if=/proc/net/ip_tables_matches bs=62 skip=1
 dd: /proc/net/ip_tables_matches: cannot skip to specified offset
 cp   <<< end of  last line
 tcp  <<< and then unexpected whole last line once again
 0+1 records in
 0+1 records out
 7 bytes copied, 0.000102447 s, 68.3 kB/s

Cc: stable@vger.kernel.org
Fixes: 1f4aace60b0e ("fs/seq_file.c: simplify seq_file iteration code ...")
Link: https://bugzilla.kernel.org/show_bug.cgi?id=206283
Signed-off-by: Vasily Averin <vvs@virtuozzo.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/x_tables.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c
index e27c6c5ba9df..cd2b034eef59 100644
--- a/net/netfilter/x_tables.c
+++ b/net/netfilter/x_tables.c
@@ -1551,6 +1551,9 @@ static void *xt_mttg_seq_next(struct seq_file *seq, void *v, loff_t *ppos,
 	uint8_t nfproto = (unsigned long)PDE_DATA(file_inode(seq->file));
 	struct nf_mttg_trav *trav = seq->private;
 
+	if (ppos != NULL)
+		++(*ppos);
+
 	switch (trav->class) {
 	case MTTG_TRAV_INIT:
 		trav->class = MTTG_TRAV_NFP_UNSPEC;
@@ -1576,9 +1579,6 @@ static void *xt_mttg_seq_next(struct seq_file *seq, void *v, loff_t *ppos,
 	default:
 		return NULL;
 	}
-
-	if (ppos != NULL)
-		++*ppos;
 	return trav;
 }
 
-- 
2.11.0


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

* [PATCH 05/11] netfilter: nf_tables: free flowtable hooks on hook register error
  2020-03-06 18:15 [PATCH 00/11] Netfilter fixes for net Pablo Neira Ayuso
                   ` (3 preceding siblings ...)
  2020-03-06 18:15 ` [PATCH 04/11] netfilter: x_tables: xt_mttg_seq_next " Pablo Neira Ayuso
@ 2020-03-06 18:15 ` Pablo Neira Ayuso
  2020-03-06 18:15 ` [PATCH 06/11] netfilter: cthelper: add missing attribute validation for cthelper Pablo Neira Ayuso
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Pablo Neira Ayuso @ 2020-03-06 18:15 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

From: Florian Westphal <fw@strlen.de>

If hook registration fails, the hooks allocated via nft_netdev_hook_alloc
need to be freed.

We can't change the goto label to 'goto 5' -- while it does fix the memleak
it does cause a warning splat from the netfilter core (the hooks were not
registered).

Fixes: 3f0465a9ef02 ("netfilter: nf_tables: dynamically allocate hooks per net_device in flowtables")
Reported-by: syzbot+a2ff6fa45162a5ed4dd3@syzkaller.appspotmail.com
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nf_tables_api.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index d1318bdf49ca..bb064aa4154b 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -6300,8 +6300,13 @@ static int nf_tables_newflowtable(struct net *net, struct sock *nlsk,
 		goto err4;
 
 	err = nft_register_flowtable_net_hooks(ctx.net, table, flowtable);
-	if (err < 0)
+	if (err < 0) {
+		list_for_each_entry_safe(hook, next, &flowtable->hook_list, list) {
+			list_del_rcu(&hook->list);
+			kfree_rcu(hook, rcu);
+		}
 		goto err4;
+	}
 
 	err = nft_trans_flowtable_add(&ctx, NFT_MSG_NEWFLOWTABLE, flowtable);
 	if (err < 0)
-- 
2.11.0


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

* [PATCH 06/11] netfilter: cthelper: add missing attribute validation for cthelper
  2020-03-06 18:15 [PATCH 00/11] Netfilter fixes for net Pablo Neira Ayuso
                   ` (4 preceding siblings ...)
  2020-03-06 18:15 ` [PATCH 05/11] netfilter: nf_tables: free flowtable hooks on hook register error Pablo Neira Ayuso
@ 2020-03-06 18:15 ` Pablo Neira Ayuso
  2020-03-06 18:15 ` [PATCH 07/11] netfilter: nft_payload: add missing attribute validation for payload csum flags Pablo Neira Ayuso
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Pablo Neira Ayuso @ 2020-03-06 18:15 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

From: Jakub Kicinski <kuba@kernel.org>

Add missing attribute validation for cthelper
to the netlink policy.

Fixes: 12f7a505331e ("netfilter: add user-space connection tracking helper infrastructure")
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nfnetlink_cthelper.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/netfilter/nfnetlink_cthelper.c b/net/netfilter/nfnetlink_cthelper.c
index de3a9596b7f1..a5f294aa8e4c 100644
--- a/net/netfilter/nfnetlink_cthelper.c
+++ b/net/netfilter/nfnetlink_cthelper.c
@@ -742,6 +742,8 @@ static const struct nla_policy nfnl_cthelper_policy[NFCTH_MAX+1] = {
 	[NFCTH_NAME] = { .type = NLA_NUL_STRING,
 			 .len = NF_CT_HELPER_NAME_LEN-1 },
 	[NFCTH_QUEUE_NUM] = { .type = NLA_U32, },
+	[NFCTH_PRIV_DATA_LEN] = { .type = NLA_U32, },
+	[NFCTH_STATUS] = { .type = NLA_U32, },
 };
 
 static const struct nfnl_callback nfnl_cthelper_cb[NFNL_MSG_CTHELPER_MAX] = {
-- 
2.11.0


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

* [PATCH 07/11] netfilter: nft_payload: add missing attribute validation for payload csum flags
  2020-03-06 18:15 [PATCH 00/11] Netfilter fixes for net Pablo Neira Ayuso
                   ` (5 preceding siblings ...)
  2020-03-06 18:15 ` [PATCH 06/11] netfilter: cthelper: add missing attribute validation for cthelper Pablo Neira Ayuso
@ 2020-03-06 18:15 ` Pablo Neira Ayuso
  2020-03-06 18:15 ` [PATCH 08/11] netfilter: nft_tunnel: add missing attribute validation for tunnels Pablo Neira Ayuso
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Pablo Neira Ayuso @ 2020-03-06 18:15 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

From: Jakub Kicinski <kuba@kernel.org>

Add missing attribute validation for NFTA_PAYLOAD_CSUM_FLAGS
to the netlink policy.

Fixes: 1814096980bb ("netfilter: nft_payload: layer 4 checksum adjustment for pseudoheader fields")
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nft_payload.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/netfilter/nft_payload.c b/net/netfilter/nft_payload.c
index 1993af3a2979..a7de3a58f553 100644
--- a/net/netfilter/nft_payload.c
+++ b/net/netfilter/nft_payload.c
@@ -129,6 +129,7 @@ static const struct nla_policy nft_payload_policy[NFTA_PAYLOAD_MAX + 1] = {
 	[NFTA_PAYLOAD_LEN]		= { .type = NLA_U32 },
 	[NFTA_PAYLOAD_CSUM_TYPE]	= { .type = NLA_U32 },
 	[NFTA_PAYLOAD_CSUM_OFFSET]	= { .type = NLA_U32 },
+	[NFTA_PAYLOAD_CSUM_FLAGS]	= { .type = NLA_U32 },
 };
 
 static int nft_payload_init(const struct nft_ctx *ctx,
-- 
2.11.0


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

* [PATCH 08/11] netfilter: nft_tunnel: add missing attribute validation for tunnels
  2020-03-06 18:15 [PATCH 00/11] Netfilter fixes for net Pablo Neira Ayuso
                   ` (6 preceding siblings ...)
  2020-03-06 18:15 ` [PATCH 07/11] netfilter: nft_payload: add missing attribute validation for payload csum flags Pablo Neira Ayuso
@ 2020-03-06 18:15 ` Pablo Neira Ayuso
  2020-03-06 18:15 ` [PATCH 09/11] netfilter: nf_tables: dump NFTA_CHAIN_FLAGS attribute Pablo Neira Ayuso
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Pablo Neira Ayuso @ 2020-03-06 18:15 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

From: Jakub Kicinski <kuba@kernel.org>

Add missing attribute validation for tunnel source and
destination ports to the netlink policy.

Fixes: af308b94a2a4 ("netfilter: nf_tables: add tunnel support")
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nft_tunnel.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/netfilter/nft_tunnel.c b/net/netfilter/nft_tunnel.c
index 4c3f2e24c7cb..764e88682a81 100644
--- a/net/netfilter/nft_tunnel.c
+++ b/net/netfilter/nft_tunnel.c
@@ -339,6 +339,8 @@ static const struct nla_policy nft_tunnel_key_policy[NFTA_TUNNEL_KEY_MAX + 1] =
 	[NFTA_TUNNEL_KEY_FLAGS]	= { .type = NLA_U32, },
 	[NFTA_TUNNEL_KEY_TOS]	= { .type = NLA_U8, },
 	[NFTA_TUNNEL_KEY_TTL]	= { .type = NLA_U8, },
+	[NFTA_TUNNEL_KEY_SPORT]	= { .type = NLA_U16, },
+	[NFTA_TUNNEL_KEY_DPORT]	= { .type = NLA_U16, },
 	[NFTA_TUNNEL_KEY_OPTS]	= { .type = NLA_NESTED, },
 };
 
-- 
2.11.0


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

* [PATCH 09/11] netfilter: nf_tables: dump NFTA_CHAIN_FLAGS attribute
  2020-03-06 18:15 [PATCH 00/11] Netfilter fixes for net Pablo Neira Ayuso
                   ` (7 preceding siblings ...)
  2020-03-06 18:15 ` [PATCH 08/11] netfilter: nft_tunnel: add missing attribute validation for tunnels Pablo Neira Ayuso
@ 2020-03-06 18:15 ` Pablo Neira Ayuso
  2020-03-06 18:15 ` [PATCH 10/11] netfilter: nf_tables: fix infinite loop when expr is not available Pablo Neira Ayuso
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Pablo Neira Ayuso @ 2020-03-06 18:15 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

Missing NFTA_CHAIN_FLAGS netlink attribute when dumping basechain
definitions.

Fixes: c9626a2cbdb2 ("netfilter: nf_tables: add hardware offload support")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nf_tables_api.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index bb064aa4154b..f9e60981bd36 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -1405,6 +1405,11 @@ static int nf_tables_fill_chain_info(struct sk_buff *skb, struct net *net,
 					      lockdep_commit_lock_is_held(net));
 		if (nft_dump_stats(skb, stats))
 			goto nla_put_failure;
+
+		if ((chain->flags & NFT_CHAIN_HW_OFFLOAD) &&
+		    nla_put_be32(skb, NFTA_CHAIN_FLAGS,
+				 htonl(NFT_CHAIN_HW_OFFLOAD)))
+			goto nla_put_failure;
 	}
 
 	if (nla_put_be32(skb, NFTA_CHAIN_USE, htonl(chain->use)))
-- 
2.11.0


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

* [PATCH 10/11] netfilter: nf_tables: fix infinite loop when expr is not available
  2020-03-06 18:15 [PATCH 00/11] Netfilter fixes for net Pablo Neira Ayuso
                   ` (8 preceding siblings ...)
  2020-03-06 18:15 ` [PATCH 09/11] netfilter: nf_tables: dump NFTA_CHAIN_FLAGS attribute Pablo Neira Ayuso
@ 2020-03-06 18:15 ` Pablo Neira Ayuso
  2020-03-06 18:15 ` [PATCH 11/11] netfilter: nft_chain_nat: inet family is missing module ownership Pablo Neira Ayuso
  2020-03-07  5:38 ` [PATCH 00/11] Netfilter fixes for net David Miller
  11 siblings, 0 replies; 13+ messages in thread
From: Pablo Neira Ayuso @ 2020-03-06 18:15 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

From: Florian Westphal <fw@strlen.de>

nft will loop forever if the kernel doesn't support an expression:

1. nft_expr_type_get() appends the family specific name to the module list.
2. -EAGAIN is returned to nfnetlink, nfnetlink calls abort path.
3. abort path sets ->done to true and calls request_module for the
   expression.
4. nfnetlink replays the batch, we end up in nft_expr_type_get() again.
5. nft_expr_type_get attempts to append family-specific name. This
   one already exists on the list, so we continue
6. nft_expr_type_get adds the generic expression name to the module
   list. -EAGAIN is returned, nfnetlink calls abort path.
7. abort path encounters the family-specific expression which
   has 'done' set, so it gets removed.
8. abort path requests the generic expression name, sets done to true.
9. batch is replayed.

If the expression could not be loaded, then we will end up back at 1),
because the family-specific name got removed and the cycle starts again.

Note that userspace can SIGKILL the nft process to stop the cycle, but
the desired behaviour is to return an error after the generic expr name
fails to load the expression.

Fixes: eb014de4fd418 ("netfilter: nf_tables: autoload modules from the abort path")
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nf_tables_api.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index f9e60981bd36..38c680f28f15 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -7388,13 +7388,8 @@ static void nf_tables_module_autoload(struct net *net)
 	list_splice_init(&net->nft.module_list, &module_list);
 	mutex_unlock(&net->nft.commit_mutex);
 	list_for_each_entry_safe(req, next, &module_list, list) {
-		if (req->done) {
-			list_del(&req->list);
-			kfree(req);
-		} else {
-			request_module("%s", req->module);
-			req->done = true;
-		}
+		request_module("%s", req->module);
+		req->done = true;
 	}
 	mutex_lock(&net->nft.commit_mutex);
 	list_splice(&module_list, &net->nft.module_list);
@@ -8177,6 +8172,7 @@ static void __net_exit nf_tables_exit_net(struct net *net)
 	__nft_release_tables(net);
 	mutex_unlock(&net->nft.commit_mutex);
 	WARN_ON_ONCE(!list_empty(&net->nft.tables));
+	WARN_ON_ONCE(!list_empty(&net->nft.module_list));
 }
 
 static struct pernet_operations nf_tables_net_ops = {
-- 
2.11.0


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

* [PATCH 11/11] netfilter: nft_chain_nat: inet family is missing module ownership
  2020-03-06 18:15 [PATCH 00/11] Netfilter fixes for net Pablo Neira Ayuso
                   ` (9 preceding siblings ...)
  2020-03-06 18:15 ` [PATCH 10/11] netfilter: nf_tables: fix infinite loop when expr is not available Pablo Neira Ayuso
@ 2020-03-06 18:15 ` Pablo Neira Ayuso
  2020-03-07  5:38 ` [PATCH 00/11] Netfilter fixes for net David Miller
  11 siblings, 0 replies; 13+ messages in thread
From: Pablo Neira Ayuso @ 2020-03-06 18:15 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

Set owner to THIS_MODULE, otherwise the nft_chain_nat module might be
removed while there are still inet/nat chains in place.

[  117.942096] BUG: unable to handle page fault for address: ffffffffa0d5e040
[  117.942101] #PF: supervisor read access in kernel mode
[  117.942103] #PF: error_code(0x0000) - not-present page
[  117.942106] PGD 200c067 P4D 200c067 PUD 200d063 PMD 3dc909067 PTE 0
[  117.942113] Oops: 0000 [#1] PREEMPT SMP PTI
[  117.942118] CPU: 3 PID: 27 Comm: kworker/3:0 Not tainted 5.6.0-rc3+ #348
[  117.942133] Workqueue: events nf_tables_trans_destroy_work [nf_tables]
[  117.942145] RIP: 0010:nf_tables_chain_destroy.isra.0+0x94/0x15a [nf_tables]
[  117.942149] Code: f6 45 54 01 0f 84 d1 00 00 00 80 3b 05 74 44 48 8b 75 e8 48 c7 c7 72 be de a0 e8 56 e6 2d e0 48 8b 45 e8 48 c7 c7 7f be de a0 <48> 8b 30 e8 43 e6 2d e0 48 8b 45 e8 48 8b 40 10 48 85 c0 74 5b 8b
[  117.942152] RSP: 0018:ffffc9000015be10 EFLAGS: 00010292
[  117.942155] RAX: ffffffffa0d5e040 RBX: ffff88840be87fc2 RCX: 0000000000000007
[  117.942158] RDX: 0000000000000007 RSI: 0000000000000086 RDI: ffffffffa0debe7f
[  117.942160] RBP: ffff888403b54b50 R08: 0000000000001482 R09: 0000000000000004
[  117.942162] R10: 0000000000000000 R11: 0000000000000001 R12: ffff8883eda7e540
[  117.942164] R13: dead000000000122 R14: dead000000000100 R15: ffff888403b3db80
[  117.942167] FS:  0000000000000000(0000) GS:ffff88840e4c0000(0000) knlGS:0000000000000000
[  117.942169] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[  117.942172] CR2: ffffffffa0d5e040 CR3: 00000003e4c52002 CR4: 00000000001606e0
[  117.942174] Call Trace:
[  117.942188]  nf_tables_trans_destroy_work.cold+0xd/0x12 [nf_tables]
[  117.942196]  process_one_work+0x1d6/0x3b0
[  117.942200]  worker_thread+0x45/0x3c0
[  117.942203]  ? process_one_work+0x3b0/0x3b0
[  117.942210]  kthread+0x112/0x130
[  117.942214]  ? kthread_create_worker_on_cpu+0x40/0x40
[  117.942221]  ret_from_fork+0x35/0x40

nf_tables_chain_destroy() crashes on module_put() because the module is
gone.

Fixes: d164385ec572 ("netfilter: nat: add inet family nat support")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nft_chain_nat.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/netfilter/nft_chain_nat.c b/net/netfilter/nft_chain_nat.c
index ff9ac8ae0031..eac4a901233f 100644
--- a/net/netfilter/nft_chain_nat.c
+++ b/net/netfilter/nft_chain_nat.c
@@ -89,6 +89,7 @@ static const struct nft_chain_type nft_chain_nat_inet = {
 	.name		= "nat",
 	.type		= NFT_CHAIN_T_NAT,
 	.family		= NFPROTO_INET,
+	.owner		= THIS_MODULE,
 	.hook_mask	= (1 << NF_INET_PRE_ROUTING) |
 			  (1 << NF_INET_LOCAL_IN) |
 			  (1 << NF_INET_LOCAL_OUT) |
-- 
2.11.0


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

* Re: [PATCH 00/11] Netfilter fixes for net
  2020-03-06 18:15 [PATCH 00/11] Netfilter fixes for net Pablo Neira Ayuso
                   ` (10 preceding siblings ...)
  2020-03-06 18:15 ` [PATCH 11/11] netfilter: nft_chain_nat: inet family is missing module ownership Pablo Neira Ayuso
@ 2020-03-07  5:38 ` David Miller
  11 siblings, 0 replies; 13+ messages in thread
From: David Miller @ 2020-03-07  5:38 UTC (permalink / raw)
  To: pablo; +Cc: netfilter-devel, netdev

From: Pablo Neira Ayuso <pablo@netfilter.org>
Date: Fri,  6 Mar 2020 19:15:02 +0100

> The following patchset contains Netfilter fixes for net:
> 
> 1) Patches to bump position index from sysctl seq_next,
>    from Vasilin Averin.
> 
> 2) Release flowtable hook from error path, from Florian Westphal.
> 
> 3) Patches to add missing netlink attribute validation,
>    from Jakub Kicinski.
> 
> 4) Missing NFTA_CHAIN_FLAGS in nf_tables_fill_chain_info().
> 
> 5) Infinite loop in module autoload if extension is not available,
>    from Florian Westphal.
> 
> 6) Missing module ownership in inet/nat chain type definition.
> 
> You can pull these changes from:
> 
>   git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git

Pulled, thanks Pablo.

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

end of thread, other threads:[~2020-03-07  5:38 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-06 18:15 [PATCH 00/11] Netfilter fixes for net Pablo Neira Ayuso
2020-03-06 18:15 ` [PATCH 01/11] netfilter: nf_conntrack: ct_cpu_seq_next should increase position index Pablo Neira Ayuso
2020-03-06 18:15 ` [PATCH 02/11] netfilter: synproxy: synproxy_cpu_seq_next " Pablo Neira Ayuso
2020-03-06 18:15 ` [PATCH 03/11] netfilter: xt_recent: recent_seq_next " Pablo Neira Ayuso
2020-03-06 18:15 ` [PATCH 04/11] netfilter: x_tables: xt_mttg_seq_next " Pablo Neira Ayuso
2020-03-06 18:15 ` [PATCH 05/11] netfilter: nf_tables: free flowtable hooks on hook register error Pablo Neira Ayuso
2020-03-06 18:15 ` [PATCH 06/11] netfilter: cthelper: add missing attribute validation for cthelper Pablo Neira Ayuso
2020-03-06 18:15 ` [PATCH 07/11] netfilter: nft_payload: add missing attribute validation for payload csum flags Pablo Neira Ayuso
2020-03-06 18:15 ` [PATCH 08/11] netfilter: nft_tunnel: add missing attribute validation for tunnels Pablo Neira Ayuso
2020-03-06 18:15 ` [PATCH 09/11] netfilter: nf_tables: dump NFTA_CHAIN_FLAGS attribute Pablo Neira Ayuso
2020-03-06 18:15 ` [PATCH 10/11] netfilter: nf_tables: fix infinite loop when expr is not available Pablo Neira Ayuso
2020-03-06 18:15 ` [PATCH 11/11] netfilter: nft_chain_nat: inet family is missing module ownership Pablo Neira Ayuso
2020-03-07  5:38 ` [PATCH 00/11] Netfilter fixes for net David Miller

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