Netfilter fixes for net
Subsystems (3)
Pablo Neira Ayuso
maintainercover Netfilter fixes for net
Hi,
The following patch contains another round of Netfilter fixes for net:
1) Fix regression in ipset hash:ip with IPv4 range, from Vishwanath Pai. This is fixing up a bug introduced in the 6.0 release.
2) The "netfilter: ipset: enforce documented limit to prevent allocating huge memory" patch contained a wrong condition which makes impossible to add up to 64 clashing elements to a hash:net,iface type of set while it is the documented feature of the set type. The patch fixes the condition and thus makes possible to add the elements while keeps preventing allocating huge memory, from Jozsef Kadlecsik. This has been broken for several releases.
3) Missing locking when updating the flow block list which might lead a reader to crash. This has been broken since the introduction of the flowtable hardware offload support.
Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git
Thanks.
----------------------------------------------------------------
The following changes since commit badbda1a01860c80c6ab60f329ef46c713653a27:
octeontx2-af: cn10k: mcs: Fix copy and paste bug in mcs_bbe_intr_handler() (2022-11-21 13:04:28 +0000)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git HEAD
for you to fetch changes up to bcd9e3c1656d0f7dd9743598c65c3ae24efb38d0:
netfilter: flowtable_offload: add missing locking (2022-11-22 22:17:12 +0100)
----------------------------------------------------------------
Felix Fietkau (1):
netfilter: flowtable_offload: add missing locking
Jozsef Kadlecsik (1):
netfilter: ipset: restore allowing 64 clashing elements in hash:net,iface
Vishwanath Pai (1):
netfilter: ipset: regression in ip_set_hash_ip.c
net/netfilter/ipset/ip_set_hash_gen.h | 2 +- net/netfilter/ipset/ip_set_hash_ip.c | 8 +++----- net/netfilter/nf_flow_table_offload.c | 4 ++++ 3 files changed, 8 insertions(+), 6 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 1/3 netfilter: ipset: regression in ip_set_hash_ip.c
From: Vishwanath Pai <[email protected]>
This patch introduced a regression: commit 48596a8ddc46 ("netfilter:
ipset: Fix adding an IPv4 range containing more than 2^31 addresses")
The variable e.ip is passed to adtfn() function which finally adds the ip address to the set. The patch above refactored the for loop and moved e.ip = htonl(ip) to the end of the for loop.
What this means is that if the value of "ip" changes between the first assignement of e.ip and the forloop, then e.ip is pointing to a different ip address than "ip".
Test case:
$ ipset create jdtest_tmp hash:ip family inet hashsize 2048 maxelem 100000 $ ipset add jdtest_tmp 10.0.1.1/31 ipset v6.21.1: Element cannot be added to the set: it's already added
The value of ip gets updated inside the "else if (tb[IPSET_ATTR_CIDR])" block but e.ip is still pointing to the old value.
--- net/netfilter/ipset/ip_set_hash_ip.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
net/netfilter/ipset/ip_set_hash_ip.c +3 -5
@@ -151,18 +151,16 @@ hash_ip4_uadt(struct ip_set *set, struct nlattr *tb[],if (((u64 )ip_to - ip +1 ) >> (32 - h->netmask) >IPSET_MAX_RANGE )return -ERANGE ; -if (retried) { +if (retried) ip =ntohl (h->next.ip); - e.ip =htonl (ip); - }for (; ip <= ip_to;) { + e.ip =htonl (ip); ret =adtfn (set, &e, &ext, &ext, flags);if (ret && !ip_set_eexist (ret, flags))return ret; ip += hosts; - e.ip =htonl (ip); -if (e.ip ==0 ) +if (ip ==0 )return 0 ; ret =0 ;
Signature · 1 line
2.30.2
Re: [PATCH net 1/3] netfilter: ipset: regression in ip_set_hash_ip.c
This series was applied to netdev/net.git (master) by Pablo Neira Ayuso <[email protected]>:
Hello:
This series was applied to netdev/net.git (master) by Pablo Neira Ayuso <[email protected]>:
Quoted 10 lines · On Tue, 22 Nov 2022 22:28:12 +0100 you wrote:
From: Vishwanath Pai <[email protected]>
This patch introduced a regression: commit
48596a8ddc46("netfilter:
ipset: Fix adding an IPv4 range containing more than 2^31 addresses")The variable e.ip is passed to
adtfn()function which finally adds the ip address to the set. The patch above refactored the for loop and moved e.ip = htonl(ip) to the end of the for loop.[...]
Here is the summary with links:
- [net,1/3] netfilter: ipset: regression in ip_set_hash_ip.c
https://git.kernel.org/netdev/net/c/c7aa1a76d4a0 - [net,2/3] netfilter: ipset: restore allowing 64 clashing elements in hash:net,iface https://git.kernel.org/netdev/net/c/6a66ce44a51b - [net,3/3] netfilter: flowtable_offload: add missing locking https://git.kernel.org/netdev/net/c/bcd9e3c1656d
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Pablo Neira Ayuso
maintainerPATCH 2/3 netfilter: ipset: restore allowing 64 clashing elements in hash:net,iface
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
The commit 510841da1fcc ("netfilter: ipset: enforce documented limit to prevent allocating huge memory") was too strict and prevented to add up to 64 clashing elements to a hash:net,iface type of set. This patch fixes the issue and now the type behaves as documented.
--- net/netfilter/ipset/ip_set_hash_gen.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/ipset/ip_set_hash_gen.h +1 -1
@@ -916,7 +916,7 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,#ifdef IP_SET_HASH_WITH_MULTI if (h->bucketsize >=AHASH_MAX_TUNED ) goto set_full; -else if (h->bucketsize < multi) +else if (h->bucketsize <= multi) h->bucketsize +=AHASH_INIT_SIZE ;#endif if (n->size >=AHASH_MAX (h)) {
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 3/3 netfilter: flowtable_offload: add missing locking
In reply to Pablo Neira AyusoFrom: Felix Fietkau <[email protected]>
nf_flow_table_block_setup and the driver TC_SETUP_FT call can modify the flow block cb list while they are being traversed elsewhere, causing a crash. Add a write lock around the calls to protect readers
--- net/netfilter/nf_flow_table_offload.c | 4 ++++ 1 file changed, 4 insertions(+)
net/netfilter/nf_flow_table_offload.c +4 -0
@@ -1098,6 +1098,7 @@ static int nf_flow_table_block_setup(struct nf_flowtable *flowtable,struct flow_block_cb *block_cb, *next;int err =0 ; +down_write (&flowtable->flow_block_lock);switch (cmd) {case FLOW_BLOCK_BIND :list_splice (&bo->cb_list, &flowtable->flow_block.cb_list);
@@ -1112,6 +1113,7 @@ static int nf_flow_table_block_setup(struct nf_flowtable *flowtable,WARN_ON_ONCE (1 ); err = -EOPNOTSUPP ; } +up_write (&flowtable->flow_block_lock);return err; }
@@ -1168,7 +1170,9 @@ static int nf_flow_table_offload_cmd(struct flow_block_offload *bo,nf_flow_table_block_offload_init (bo,dev_net (dev), cmd, flowtable, extack); +down_write (&flowtable->flow_block_lock); err = dev->netdev_ops->ndo_setup_tc (dev,TC_SETUP_FT , bo); +up_write (&flowtable->flow_block_lock);if (err <0 )return err;
Signature · 1 line
2.30.2