Skip to contentSkip to conversation

Netfilter updates for net-next

PATCH Applied Pablo Neira Ayuso 4 participants 18 messages Sep 27 – Oct 5

Subsystems (8)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

cover Netfilter updates for net-next

Hi,

The following patchset contains Netfilter updates for net-next. The fixes included in this batch are deemed to handle correctness issues present in the Netfilter tree:

1) TCP sequence tracking is not reset inconditionally by synproxy when recycling an entry, sashiko reports the zero offset case skips it. Add a new function to inconditionally reset TCP sequence tracking. From Fernando F. Mancera.

2) Update documentation to reflect that the default maximum number of expectations (nf_conntrack_expect_max) is nf_conntrack_buckets / 64. From Shaojie Sun.

3) Remove useless break; after return in nft_osf, from Linkui Xiao.

4) Fix typos in comments in the netfilter tree, from Hemanth Selam.

5) Remove a few conntrack error stats duplicated updates, from Phil Sutter.

6) Do not bump invalid and drop conntrack error stats when packet is dropped, this is another duplicate. also From Phil.

7) Set on netns pointer before registering the flowtable, this is a requirement by the next patch, not fixing an existing issue. From Qingfang Deng.

8) Remove unnecessary workqueue work flush for all of the existing netns when device is gone. Also from Qingfang Deng.

9) Rework-fix nfnetlink_hook to correctly deal with large netlink dumps. Use sequence numbers to detect interference with hook updates while netlink dump is ongoing. From Phil Sutter.

10) Fix ctnetlink dump filtering by the IPv6 address, this has only work correctly for IPv4 this far, from Piotr Kubik.

11) ctnetlink filtering by zone is supported, but the ctnetlink dump filtering infrastructure was never updated to include a flag from userspace, update it to fill this gap. From Ilya Maximets.

Please, pull these changes from:

git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next.git nf-next-26-09-28

Thanks.

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

The following changes since commit 014d795c73837ea2339a4ea8e8f82c6e959b845d:

idpf: fix kernel-doc parameter descriptions (2026-09-25 18:26:50 -0700)

are available in the Git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next.git nf-next-26-09-28

for you to fetch changes up to 46da6029bf468ce3c426cb8b4abf96976ed9d4c8:

netfilter: conntrack: make filtering by zone discoverable (2026-09-27 23:39:21 +0200)

----------------------------------------------------------------
netfilter pull request 26-09-28

----------------------------------------------------------------
Fernando Fernandez Mancera (1):
netfilter: synproxy: fix reset of ct seqadj when reopening a connection

Hemanth Selam (1):
netfilter: fix several typos in comments

Ilya Maximets (1):
netfilter: conntrack: make filtering by zone discoverable

Linkui Xiao (1):
netfilter: osf: remove unreachable break in nf_osf_ttl()

Phil Sutter (3):
netfilter: conntrack: Untangle insert_failed counter from others
netfilter: conntrack: Untangle drop and invalid counters
netfilter: nfnetlink: Fix for interrupted hook dumps

Piotr Kubik (1):
netfilter: ctnetlink: fix inverted IPv6 address match in dump filter

Qingfang Deng (2):
net/sched: act_ct: set net pointer before publishing flowtable
netfilter: flowtable: check namespace before iterating flows

Shaojie Sun (1):
netfilter: conntrack: fix nf_conntrack_expect_max default value in documentation

 Documentation/netlink/specs/conntrack.yaml         |   6 +
 Documentation/networking/nf_conntrack-sysctl.rst   |   2 +-
 include/net/netfilter/nf_conntrack_seqadj.h        |   1 +
 include/net/netns/netfilter.h                      |   2 +
 include/uapi/linux/netfilter/nfnetlink_conntrack.h |   1 +
 net/ipv4/netfilter/arp_tables.c                    |   2 +-
 net/netfilter/core.c                               |  18 ++-
 net/netfilter/ipset/ip_set_core.c                  |   2 +-
 net/netfilter/ipvs/ip_vs_sync.c                    |   2 +-
 net/netfilter/nf_conntrack_core.c                  |   5 +-
 net/netfilter/nf_conntrack_netlink.c               |  19 ++-
 net/netfilter/nf_conntrack_seqadj.c                |  17 +++
 net/netfilter/nf_flow_table_core.c                 |  17 +--
 net/netfilter/nf_nat_core.c                        |  11 ++
 net/netfilter/nf_synproxy_core.c                   |   4 +-
 net/netfilter/nfnetlink_hook.c                     |  74 ++++++-----
 net/netfilter/nfnetlink_osf.c                      |   1 -
 net/sched/act_ct.c                                 |   2 +-
 .../selftests/net/netfilter/conntrack_dump_flush.c | 145 ++++++++++++++-------
 .../net/netfilter/conntrack_icmp_related.sh        |   2 +-
 20 files changed, 229 insertions(+), 104 deletions(-)
author maintainer
#1 lore raw

PATCH 1/11 netfilter: synproxy: fix reset of ct seqadj when reopening a connection

From: Fernando Fernandez Mancera <[email protected]>

SYNPROXY is resetting conntrack seqadj when a closed connection is re-opened, but it was using nf_ct_seqadj_init() which is a no-op for a zero offset.

This patch introduces nf_ct_seqadj_reset() which sets the offset values directly to zero and avoid setting IPS_SEQ_ADJUST_BIT flag, it changes SYNPROXY code to use it when needed.

