Bug 199107

Summary: Massive use of "ipset" utility: NULL pointer dereference in kernel (ip_set_hash_netiface, hash_netiface4_resize)
Product: Networking Reporter: Dmitry Yu Okunev (dyokunev)
Component: Netfilter/IptablesAssignee: networking_netfilter-iptables (networking_netfilter-iptables)
Status: NEW ---    
Severity: normal CC: dxu, dyokunev
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 4.14.13 Subsystem:
Regression: No Bisected commit-id:
Attachments: Logs of dmesg and "strace -f ipset list"

Description Dmitry Yu Okunev 2018-03-14 05:51:21 UTC
Created attachment 274713 [details]
Logs of dmesg and "strace -f ipset list"

If I massively work with "ipset" utility then I get a NULL pointer dereference and netfilter hangs after that. The logs are attached.
Comment 1 Dmitry Yu Okunev 2018-03-14 08:42:10 UTC
The command causes the bug (I mean the last command before the bug) in my case is:

/sbin/ipset add ACL.IN.ALL_PERMIT 0.0.0.0/0,kaf_54 timeout 0 -exist
Comment 2 Dmitry Yu Okunev 2018-03-14 08:53:46 UTC
To repeat the bug on my machine it's enough just to copy this into the root terminal:

ipset create ACL.IN.ALL_PERMIT hash:net,iface hashsize 1048576 timeout 0
for i in $(seq 0 100); do
    /sbin/ipset add ACL.IN.ALL_PERMIT 0.0.0.0/0,kaf_$i timeout 0 -exist
done
Comment 3 Dmitry Yu Okunev 2018-03-14 09:17:16 UTC
It seems problems appears when I add the 65th such row into a set.
Comment 4 Dmitry Yu Okunev 2018-03-14 12:50:35 UTC
I've tuned some constants in the code and it helped:

linux-4.14.26/net/netfilter/ipset/ip_set_core.c:
#define IP_SET_INC        2048

linux-4.14.26/net/netfilter/ipset/ip_set_hash_gen.h:
#define AHASH_MAX_TUNED                       2048
Comment 5 Dmitry Yu Okunev 2018-03-14 12:54:25 UTC
However it works quite strange. It claims that there're 101 entry, however doesn't display any member:

# ipset list ACL.IN.ALL_PERMIT
Name: ACL.IN.ALL_PERMIT
Type: hash:net,iface
Revision: 6
Header: family inet hashsize 2097152 maxelem 65536 timeout 0
Size in memory: 10984
References: 0
Number of entries: 101
Members:
#
Comment 6 Daniel Xu 2022-08-25 18:09:08 UTC
Hit same issue as well. Testing / analysis points to https://github.com/torvalds/linux/commit/2b33d6ffa9e38f344418976b06 as the fix.