Fixes 48b1de4c110a ("netfilter: add SYNPROXY core/target")
---
 include/net/netfilter/nf_conntrack_seqadj.h |  1 +
 net/netfilter/nf_conntrack_seqadj.c         | 17 +++++++++++++++++
 net/netfilter/nf_synproxy_core.c            |  4 ++--
 3 files changed, 20 insertions(+), 2 deletions(-)
include/net/netfilter/nf_conntrack_seqadj.h +1 -0
index 883c414b768e..0f5bbb14a25a 100644
@@ -33,6 +33,7 @@ static inline struct nf_conn_seqadj *nfct_seqadj_ext_add(struct nf_conn *ct)
 
 int nf_ct_seqadj_init(struct nf_conn *ct, enum ip_conntrack_info ctinfo,
 		      s32 off);
+void nf_ct_seqadj_reset(struct nf_conn *ct, enum ip_conntrack_info ctinfo);
 int nf_ct_seqadj_set(struct nf_conn *ct, enum ip_conntrack_info ctinfo,
 		     __be32 seq, s32 off);
 void nf_ct_tcp_seqadj_set(struct sk_buff *skb, struct nf_conn *ct,
net/netfilter/nf_conntrack_seqadj.c +17 -0
index d75e8dafb189..b7b166a8ad58 100644
@@ -31,6 +31,23 @@ int nf_ct_seqadj_init(struct nf_conn *ct, enum ip_conntrack_info ctinfo,
 }
 EXPORT_SYMBOL_GPL(nf_ct_seqadj_init);
 
+void nf_ct_seqadj_reset(struct nf_conn *ct, enum ip_conntrack_info ctinfo)
+{
+	struct nf_conn_seqadj *seqadj = nfct_seqadj(ct);
+	enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);
+	struct nf_ct_seqadj *this_way;
+
+	if (unlikely(!seqadj))
+		return;
+
+	spin_lock_bh(&ct->lock);
+	this_way = &seqadj->seq[dir];
+	this_way->offset_before	 = 0;
+	this_way->offset_after	 = 0;
+	spin_unlock_bh(&ct->lock);
+}
+EXPORT_SYMBOL_GPL(nf_ct_seqadj_reset);
+
 int nf_ct_seqadj_set(struct nf_conn *ct, enum ip_conntrack_info ctinfo,
 		     __be32 seq, s32 off)
 {
net/netfilter/nf_synproxy_core.c +2 -2
index 9fc959ba2030..401ce5a13f3f 100644
@@ -686,7 +686,7 @@ ipv4_synproxy_hook(void *priv, struct sk_buff *skb,
 		 * adjustments, they will get initialized once the connection is
 		 * reestablished.
 		 */
-		nf_ct_seqadj_init(ct, ctinfo, 0);
+		nf_ct_seqadj_reset(ct, ctinfo);
 		synproxy->tsoff = 0;
 		this_cpu_inc(snet->stats->conn_reopened);
 		fallthrough;
@@ -1116,7 +1116,7 @@ ipv6_synproxy_hook(void *priv, struct sk_buff *skb,
 		 * adjustments, they will get initialized once the connection is
 		 * reestablished.
 		 */
-		nf_ct_seqadj_init(ct, ctinfo, 0);
+		nf_ct_seqadj_reset(ct, ctinfo);
 		synproxy->tsoff = 0;
 		this_cpu_inc(snet->stats->conn_reopened);
 		fallthrough;
Signature · 1 line
2.47.3
#2 lore raw

Re: [PATCH net-next 01/11] netfilter: synproxy: fix reset of ct seqadj when reopening a connection

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.

- Whether the issue was actually triggered, or is only theoretical (e.g. found by code inspection). If it was triggered please include the symptoms, like the stack trace or error messages.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.

The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.

author maintainer
#3 lore raw

Re: [PATCH net-next 01/11] netfilter: synproxy: fix reset of ct seqadj when reopening a connection

Hi,

Quoted 13 lines · On Sun, Sep 27, 2026 at 10:40:44PM +0000, [email protected] wrote:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.

- Whether the issue was actually triggered, or is only theoretical (e.g. found by code inspection). If it was triggered please include the symptoms, like the stack trace or error messages.

Quoted 8 lines

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.

The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.

This are correctness fixes (no crashes to my knowledged, hence I decided to target net-next) as the cover letter specifies:

Patch #1 TCP sequence tracking issue was reported by sashiko as the
cover letter says.

Patch #2 Just documentation update to fix incorrect information
about the maximum number of expectations.

Patch #3 Just a cleanup patch to remove a break;

Patch #4 Just a cleanup, typos in comments.

Patch #5 and #6 are the result of a human triggered review of the
conntrack error stats by Phil Sutter, I think.

Patch #7 is a preparation patch for #8.

Patch #8 removes a unnecessary workqueue flush, submitter does not
specify if it is visible in production, I suspect with a very large number of netns it must be. Author does not claim LLM assistance.

Patch #9 is a fix triggered by sashiko report IIRC, I deemed it too
large for net so I am routing this rework-fix to net-next.

Patch #10 is a feature fix, IPv6 filtering does not work.
I suspect it was found when trying to use this (broken) feature by the submitter.

Patch #11 Ilya Maximets reports the CTA_ZONE filtering feature is
not easy to infer from userspace, I don't think LLM triggered this, it looks more like an improvement to help userspace tools discover this feature.

This is human written reply, my cover letter has been generated by me too to provide more context on these patches.

Thanks!

author maintainer
#4 lore raw

Re: [PATCH net-next 01/11] netfilter: synproxy: fix reset of ct seqadj when reopening a connection

Hi,

Just a gentle bump to this net-next PR containing Netfilter updates.

Let me know if there is anything that needs to be addressed.

Thanks.

Quoted 65 lines · Pablo Neira Ayuso

Hi,

Quoted 13 lines · On Sun, Sep 27, 2026 at 10:40:44PM +0000, [email protected] wrote:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.

- Whether the issue was actually triggered, or is only theoretical (e.g. found by code inspection). If it was triggered please include the symptoms, like the stack trace or error messages.

Quoted 8 lines

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.

The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.

This are correctness fixes (no crashes to my knowledged, hence I decided to target net-next) as the cover letter specifies:

Patch #1 TCP sequence tracking issue was reported by sashiko as the
cover letter says.

Patch #2 Just documentation update to fix incorrect information
about the maximum number of expectations.

Patch #3 Just a cleanup patch to remove a break;

Patch #4 Just a cleanup, typos in comments.

Patch #5 and #6 are the result of a human triggered review of the
conntrack error stats by Phil Sutter, I think.

Patch #7 is a preparation patch for #8.

Patch #8 removes a unnecessary workqueue flush, submitter does not
specify if it is visible in production, I suspect with a very large number of netns it must be. Author does not claim LLM assistance.

Patch #9 is a fix triggered by sashiko report IIRC, I deemed it too
large for net so I am routing this rework-fix to net-next.

Patch #10 is a feature fix, IPv6 filtering does not work.
I suspect it was found when trying to use this (broken) feature by the submitter.

Patch #11 Ilya Maximets reports the CTA_ZONE filtering feature is
not easy to infer from userspace, I don't think LLM triggered this, it looks more like an improvement to help userspace tools discover this feature.

This is human written reply, my cover letter has been generated by me too to provide more context on these patches.

Thanks!

#5 lore raw

Re: [PATCH net-next 01/11] netfilter: synproxy: fix reset of ct seqadj when reopening a connection

Quoted 5 lines · Pablo Neira Ayuso

Hi,

Just a gentle bump to this net-next PR containing Netfilter updates.

Let me know if there is anything that needs to be addressed.

AFAICT, this PR was merged to net-next on the 29th:
https://git.kernel.org/netdev/net-next/c/0a1a3898ab64fd4f7b90816fc61186d8eb5302a7

The bot was a little confused, but the reply was actually sent:
https://lore.kernel.org/all/179064961102.229594.11396134169189168960.git-patchwork-notify@kernel.org/

Best regards, Ilya Maximets.

Quoted 69 lines

Thanks.

Quoted 65 lines · Pablo Neira Ayuso

Hi,

Quoted 13 lines · On Sun, Sep 27, 2026 at 10:40:44PM +0000, [email protected] wrote:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.

- Whether the issue was actually triggered, or is only theoretical (e.g. found by code inspection). If it was triggered please include the symptoms, like the stack trace or error messages.

Quoted 8 lines

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.

The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.

This are correctness fixes (no crashes to my knowledged, hence I decided to target net-next) as the cover letter specifies:

Patch #1 TCP sequence tracking issue was reported by sashiko as the
cover letter says.

Patch #2 Just documentation update to fix incorrect information
about the maximum number of expectations.

Patch #3 Just a cleanup patch to remove a break;

Patch #4 Just a cleanup, typos in comments.

Patch #5 and #6 are the result of a human triggered review of the
conntrack error stats by Phil Sutter, I think.

Patch #7 is a preparation patch for #8.

Patch #8 removes a unnecessary workqueue flush, submitter does not
specify if it is visible in production, I suspect with a very large number of netns it must be. Author does not claim LLM assistance.

Patch #9 is a fix triggered by sashiko report IIRC, I deemed it too
large for net so I am routing this rework-fix to net-next.

Patch #10 is a feature fix, IPv6 filtering does not work.
I suspect it was found when trying to use this (broken) feature by the submitter.

Patch #11 Ilya Maximets reports the CTA_ZONE filtering feature is
not easy to infer from userspace, I don't think LLM triggered this, it looks more like an improvement to help userspace tools discover this feature.

This is human written reply, my cover letter has been generated by me too to provide more context on these patches.

Thanks!

author maintainer
#6 lore raw

Re: [PATCH net-next 01/11] netfilter: synproxy: fix reset of ct seqadj when reopening a connection

Quoted 5 lines · Ilya Maximets
Quoted 4 lines · Pablo Neira Ayuso

Hi,

Just a gentle bump to this net-next PR containing Netfilter updates.

Quoted 7 lines
Quoted 1 line

Let me know if there is anything that needs to be addressed.

AFAICT, this PR was merged to net-next on the 29th:
https://git.kernel.org/netdev/net-next/c/0a1a3898ab64fd4f7b90816fc61186d8eb5302a7

The bot was a little confused, but the reply was actually sent:
https://lore.kernel.org/all/179064961102.229594.11396134169189168960.git-patchwork-notify@kernel.org/

Indeed, all then, thanks!

#7 lore raw

Re: [PATCH net-next 01/11] netfilter: synproxy: fix reset of ct seqadj when reopening a connection

In reply to Pablo Neira Ayuso
This series was applied to netdev/net-next.git (main) by Pablo Neira Ayuso <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Pablo Neira Ayuso <[email protected]>:

Quoted 11 lines · On Mon, 28 Sep 2026 00:34:26 +0200 you wrote:

From: Fernando Fernandez Mancera <[email protected]>

SYNPROXY is resetting conntrack seqadj when a closed connection is re-opened, but it was using nf_ct_seqadj_init() which is a no-op for a zero offset.

This patch introduces nf_ct_seqadj_reset() which sets the offset values directly to zero and avoid setting IPS_SEQ_ADJUST_BIT flag, it changes SYNPROXY code to use it when needed.

[...]

Here is the summary with links:
- [net-next,01/11] netfilter: synproxy: fix reset of ct seqadj when reopening a connection

    https://git.kernel.org/netdev/net-next/c/a8708aa9fe10
  - [net-next,02/11] netfilter: conntrack: fix nf_conntrack_expect_max default value in documentation
    https://git.kernel.org/netdev/net-next/c/409df11c5674
  - [net-next,03/11] netfilter: osf: remove unreachable break in nf_osf_ttl()
    https://git.kernel.org/netdev/net-next/c/32cbf7a8e556
  - [net-next,04/11] netfilter: fix several typos in comments
    https://git.kernel.org/netdev/net-next/c/d8cefdc18124
  - [net-next,05/11] netfilter: conntrack: Untangle insert_failed counter from others
    https://git.kernel.org/netdev/net-next/c/96ed91f5773a
  - [net-next,06/11] netfilter: conntrack: Untangle drop and invalid counters
    https://git.kernel.org/netdev/net-next/c/2ac41d7009c7
  - [net-next,07/11] net/sched: act_ct: set net pointer before publishing flowtable
    https://git.kernel.org/netdev/net-next/c/d4548625f38b
  - [net-next,08/11] netfilter: flowtable: check namespace before iterating flows
    https://git.kernel.org/netdev/net-next/c/c48fdf027a72
  - [net-next,09/11] netfilter: nfnetlink: Fix for interrupted hook dumps
    https://git.kernel.org/netdev/net-next/c/d3950004ba90
  - [net-next,10/11] netfilter: ctnetlink: fix inverted IPv6 address match in dump filter
    https://git.kernel.org/netdev/net-next/c/1ae2d094b020
  - [net-next,11/11] netfilter: conntrack: make filtering by zone discoverable
    https://git.kernel.org/netdev/net-next/c/46da6029bf46

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
author maintainer
#8 lore raw

PATCH 2/11 netfilter: conntrack: fix nf_conntrack_expect_max default value in documentation

In reply to Pablo Neira Ayuso

From: Shaojie Sun <[email protected]>

The documentation for nf_conntrack_expect_max incorrectly states that the default value is nf_conntrack_buckets / 256. However, the code in nf_conntrack_expect_init() shows:

    nf_ct_expect_hsize = nf_conntrack_htable_size / 256;
    nf_ct_expect_max = nf_ct_expect_hsize * 4;

This means the default value is actually nf_conntrack_buckets / 64 (i.e. 4 times the hash table size, which defaults to nf_conntrack_buckets / 256).

Fix the documentation to reflect the correct default value and add explanation of the calculation.

---
 Documentation/networking/nf_conntrack-sysctl.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/networking/nf_conntrack-sysctl.rst +1 -1
index 35f889259fcd..4426cce2a73f 100644
@@ -44,7 +44,7 @@ nf_conntrack_events - BOOLEAN
 
 nf_conntrack_expect_max - INTEGER
 	Maximum size of expectation table.  Default value is
-	nf_conntrack_buckets / 256. Minimum is 1.
+	nf_conntrack_buckets / 64. Minimum is 1.
 
 nf_conntrack_frag6_high_thresh - INTEGER
 	default 262144
Signature · 1 line
2.47.3
author maintainer
#9 lore raw

PATCH 3/11 netfilter: osf: remove unreachable break in nf_osf_ttl()

In reply to Pablo Neira Ayuso

From: Linkui Xiao <[email protected]>

In nf_osf_ttl(), the break statement after return in NF_OSF_TTL_TRUE case is unreachable dead‑code. The return statement exits the function immediately, so break will never execute.

Remove the useless break, no functional change.

---
 net/netfilter/nfnetlink_osf.c | 1 -
 1 file changed, 1 deletion(-)
net/netfilter/nfnetlink_osf.c +0 -1
index e4835b0f4bb1..c8cd6af95db4 100644
@@ -36,7 +36,6 @@ static inline int nf_osf_ttl(const struct sk_buff *skb,
 	switch (ttl_check) {
 	case NF_OSF_TTL_TRUE:
 		return ip->ttl == f_ttl;
-		break;
 	case NF_OSF_TTL_NOCHECK:
 		return 1;
 	case NF_OSF_TTL_LESS:
Signature · 1 line
2.47.3
author maintainer
#10 lore raw

PATCH 4/11 netfilter: fix several typos in comments

In reply to Pablo Neira Ayuso

From: Hemanth Selam <[email protected]>

Fix typos reported by scripts/checkpatch.pl using the misspelling list in scripts/spelling.txt. Only touches comments, no code changes.

Assisted-by Cursor:claude-opus-5
---
 net/ipv4/netfilter/arp_tables.c                                 | 2 +-
 net/netfilter/ipset/ip_set_core.c                               | 2 +-
 net/netfilter/ipvs/ip_vs_sync.c                                 | 2 +-
 tools/testing/selftests/net/netfilter/conntrack_icmp_related.sh | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
net/ipv4/netfilter/arp_tables.c +1 -1
index db307fa49f3f..cf747e1e17a3 100644
@@ -58,7 +58,7 @@ static inline int arp_devaddr_compare(const struct arpt_devaddr_info *ap,
 /*
  * Unfortunately, _b and _mask are not aligned to an int (or long int)
  * Some arches dont care, unrolling the loop is a win on them.
- * For other arches, we only have a 16bit alignement.
+ * For other arches, we only have a 16bit alignment.
  */
 static unsigned long ifname_compare(const char *_a, const char *_b, const char *_mask)
 {
net/netfilter/ipset/ip_set_core.c +1 -1
index 0a86a170ba90..4aeb767088cf 100644
@@ -1426,7 +1426,7 @@ static int ip_set_swap(struct sk_buff *skb, const struct nfnl_info *info,
 		return -IPSET_ERR_EXIST_SETNAME2;
 
 	/* Features must not change.
-	 * Not an artifical restriction anymore, as we must prevent
+	 * Not an artificial restriction anymore, as we must prevent
 	 * possible loops created by swapping in setlist type of sets.
 	 */
 	if (!(from->type->features == to->type->features &&
net/netfilter/ipvs/ip_vs_sync.c +1 -1
index 5383aeafb0ae..4dacd5af65db 100644
@@ -1344,7 +1344,7 @@ static void set_mcast_pmtudisc(struct sock *sk, int val)
 }
 
 /*
- *      Specifiy default interface for outgoing multicasts
+ *      Specify default interface for outgoing multicasts
  */
 static int set_mcast_if(struct sock *sk, struct net_device *dev)
 {
tools/testing/selftests/net/netfilter/conntrack_icmp_related.sh +1 -1
index c63d840ead61..f63b7f12b36a 100755
@@ -171,7 +171,7 @@ table inet filter {
 }
 EOF
 
-# make sure NAT core rewrites adress of icmp error if nat is used according to
+# make sure NAT core rewrites address of icmp error if nat is used according to
 # conntrack nat information (icmp error will be directed at nsrouter1 address,
 # but it needs to be routed to nsclient1 address).
 ip netns exec "$nsrouter1" nft -f - <<EOF
Signature · 1 line
2.47.3
author maintainer
#11 lore raw

PATCH 5/11 netfilter: conntrack: Untangle insert_failed counter from others

In reply to Pablo Neira Ayuso

From: Phil Sutter <[email protected]>

There is not much sense in incrementing multiple conntrack counters for the same situation. Defining insert_failed as a situation where a valid packet's conntrack can't be confirmed due to unresolvable clash sets it apart from 'drop' (ENOMEM situation) and 'chaintoolong'.

---
 net/netfilter/nf_conntrack_core.c | 2 --
 1 file changed, 2 deletions(-)
net/netfilter/nf_conntrack_core.c +0 -2
index d0d9e5ea84a0..53401e21ad99 100644
@@ -1169,7 +1169,6 @@ nf_ct_resolve_clash(struct sk_buff *skb, struct nf_conntrack_tuple_hash *h,
 		return ret;
 
 drop:
-	NF_CT_STAT_INC(net, drop);
 	NF_CT_STAT_INC(net, insert_failed);
 	return NF_DROP;
 }
@@ -1259,7 +1258,6 @@ __nf_conntrack_confirm(struct sk_buff *skb)
 		if (chainlen++ > max_chainlen) {
 chaintoolong:
 			NF_CT_STAT_INC(net, chaintoolong);
-			NF_CT_STAT_INC(net, insert_failed);
 			ret = NF_DROP;
 			goto dying;
 		}
Signature · 1 line
2.47.3
author maintainer
#12 lore raw

PATCH 6/11 netfilter: conntrack: Untangle drop and invalid counters

In reply to Pablo Neira Ayuso

From: Phil Sutter <[email protected]>

In nf_conntrack_in, 'drop' counter increments if nf_conntrack_handle_packet returns NF_DROP. This is a special case with TCP packets (added by commit 6b69fe0c73c0 ("netfilter: nf_conntrack_tcp:
fix endless loop") and not related to invalid packets which are responsible for all the other <=0 returns. So don't increment 'invalid' ounter in this case.

---
 net/netfilter/nf_conntrack_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/netfilter/nf_conntrack_core.c +2 -1
index 53401e21ad99..f9b8927327ba 100644
@@ -2065,9 +2065,10 @@ nf_conntrack_in(struct sk_buff *skb, const struct nf_hook_state *state)
 		if (ret == -NF_REPEAT)
 			goto repeat;
 
-		NF_CT_STAT_INC_ATOMIC(state->net, invalid);
 		if (ret == NF_DROP)
 			NF_CT_STAT_INC_ATOMIC(state->net, drop);
+		else
+			NF_CT_STAT_INC_ATOMIC(state->net, invalid);
 
 		ret = -ret;
 		goto out;
Signature · 1 line
2.47.3
author maintainer
#13 lore raw

PATCH 7/11 net/sched: act_ct: set net pointer before publishing flowtable

In reply to Pablo Neira Ayuso

From: Qingfang Deng <[email protected]>

nf_flow_table_init() adds the flowtable to the global flowtables list. However, tcf_ct_flow_table_get() sets the table's network namespace only after that call, leaving a window where the published table has a NULL namespace pointer.

Set the namespace before calling nf_flow_table_init() so that flowtable list walkers can rely on it being initialized.

This is required by:
"netfilter: flowtable: check namespace before iterating flows"

---
 net/sched/act_ct.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/act_ct.c +1 -1
index 411e3dd92d07..e26c0d5b2176 100644
@@ -349,10 +349,10 @@ static int tcf_ct_flow_table_get(struct net *net, struct tcf_ct_params *params)
 	ct_ft->nf_ft.type = &flowtable_ct;
 	ct_ft->nf_ft.flags |= NF_FLOWTABLE_HW_OFFLOAD |
 			      NF_FLOWTABLE_COUNTER;
+	write_pnet(&ct_ft->nf_ft.net, net);
 	err = nf_flow_table_init(&ct_ft->nf_ft);
 	if (err)
 		goto err_init;
-	write_pnet(&ct_ft->nf_ft.net, net);
 
 	__module_get(THIS_MODULE);
 out_unlock:
Signature · 1 line
2.47.3
author maintainer
#14 lore raw

PATCH 8/11 netfilter: flowtable: check namespace before iterating flows

In reply to Pablo Neira Ayuso

From: Qingfang Deng <[email protected]>

nf_flow_table_cleanup() walks every registered flow table, checking the network namespace for each flow in nf_flow_table_do_cleanup(). As a result, tables in other namespaces are still iterated and their cleanup work is flushed.

Compare the flow table's namespace with the device's namespace in nf_flow_table_cleanup() and skip nonmatching tables. This avoids unnecessary iteration and work flushing, and leaves the per-flow cleanup callback to check only the interface index.

---
 net/netfilter/nf_flow_table_core.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
net/netfilter/nf_flow_table_core.c +7 -10
index 934c6151f558..bd8f9cf394ff 100644
@@ -737,14 +737,9 @@ static void nf_flow_table_do_cleanup(struct nf_flowtable *flow_table,
 {
 	struct net_device *dev = data;
 
-	if (!dev) {
-		flow_offload_teardown(flow);
-		return;
-	}
-
-	if (net_eq(nf_ct_net(flow->ct), dev_net(dev)) &&
-	    (flow->tuplehash[0].tuple.iifidx == dev->ifindex ||
-	     flow->tuplehash[1].tuple.iifidx == dev->ifindex))
+	if (!dev ||
+	    flow->tuplehash[0].tuple.iifidx == dev->ifindex ||
+	    flow->tuplehash[1].tuple.iifidx == dev->ifindex)
 		flow_offload_teardown(flow);
 }
 
@@ -761,8 +756,10 @@ void nf_flow_table_cleanup(struct net_device *dev)
 	struct nf_flowtable *flowtable;
 
 	mutex_lock(&flowtable_lock);
-	list_for_each_entry(flowtable, &flowtables, list)
-		nf_flow_table_gc_cleanup(flowtable, dev);
+	list_for_each_entry(flowtable, &flowtables, list) {
+		if (net_eq(read_pnet(&flowtable->net), dev_net(dev)))
+			nf_flow_table_gc_cleanup(flowtable, dev);
+	}
 	mutex_unlock(&flowtable_lock);
 }
 EXPORT_SYMBOL_GPL(nf_flow_table_cleanup);
Signature · 1 line
2.47.3
author maintainer
#15 lore raw

PATCH 9/11 netfilter: nfnetlink: Fix for interrupted hook dumps

In reply to Pablo Neira Ayuso

From: Phil Sutter <[email protected]>

Handling of concurrent hook changes with a dump in progress was problematic in nfnl_hook_dump and entirely broken in nfnl_hook_dump_nat. Address all issues in a single patch to please the review LLM.

Introduce sequence numbers in struct netns_nf to replace pointer value-based modification detection which may fail due to memory buffer reuse. This also eliminates the need for most manual cb->seq updates and excessive array index value checks.

Since nat hook updates are protected by a different mutex than others, they have to bump their own sequence number. nfnl_hook_dump_nat therefore open-codes what nl_dump_check_consistent does but bumps cb->seq instead of setting NLM_F_DUMP_INTR flag.

Dumps of many nat hooks was entirely broken since the array index was not (re)stored. Use cb->args[1] for that and make sure it is reset upon completion as the same dump may loop over multiple arrays of nat hooks.

In nfnl_hook_dump, don't signal NLM_F_DUMP_INTR if nfnl_hook_entries_head returns error: This is a permanent condition which does not change during a dump. It is already caught by nfnl_hook_dump_start though, so should not happen anyway.

In general, access ops array pointer values using READ_ONCE since they are assigned to using WRITE_ONCE.

Avoid setting NLM_F_DUMP_INTR flag in garbage memory by calling nl_dump_check_consistent only for non-empty skbs. If not a single netlink message was created, nfnetlink code will take care of setting the flag.

Fixes e2cf17d3774c ("netfilter: add new hook nfnl subsystem")
Fixes b010e2a4a9ac ("netfilter: nfnetlink_hook: Dump nat type chains")
---
 include/net/netns/netfilter.h  |  2 +
 net/netfilter/core.c           | 18 ++++++++-
 net/netfilter/nf_nat_core.c    | 11 +++++
 net/netfilter/nfnetlink_hook.c | 74 ++++++++++++++++++++--------------
 4 files changed, 73 insertions(+), 32 deletions(-)
include/net/netns/netfilter.h +2 -0
index a6a0bf4a247e..7fd78394d1e7 100644
@@ -33,5 +33,7 @@ struct netns_nf {
 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
 	unsigned int defrag_ipv6_users;
 #endif
+	unsigned int hook_base_seq;
+	unsigned int nat_hook_base_seq;
 };
 #endif
net/netfilter/core.c +17 -1
index 675a1034b340..940dea2663e9 100644
@@ -386,6 +386,15 @@ static void nf_static_key_dec(const struct nf_hook_ops *reg, int pf)
 #endif
 }
 
+static void bump_hook_base_seq(struct net *net)
+{
+	unsigned int base_seq = READ_ONCE(net->nf.hook_base_seq);
+
+	while (++base_seq == 0)
+		;
+	smp_store_release(&net->nf.hook_base_seq, base_seq);
+}
+
 static int __nf_register_net_hook(struct net *net, int pf,
 				  const struct nf_hook_ops *reg)
 {
@@ -430,6 +439,7 @@ static int __nf_register_net_hook(struct net *net, int pf,
 	if (!IS_ERR(new_hooks)) {
 		hooks_validate(new_hooks);
 		rcu_assign_pointer(*pp, new_hooks);
+		bump_hook_base_seq(net);
 	}
 
 	mutex_unlock(&nf_hook_mutex);
@@ -483,6 +493,7 @@ static void __nf_unregister_net_hook(struct net *net, int pf,
 {
 	struct nf_hook_entries __rcu **pp;
 	struct nf_hook_entries *p;
+	bool found;
 
 	pp = nf_hook_entry_head(net, pf, reg->hooknum, reg->dev);
 	if (!pp)
@@ -496,7 +507,8 @@ static void __nf_unregister_net_hook(struct net *net, int pf,
 		return;
 	}
 
-	if (nf_remove_net_hook(p, reg)) {
+	found = nf_remove_net_hook(p, reg);
+	if (found) {
 #ifdef CONFIG_NETFILTER_INGRESS
 		if (nf_ingress_hook(reg, pf))
 			net_dec_ingress_queue();
@@ -511,6 +523,8 @@ static void __nf_unregister_net_hook(struct net *net, int pf,
 	}
 
 	p = __nf_hook_entries_try_shrink(p, pp);
+	if (found)
+		bump_hook_base_seq(net);
 	mutex_unlock(&nf_hook_mutex);
 	if (!p)
 		return;
@@ -784,6 +798,8 @@ static int __net_init netfilter_net_init(struct net *net)
 		return -ENOMEM;
 	}
 #endif
+	net->nf.hook_base_seq = 1;
+	net->nf.nat_hook_base_seq = 1;
 
 	return 0;
 }
net/netfilter/nf_nat_core.c +11 -0
index 84f82957e66b..5ddd5fc95b24 100644
@@ -1160,6 +1160,15 @@ nfnetlink_parse_nat_setup(struct nf_conn *ct,
 }
 #endif
 
+static void bump_nat_hook_base_seq(struct net *net)
+{
+	unsigned int base_seq = READ_ONCE(net->nf.nat_hook_base_seq);
+
+	while (++base_seq == 0)
+		;
+	smp_store_release(&net->nf.nat_hook_base_seq, base_seq);
+}
+
 static struct nf_ct_helper_expectfn follow_master_nat = {
 	.name		= "nat-follow-master",
 	.expectfn	= nf_nat_follow_master,
@@ -1245,6 +1254,7 @@ int nf_nat_register_fn(struct net *net, u8 pf, const struct nf_hook_ops *ops,
 		nat_proto_net->nat_hook_ops = nat_ops;
 
 	nat_proto_net->users++;
+	bump_nat_hook_base_seq(net);
 
 	mutex_unlock(&nf_nat_proto_mutex);
 
@@ -1299,6 +1309,7 @@ void nf_nat_unregister_fn(struct net *net, u8 pf, const struct nf_hook_ops *ops,
 		goto unlock;
 	priv = nat_ops[hooknum].priv;
 	nf_hook_entries_delete_raw(&priv->entries, ops);
+	bump_nat_hook_base_seq(net);
 
 	if (nat_proto_net->users == 0) {
 		nf_unregister_net_hooks(net, nat_ops, ops_count);
net/netfilter/nfnetlink_hook.c +43 -31

122 lines not on this page · raw message

Signature · 1 line
2.47.3
author maintainer
#16 lore raw

PATCH 10/11 netfilter: ctnetlink: fix inverted IPv6 address match in dump filter

In reply to Pablo Neira Ayuso

From: Piotr Kubik <[email protected]>

ctnetlink_filter_match_tuple() rejects an entry when !ipv6_addr_cmp(filter, entry) is true. ipv6_addr_cmp() is a memcmp() and returns 0 for equal addresses, so the condition is true exactly when the addresses match: a CTA_FILTER dump with an IPv6 CTA_IP_SRC or CTA_IP_DST skips every entry that matches the requested address and returns all the others. The IPv4 branch compares with != and behaves correctly.

Observed with libnetfilter_conntrack NFCT_FILTER_DUMP_TUPLE: a dump filtered on src 2001:db8::10 returned only the unrelated entries, and a dump filtered on ::1 returned every entry except the ::1 ones. conntrack-tools does not use the tuple filter for -L, which is why this went unnoticed.

Use ipv6_addr_equal() so the IPv6 branch mirrors the IPv4 one.

Fixes cb8aa9a3affb ("netfilter: ctnetlink: add kernel side filtering for dump")
---
 net/netfilter/nf_conntrack_netlink.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
net/netfilter/nf_conntrack_netlink.c +4 -4
index 4e5d7c701436..e8477f792c95 100644
@@ -1098,13 +1098,13 @@ static int ctnetlink_filter_match_tuple(struct nf_conntrack_tuple *filter_tuple,
 		break;
 	case NFPROTO_IPV6:
 		if ((flags & CTA_FILTER_FLAG(CTA_IP_SRC)) &&
-		    !ipv6_addr_cmp(&filter_tuple->src.u3.in6,
-				   &ct_tuple->src.u3.in6))
+		    !ipv6_addr_equal(&filter_tuple->src.u3.in6,
+				     &ct_tuple->src.u3.in6))
 			return 0;
 
 		if ((flags & CTA_FILTER_FLAG(CTA_IP_DST)) &&
-		    !ipv6_addr_cmp(&filter_tuple->dst.u3.in6,
-				   &ct_tuple->dst.u3.in6))
+		    !ipv6_addr_equal(&filter_tuple->dst.u3.in6,
+				     &ct_tuple->dst.u3.in6))
 			return 0;
 		break;
 	}
Signature · 1 line
2.47.3
author maintainer
#17 lore raw

PATCH 11/11 netfilter: conntrack: make filtering by zone discoverable

In reply to Pablo Neira Ayuso

From: Ilya Maximets <[email protected]>

Conntrack flush supports filtering by zone using CTA_ZONE, but this attribute is really hard to use from user space applications. The reason is that it is not possible to tell if it's supported or not.

Older kernels silently ignore CTA_ZONE. And in that case they just happily flush all the entries from all zones breaking all the existing connections. So, applications have to infer support from the kernel version. While it works in most cases, it's not a particularly reliable or desired way to check kernel capabilities from applications that aim to be portable. There should be a better way to probe or discover features in the kernel.

The CTA_FILTER interface on the other hand is simple enough to probe. We can check for NLM_F_DUMP_FILTERED in the dump to see if filtering is supported. And unknown sub-attributes in CTA_FILTER are rejected explicitly since strict validation is in use there.

Let's add new CTA_FILTER_ZONE that signals that CTA_ZONE should be filtered on. It is a flag, since everything in the CTA_FILTER is a bit mask, i.e., a form of a flag. If set, it means that CTA_ZONE must be present and be used for filtering. If the flag is not set however, the filtering on CTA_ZONE will still take place to ensure backwards compatibility. So, the flag doesn't really change the filtering behavior, but it allows user space applications to properly discover support for CTA_ZONE filtering without need to rely on kernel version parsing or risk accidental flushes of the entire conntrack table, and also without modifying the kernel state.

A new test variant is added to test with and without the new flag. Since the setup code is moved into a shared function, expectations replaced with assertions to bail early if the base setup fails to avoid the cascade of secondary failures that can be misleading. Error return is only for the SKIP cases.

---
 Documentation/netlink/specs/conntrack.yaml    |   6 +
 .../linux/netfilter/nfnetlink_conntrack.h     |   1 +
 net/netfilter/nf_conntrack_netlink.c          |  11 ++
 .../net/netfilter/conntrack_dump_flush.c      | 145 ++++++++++++------
 4 files changed, 117 insertions(+), 46 deletions(-)
Documentation/netlink/specs/conntrack.yaml +6 -0
index 1d163130241a..56c13705243b 100644
@@ -393,6 +393,12 @@ attribute-sets:
         name: reply-flags
         type: u32
         doc: bitmask of tuple fields to filter on, reply direction
+      -
+        name: zone
+        type: flag
+        doc: >-
+          Filter on conntrack zone id; requires the top-level zone
+          (``CTA_ZONE``) attribute.
   -
     name: conntrack-attrs
     attributes:
include/uapi/linux/netfilter/nfnetlink_conntrack.h +1 -0
index 43233af75b9d..985f9c08d3e9 100644
@@ -285,6 +285,7 @@ enum ctattr_filter {
 	CTA_FILTER_UNSPEC,
 	CTA_FILTER_ORIG_FLAGS,
 	CTA_FILTER_REPLY_FLAGS,
+	CTA_FILTER_ZONE,
 	__CTA_FILTER_MAX
 };
 #define CTA_FILTER_MAX (__CTA_FILTER_MAX - 1)
net/netfilter/nf_conntrack_netlink.c +11 -0
index e8477f792c95..4b6abe36028e 100644
@@ -911,6 +911,7 @@ struct ctnetlink_filter {
 static const struct nla_policy cta_filter_nla_policy[CTA_FILTER_MAX + 1] = {
 	[CTA_FILTER_ORIG_FLAGS]		= NLA_POLICY_MASK(NLA_U32, CTA_FILTER_F_ALL),
 	[CTA_FILTER_REPLY_FLAGS]	= NLA_POLICY_MASK(NLA_U32, CTA_FILTER_F_ALL),
+	[CTA_FILTER_ZONE]		= { .type = NLA_FLAG },
 };
 
 static int ctnetlink_parse_filter(const struct nlattr *attr,
@@ -930,6 +931,9 @@ static int ctnetlink_parse_filter(const struct nlattr *attr,
 	if (tb[CTA_FILTER_REPLY_FLAGS])
 		filter->reply_flags = nla_get_u32(tb[CTA_FILTER_REPLY_FLAGS]);
 
+	if (tb[CTA_FILTER_ZONE])
+		filter->zone_filter = true;
+
 	return 0;
 }
 
@@ -1006,6 +1010,7 @@ ctnetlink_alloc_filter(const struct nlattr * const cda[], u8 family)
 	if (err)
 		goto err_filter;
 
+	/* CTA_ZONE is allowed without CTA_FILTER_ZONE. */
 	if (cda[CTA_ZONE]) {
 		err = ctnetlink_parse_zone(cda[CTA_ZONE], &filter->zone);
 		if (err < 0)
@@ -1020,6 +1025,12 @@ ctnetlink_alloc_filter(const struct nlattr * const cda[], u8 family)
 	if (err < 0)
 		goto err_filter;
 
+	/* CTA_FILTER_ZONE cannot be set without CTA_ZONE. */
+	if (filter->zone_filter && !cda[CTA_ZONE]) {
+		err = -EINVAL;
+		goto err_filter;
+	}
+
 	if (filter->orig_flags) {
 		if (!cda[CTA_TUPLE_ORIG]) {
 			err = -EINVAL;
tools/testing/selftests/net/netfilter/conntrack_dump_flush.c +99 -46

250 lines not on this page · raw message

Signature · 1 line
2.47.3