]> git.ipfire.org Git - thirdparty/ipset.git/log
thirdparty/ipset.git
9 days agoAdd more explanations to the manpage about the maxelem and hashsize parameters master
Jozsef Kadlecsik [Sun, 22 Jun 2025 10:30:58 +0000 (12:30 +0200)] 
Add more explanations to the manpage about the maxelem and hashsize parameters

Fixes bugzilla #1804.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
9 days agoCorrect manpage about the value of the bucketsize parameter.
Jozsef Kadlecsik [Sat, 21 Jun 2025 15:01:21 +0000 (17:01 +0200)] 
Correct manpage about the value of the bucketsize parameter.

Both the possible values and the default one contained 14
in the manpage while the real value is 12.
Fixes bugzilla #1803.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
9 days agonetfilter: ipset: fix typo in hash size macro
RubenKelevra [Fri, 20 Jun 2025 09:20:53 +0000 (11:20 +0200)] 
netfilter: ipset: fix typo in hash size macro

Rename IPSET_MIMINAL_HASHSIZE → IPSET_MINIMAL_HASHSIZE in
ip_set_hash_gen.h, matching the header typo-fix.

Signed-off-by: RubenKelevra <rubenkelevra@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
3 weeks agoModify pernet_operations check
Jozsef Kadlecsik [Thu, 5 Jun 2025 07:15:47 +0000 (09:15 +0200)] 
Modify pernet_operations check

Check for 'int \*id' in the pernet_operations struct
fails for some later versions of kernels as the declaration
is now 'int * const id'.

Kernel Commit 768e4bb6a75e3c6a034df7c67edac20bd222857e changed
the variable declaration that ipset uses to ensure presence
of the pernet ops id.

Modify the pattern match to include both the newer change while
still supporting the original declaration.

Reported and original patch submitted by Mike Pagano <mpagano@gentoo.org>,
single pattern suggested by Jeremy Sowden <jeremy@azazel.net>

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
6 weeks agoipset 7.24 released v7.24
Jozsef Kadlecsik [Sat, 17 May 2025 13:50:19 +0000 (15:50 +0200)] 
ipset 7.24 released

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
6 weeks agonetfilter: ipset: fix region locking in hash types
Jozsef Kadlecsik [Tue, 6 May 2025 08:26:03 +0000 (10:26 +0200)] 
netfilter: ipset: fix region locking in hash types

Region locking introduced in v5.6-rc4 contained three macros to handle
the region locks: ahash_bucket_start(), ahash_bucket_end() which gave
back the start and end hash bucket values belonging to a given region
lock and ahash_region() which should give back the region lock belonging
to a given hash bucket. The latter was incorrect which can lead to a
race condition between the garbage collector and adding new elements
when a hash type of set is defined with timeouts.

Fixes: f66ee0410b1c ("netfilter: ipset: Fix "INFO: rcu detected stall in hash_xxx" reports")
Reported-by: Kota Toda <kota.toda@gmo-cybersecurity.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
2 months agoImprove fixing commas in sorted json output
Jozsef Kadlecsik [Sat, 19 Apr 2025 13:06:44 +0000 (15:06 +0200)] 
Improve fixing commas in sorted json output

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
2 months agoFix extra quotes around elements in json output
Jozsef Kadlecsik [Fri, 18 Apr 2025 14:54:24 +0000 (16:54 +0200)] 
Fix extra quotes around elements in json output

Fixes bugzilla #1793, issue 3.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
2 months agoFix commas in sorted json output
Jozsef Kadlecsik [Fri, 18 Apr 2025 14:30:47 +0000 (16:30 +0200)] 
Fix commas in sorted json output

Fixes bugzilla #1793, issue 4.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
2 months agoFix unquoted port range in json output
Jozsef Kadlecsik [Fri, 18 Apr 2025 13:40:47 +0000 (15:40 +0200)] 
Fix unquoted port range in json output

Fixes bugzilla #1793, issue 1.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
2 months agoFix extraneous comma in terse list json output
Joachim [Fri, 18 Apr 2025 13:14:27 +0000 (15:14 +0200)] 
Fix extraneous comma in terse list json output

Also fix extra whitespace before closing curly brace.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
2 months agobash-completion: restore fix for syntax error
Jeremy Sowden [Fri, 7 Feb 2025 20:08:13 +0000 (20:08 +0000)] 
bash-completion: restore fix for syntax error

There is a syntax error in a redirection:

  $ bash -x utils/ipset_bash_completion/ipset
  + shopt -s extglob
  utils/ipset_bash_completion/ipset: line 365: syntax error near unexpected token `('
  utils/ipset_bash_completion/ipset: line 365: `done < <(PATH=${PATH}:/sbin ( command ip -o link show ) 2>/dev/null)'

Move the environment variable assignment into the sub-shell.

This fix was previously applied in commit 417ee1054fb2 ("bash-completion:
fix syntax error"), but then reverted, presumably by mistake, in commit
0378d91222c1 ("Bash completion utility updated").

Fixes: 0378d91222c1 ("Bash completion utility updated")
Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
2 months agoCorrect typo in man-page
Jeremy Sowden [Fri, 7 Feb 2025 20:08:12 +0000 (20:08 +0000)] 
Correct typo in man-page

"This values is ..." should be "This value is ...".

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
6 months agoHandle "netfilter: ipset: Fix for recursive locking warning" patch for backward compa...
Jozsef Kadlecsik [Thu, 19 Dec 2024 09:54:23 +0000 (10:54 +0100)] 
Handle "netfilter: ipset: Fix for recursive locking warning" patch for backward compatibility

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
6 months agonetfilter: ipset: Fix for recursive locking warning
Phil Sutter [Tue, 17 Dec 2024 19:56:55 +0000 (20:56 +0100)] 
netfilter: ipset: Fix for recursive locking warning

With CONFIG_PROVE_LOCKING, when creating a set of type bitmap:ip, adding
it to a set of type list:set and populating it from iptables SET target
triggers a kernel warning:

| WARNING: possible recursive locking detected
6.12.0-rc7-01692-g5e9a28f41134-dirty #594 Not tainted
| --------------------------------------------
| ping/4018 is trying to acquire lock:
ffff8881094a6848 (&set->lock){+.-.}-{2:2}, at: ip_set_add+0x28c/0x360 [ip_set]
|
| but task is already holding lock:
ffff88811034c048 (&set->lock){+.-.}-{2:2}, at: ip_set_add+0x28c/0x360 [ip_set]

This is a false alarm: ipset does not allow nested list:set type, so the
loop in list_set_kadd() can never encounter the outer set itself. No
other set type supports embedded sets, so this is the only case to
consider.

To avoid the false report, create a distinct lock class for list:set
type ipset locks.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
6 months agoipset 7.23 released v7.23
Jozsef Kadlecsik [Mon, 16 Dec 2024 18:12:56 +0000 (19:12 +0100)] 
ipset 7.23 released

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
6 months agonetfilter: ipset: Hold module reference while requesting a module
Phil Sutter [Fri, 29 Nov 2024 15:30:38 +0000 (16:30 +0100)] 
netfilter: ipset: Hold module reference while requesting a module

User space may unload ip_set.ko while it is itself requesting a set type
backend module, leading to a kernel crash. The race condition may be
provoked by inserting an mdelay() right after the nfnl_unlock() call.

Fixes: a7b4f989a629 ("netfilter: ipset: IP set core support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Jozsef Kadlecsik <kadlec@netfilter.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
6 months agonetfilter: ipset: add missing range check in bitmap_ip_uadt
Jeongjun Park [Wed, 13 Nov 2024 13:02:09 +0000 (22:02 +0900)] 
netfilter: ipset: add missing range check in bitmap_ip_uadt

When tb[IPSET_ATTR_IP_TO] is not present but tb[IPSET_ATTR_CIDR] exists,
the values of ip and ip_to are slightly swapped. Therefore, the range check
for ip should be done later, but this part is missing and it seems that the
vulnerability occurs.

So we should add missing range checks and remove unnecessary range checks.

Cc: <stable@vger.kernel.org>
Reported-by: syzbot+58c872f7790a4d2ac951@syzkaller.appspotmail.com
Fixes: 72205fc68bd1 ("netfilter: ipset: bitmap:ip set type support")
Signed-off-by: Jeongjun Park <aha310510@gmail.com>
Acked-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
6 months agonetfilter: ipset: Fix suspicious rcu_dereference_protected()
Jozsef Kadlecsik [Mon, 17 Jun 2024 09:18:15 +0000 (11:18 +0200)] 
netfilter: ipset: Fix suspicious rcu_dereference_protected()

When destroying all sets, we are either in pernet exit phase or
are executing a "destroy all sets command" from userspace. The latter
was taken into account in ip_set_dereference() (nfnetlink mutex is held),
but the former was not. The patch adds the required check to
rcu_dereference_protected() in ip_set_dereference().

Fixes: 4e7aaa6b82d6 ("netfilter: ipset: Fix race between namespace cleanup and gc in the list:set type")
Reported-by: syzbot+b62c37cdd58103293a5a@syzkaller.appspotmail.com
Reported-by: syzbot+cfbe1da5fdfc39efc293@syzkaller.appspotmail.com
Reported-by: kernel test robot <oliver.sang@intel.com>
Closes: https://lore.kernel.org/oe-lkp/202406141556.e0b6f17e-lkp@intel.com
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
6 months agotests: runtest.sh: Keep running, print summary of failed tests
Phil Sutter [Thu, 12 Dec 2024 12:47:33 +0000 (13:47 +0100)] 
tests: runtest.sh: Keep running, print summary of failed tests

Do not exit at each failure.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
6 months agotests: cidr.sh: Fix for quirks in RHEL's ipcalc
Phil Sutter [Thu, 12 Dec 2024 12:47:32 +0000 (13:47 +0100)] 
tests: cidr.sh: Fix for quirks in RHEL's ipcalc

RHEL ships a special ipset[1] tool with different output in corner-cases
than the common one[2]:

* Reduced output with /32 netmasks:

| # ipcalc 255.255.255.254/32
| Address: 255.255.255.254
| Address space: Reserved

To cover for this, make net_last_addr() fall back to the 'Address:'
line. Simply adding this keyword is fine as in normal output it appears
first and thus the other recognized keywords' values take precedence.

* No "Address:" line with all-zero addresses:

| # ipcalc 0.0.0.0/1
| Network: 0.0.0.0/1
| Netmask: 128.0.0.0 = 1
| Broadcast: 127.255.255.255
|
| Address space: This host on this network
| HostMin: 0.0.0.1
| HostMax: 127.255.255.254
| Hosts/Net: 2147483646

Have net_first_addr() fall back to the 'HostMin:' line in this case.

[1] https://gitlab.com/ipcalc/ipcalc
[2] http://jodies.de/ipcalc

Fixes: e24e7656b3dd9 ("tests: cidr.sh: Add ipcalc fallback")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
6 months agotests: cidr.sh: Respect IPSET_BIN env var
Phil Sutter [Thu, 12 Dec 2024 12:47:31 +0000 (13:47 +0100)] 
tests: cidr.sh: Respect IPSET_BIN env var

Allow callers to specify the ipset binary to test (with), just like
runtest.sh itself does, too.

Fixes: d05e7e9349bd1 ("Out of bound access in hash:net* types fixed")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
9 months agoipset: Fix implicit declaration of function basename
Mike Pagano [Fri, 30 Aug 2024 15:31:19 +0000 (11:31 -0400)] 
ipset: Fix implicit declaration of function basename

basename(3) is defined in libgen.h in MUSL.
Include libgen.h where basename(3) is used.

Signed-off-by: Mike Pagano <mpagano@gentoo.org>
Acked-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
12 months agotests: Reduce testsuite run-time
Phil Sutter [Thu, 27 Jun 2024 08:18:18 +0000 (10:18 +0200)] 
tests: Reduce testsuite run-time

Where acceptable, batch add set element calls to avoid overhead of
excessive 'ipset' program spawns. On my (slow) testing VM, this patch
reduces a full run of tests/runtest.sh from ~70min down to ~11min.

This might eliminate the situation being tested: resize.sh might be such
a case so batch only 255 'ipset add' calls and continue to repeat these
batched calls 32 times in hopes that it still qualifies as the resizing
stress test tests/hash:ip.t calls it.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
12 months agolib: ipset: Avoid 'argv' array overstepping
Phil Sutter [Thu, 27 Jun 2024 08:18:17 +0000 (10:18 +0200)] 
lib: ipset: Avoid 'argv' array overstepping

The maximum accepted value for 'argc' is MAX_ARGS which matches 'argv'
array size. The maximum allowed array index is therefore argc-1.

This fix will leave items in argv non-NULL-terminated, so explicitly
NULL the formerly last entry after shifting.

Looks like a day-1 bug. Interestingly, this neither triggered ASAN nor
valgrind. Yet adding debug output printing argv entries being copied
did.

Fixes: 1e6e8bd9a62aa ("Third stage to ipset-5")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
12 months agolib: data: Fix for global-buffer-overflow warning by ASAN
Phil Sutter [Thu, 27 Jun 2024 08:18:16 +0000 (10:18 +0200)] 
lib: data: Fix for global-buffer-overflow warning by ASAN

After compiling with CFLAGS="-fsanitize=address -g", running the
testsuite triggers the following warning:

| ipmap: Range: Check syntax error: missing range/from-to: FAILED
| Failed test: ../src/ipset 2>.foo.err -N test ipmap
| =================================================================
| ==4204==ERROR: AddressSanitizer: global-buffer-overflow on address 0x55a21e77172a at pc 0x7f1ef246f2a6 bp 0x7fffed8f4f40 sp 0x7fffed8f46e8
| READ of size 32 at 0x55a21e77172a thread T0
|     #0 0x7f1ef246f2a5 in __interceptor_memcpy /var/tmp/portage/sys-devel/gcc-13.2.1_p20231014/work/gcc-13-20231014/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:899
|     #1 0x55a21e758bf6 in ipset_strlcpy /home/n0-1/git/ipset/lib/data.c:119
|     #2 0x55a21e758bf6 in ipset_data_set /home/n0-1/git/ipset/lib/data.c:349
|     #3 0x55a21e75ee2f in ipset_parse_typename /home/n0-1/git/ipset/lib/parse.c:1819
|     #4 0x55a21e754119 in ipset_parser /home/n0-1/git/ipset/lib/ipset.c:1205
|     #5 0x55a21e752cef in ipset_parse_argv /home/n0-1/git/ipset/lib/ipset.c:1344
|     #6 0x55a21e74ea45 in main /home/n0-1/git/ipset/src/ipset.c:38
|     #7 0x7f1ef224cf09  (/lib64/libc.so.6+0x23f09)
|     #8 0x7f1ef224cfc4 in __libc_start_main (/lib64/libc.so.6+0x23fc4)
|     #9 0x55a21e74f040 in _start (/home/n0-1/git/ipset/src/ipset+0x1d040)
|
| 0x55a21e77172a is located 54 bytes before global variable '*.LC1' defined in 'ipset_bitmap_ip.c' (0x55a21e771760) of size 19
|   '*.LC1' is ascii string 'IP|IP/CIDR|FROM-TO'
| 0x55a21e77172a is located 0 bytes after global variable '*.LC0' defined in 'ipset_bitmap_ip.c' (0x55a21e771720) of size 10
|   '*.LC0' is ascii string 'bitmap:ip'

Fix this by avoiding 'src' array overstep in ipset_strlcpy(): In
contrast to strncpy(), memcpy() does not respect NUL-chars in input but
stubbornly reads as many bytes as specified.

Fixes: a7432ba786ca4 ("Workaround misleading -Wstringop-truncation warning")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
12 months agoReplace BUG_ON() with WARN_ON_ONCE() according to usage policy.
Jozsef Kadlecsik [Thu, 6 Jun 2024 06:57:11 +0000 (08:57 +0200)] 
Replace BUG_ON() with WARN_ON_ONCE() according to usage policy.

12 months agoipset 7.22 released v7.22
Jozsef Kadlecsik [Wed, 5 Jun 2024 06:37:43 +0000 (08:37 +0200)] 
ipset 7.22 released

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
12 months agoipset: fix json output format for IPSET_OPT_IP
Z. Liu [Mon, 20 May 2024 14:23:40 +0000 (22:23 +0800)] 
ipset: fix json output format for IPSET_OPT_IP

IPSET_OPT_IP should be quoted to be a well formed json file, otherwise see
following bad example (range is not quoted):

  # ipset create foo bitmap:ip range 192.168.0.0/16
  # ipset list -o json foo
  [
    {
      "name" : "foo",
      "type" : "bitmap:ip",
      "revision" : 3,
      "header" : {
        "range" : 192.168.0.0-192.168.255.255,
        "memsize" : 8280,
        "references" : 0,
        "numentries" : 0
      },
      "members" : [
      ]
    }
  ]

Signed-off-by: Z. Liu <liuzx@knownsec.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
12 months agotests: add namespace test and take into account delayed set removal at module remove
Jozsef Kadlecsik [Tue, 4 Jun 2024 08:04:33 +0000 (10:04 +0200)] 
tests: add namespace test and take into account delayed set removal at module remove

12 months agonetfilter: ipset: Fix race between namespace cleanup and gc in the list:set type
Jozsef Kadlecsik [Tue, 4 Jun 2024 07:40:37 +0000 (09:40 +0200)] 
netfilter: ipset: Fix race between namespace cleanup and gc in the list:set type

Lion Ackermann reported that there is a race condition between namespace cleanup
in ipset and the garbage collection of the list:set type. The namespace
cleanup can destroy the list:set type of sets while the gc of the set type is
waiting to run in rcu cleanup. The latter uses data from the destroyed set which
thus leads use after free. The patch contains the following parts:

- When destroying all sets, first remove the garbage collectors, then wait
  if needed and then destroy the sets.
- Fix the badly ordered "wait then remove gc" for the destroy a single set
  case.
- Fix the missing rcu locking in the list:set type in the userspace test
  case.
- Use proper RCU list handlings in the list:set type.

The patch depends on 975403cda657 (netfilter: ipset: Add list flush to cancel_gc).

Fixes: fdb8e12cc2cc (netfilter: ipset: fix performance regression in swap operation)
Reported-by: Lion Ackermann <nnamrec@gmail.com>
Tested-by: Lion Ackermann <nnamrec@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
13 months agonetfilter: ipset: Add list flush to cancel_gc
Alexander Maltsev [Wed, 17 Apr 2024 13:51:41 +0000 (18:51 +0500)] 
netfilter: ipset: Add list flush to cancel_gc

Flushing list in cancel_gc drops references to other lists right away,
without waiting for RCU to destroy list. Fixes race when referenced
ipsets can't be destroyed while referring list is scheduled for destroy.

Signed-off-by: Alexander Maltsev <keltar.gw@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
13 months agoKill sched.h dependency on rcupdate.h
Kent Overstreet [Wed, 22 May 2024 18:06:35 +0000 (20:06 +0200)] 
Kill sched.h dependency on rcupdate.h

by moving cond_resched_rcu() to rcupdate_wait.h, we can kill another big
sched.h dependency.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
13 months agoHandle "netfilter: propagate net to nf_bridge_get_physindev" patch
Jozsef Kadlecsik [Wed, 22 May 2024 17:55:29 +0000 (19:55 +0200)] 
Handle "netfilter: propagate net to nf_bridge_get_physindev" patch

Handle backward compatibility with regard of the patch.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
13 months agonetfilter: propagate net to nf_bridge_get_physindev
Pavel Tikhomirov [Wed, 22 May 2024 17:54:22 +0000 (19:54 +0200)] 
netfilter: propagate net to nf_bridge_get_physindev

This is a preparation patch for replacing physindev with physinif on
nf_bridge_info structure. We will use dev_get_by_index_rcu to resolve
device, when needed, and it requires net to be available.

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
13 months agoUpdate autoconfig tools to build cleanly on Debian bookworm
Jozsef Kadlecsik [Tue, 21 May 2024 12:27:13 +0000 (14:27 +0200)] 
Update autoconfig tools to build cleanly on Debian bookworm

13 months agoRevert "netfilter: ipset: remove set destroy at ip_set module removal"
Jozsef Kadlecsik [Tue, 21 May 2024 10:57:28 +0000 (12:57 +0200)] 
Revert "netfilter: ipset: remove set destroy at ip_set module removal"

In case of namespace exit the modules are not unloaded but the sets belonging
to the namespace must be destroyed.

This reverts commit 099916e8f2c0a9c84f79469a8db49f775d4af16e.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
16 months agoipset 7.21 released v7.21
Jozsef Kadlecsik [Mon, 12 Feb 2024 11:57:06 +0000 (12:57 +0100)] 
ipset 7.21 released

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
16 months agonetfilter: ipset: Suppress false sparse warnings
Jozsef Kadlecsik [Mon, 12 Feb 2024 11:51:17 +0000 (12:51 +0100)] 
netfilter: ipset: Suppress false sparse warnings

Due to the code reorganization the functions in question now run by call_rcu(),
not under rcu locking and pointer access. This produces false sparse warning
which are suppressed by the patch.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
16 months agotests: Verify module unload when sets with timeout were just destroyed
Jozsef Kadlecsik [Mon, 5 Feb 2024 11:41:10 +0000 (12:41 +0100)] 
tests: Verify module unload when sets with timeout were just destroyed

16 months agonetfilter: ipset: remove set destroy at ip_set module removal
Jozsef Kadlecsik [Mon, 5 Feb 2024 11:31:16 +0000 (12:31 +0100)] 
netfilter: ipset: remove set destroy at ip_set module removal

The ip_set module can only be removed when all set module type modules
are already removed. A set type module can only be removed when all sets
belonging to the given type are already removed. So it is not possible
that there's any set defined at ip_set module removal.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
16 months agonetfilter: ipset: Cleanup the code of destroy operation and explain the two stages...
Jozsef Kadlecsik [Mon, 5 Feb 2024 10:30:51 +0000 (11:30 +0100)] 
netfilter: ipset: Cleanup the code of destroy operation and explain the two stages in comments

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
16 months agonetfilter: ipset: Missing gc cancellations fixed
Jozsef Kadlecsik [Sun, 4 Feb 2024 15:09:09 +0000 (16:09 +0100)] 
netfilter: ipset: Missing gc cancellations fixed

The patch fdb8e12cc2cc ("netfilter: ipset: fix performance regression
in swap operation") missed to add the calls to gc cancellations
at the error path of create operations and at module unload. Also,
because the half of the destroy operations now executed by a
function registered by call_rcu(), neither NFNL_SUBSYS_IPSET mutex
or rcu read lock is held and therefore the checking of them results
false warnings.

Reported-by: syzbot+52bbc0ad036f6f0d4a25@syzkaller.appspotmail.com
Reported-by: Brad Spengler <spender@grsecurity.net>
Reported-by: Стас Ничипорович <stasn77@gmail.com>
Fixes: fdb8e12cc2cc ("netfilter: ipset: fix performance regression in swap operation")
Tested-by: Brad Spengler <spender@grsecurity.net>
Tested-by: Стас Ничипорович <stasn77@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
16 months agoThe "Fix hex literals in json output" broke save mode, restore it
Jozsef Kadlecsik [Sat, 3 Feb 2024 20:49:48 +0000 (21:49 +0100)] 
The "Fix hex literals in json output" broke save mode, restore it

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
16 months agoFix -Werror=format-extra-args warning
Jozsef Kadlecsik [Sat, 3 Feb 2024 20:48:26 +0000 (21:48 +0100)] 
Fix -Werror=format-extra-args warning

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
16 months agoWorkaround misleading -Wstringop-truncation warning
Jozsef Kadlecsik [Sat, 3 Feb 2024 20:46:05 +0000 (21:46 +0100)] 
Workaround misleading -Wstringop-truncation warning

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
17 months agoipset 7.20 released v7.20
Jozsef Kadlecsik [Wed, 31 Jan 2024 10:32:03 +0000 (11:32 +0100)] 
ipset 7.20 released

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
17 months agoIgnore *.order.cmd and *.symvers.cmd files in kernel builds
Jozsef Kadlecsik [Mon, 29 Jan 2024 12:22:23 +0000 (13:22 +0100)] 
Ignore *.order.cmd and *.symvers.cmd files in kernel builds

17 months agotreewide: Convert del_timer*() to timer_shutdown*()
Steven Rostedt (Google) [Mon, 29 Jan 2024 12:12:31 +0000 (13:12 +0100)] 
treewide: Convert del_timer*() to timer_shutdown*()

Due to several bugs caused by timers being re-armed after they are
shutdown and just before they are freed, a new state of timers was added
called "shutdown".  After a timer is set to this state, then it can no
longer be re-armed.

The following script was run to find all the trivial locations where
del_timer() or del_timer_sync() is called in the same function that the
object holding the timer is freed.  It also ignores any locations where
the timer->function is modified between the del_timer*() and the free(),
as that is not considered a "trivial" case.

This was created by using a coccinelle script and the following
commands:

       $ cat timer.cocci
        @@
        expression ptr, slab;
        identifier timer, rfield;
        @@
        (
        -       del_timer(&ptr->timer);
        +       timer_shutdown(&ptr->timer);
        |
        -       del_timer_sync(&ptr->timer);
        +       timer_shutdown_sync(&ptr->timer);
        )
          ... when strict
              when != ptr->timer
        (
                kfree_rcu(ptr, rfield);
        |
                kmem_cache_free(slab, ptr);
        |
                kfree(ptr);
        )

        $ spatch timer.cocci . > /tmp/t.patch
        $ patch -p1 < /tmp/t.patch

Link: https://lore.kernel.org/lkml/20221123201306.823305113@linutronix.de/
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Acked-by: Pavel Machek <pavel@ucw.cz> [ LED ]
Acked-by: Kalle Valo <kvalo@kernel.org> [ wireless ]
Acked-by: Paolo Abeni <pabeni@redhat.com> [ networking ]
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
17 months agoUse timer_shutdown_sync() when available, instead of del_timer_sync()
Jozsef Kadlecsik [Mon, 29 Jan 2024 12:10:47 +0000 (13:10 +0100)] 
Use timer_shutdown_sync() when available, instead of del_timer_sync()

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
17 months agonetfilter: ipset: fix race condition between swap/destroy and kernel side add/del...
Jozsef Kadlecsik [Mon, 29 Jan 2024 11:30:23 +0000 (12:30 +0100)] 
netfilter: ipset: fix race condition between swap/destroy and kernel side add/del/test v4

The patch "netfilter: ipset: fix race condition between swap/destroy
and kernel side add/del/test", commit 28628fa9 fixes a race condition.
But the synchronize_rcu() added to the swap function unnecessarily slows
it down: it can safely be moved to destroy and use call_rcu() instead.

Eric Dumazet pointed out that simply calling the destroy functions as
rcu callback does not work: sets with timeout use garbage collectors
which need cancelling at destroy which can wait. Therefore the destroy
functions are split into two: cancelling garbage collectors safely at
executing the command received by netlink and moving the remaining
part only into the rcu callback.

Link: https://lore.kernel.org/lkml/C0829B10-EAA6-4809-874E-E1E9C05A8D84@automattic.com/
Fixes: 28628fa952fe ("netfilter: ipset: fix race condition between swap/destroy and kernel side add/del/test")
Reported-by: Ale Crismani <ale.crismani@automattic.com>
Reported-by: David Wang <00107082@163.com>
Tested-by: David Wang <00107082@163.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
18 months agoBash completion utility updated
Jozsef Kadlecsik [Thu, 14 Dec 2023 11:13:25 +0000 (12:13 +0100)] 
Bash completion utility updated

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
18 months agoFix json output for -name option
Mark [Tue, 12 Dec 2023 08:30:40 +0000 (09:30 +0100)] 
Fix json output for -name option

When listing just the set names,json output generated key:value pairs
in an array and not a map, which is invalid in json. Instead of

[
"name" : "test"
"name" : "test2"
]

generate

[
  { "name" : "test" },
  { "name" : "test2" }
]

Fixes bugzilla #1726.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
18 months agoFix hex literals in json output
Jozsef Kadlecsik [Tue, 12 Dec 2023 08:24:43 +0000 (09:24 +0100)] 
Fix hex literals in json output

Json does not allow 0x prefixes in hex numbers, so output hex numbers
as quoted strings instead.

Fixes bugzilla #1726, reported by Mark.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
18 months agonetfilter: ipset: fix race condition between swap/destroy and kernel side add/del...
Jozsef Kadlecsik [Mon, 11 Dec 2023 10:30:30 +0000 (11:30 +0100)] 
netfilter: ipset: fix race condition between swap/destroy and kernel side add/del/test v3

Florian Westphal pointed out that all netfilter hooks run with rcu_read_lock() held
and em_ipset.c wraps the entire ip_set_test() in rcu read lock/unlock pair.
So there's no need to extend the rcu read locked area in ipset itself.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
19 months agonetfilter: ipset: fix race condition between swap/destroy and kernel side add/del...
Jozsef Kadlecsik [Sat, 4 Nov 2023 09:51:47 +0000 (10:51 +0100)] 
netfilter: ipset: fix race condition between swap/destroy and kernel side add/del/test v2

synchronize_rcu() is moved into ip_set_swap() in order not to burden
ip_set_destroy() unnecessarily when all sets are destroyed

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
20 months agonetfilter: ipset: fix race condition between swap/destroy and kernel side add/del...
Jozsef Kadlecsik [Thu, 19 Oct 2023 18:41:53 +0000 (20:41 +0200)] 
netfilter: ipset: fix race condition between swap/destroy and kernel side add/del/test

Linkui Xiao reported that there's a race condition when ipset swap and destroy is
called, which can lead to crash in add/del/test element operations. Swap then
destroy are usual operations to replace a set with another one in a production
system. The issue can in some cases be reproduced with the script:

ipset create hash_ip1 hash:net family inet hashsize 1024 maxelem 1048576
ipset add hash_ip1 172.20.0.0/16
ipset add hash_ip1 192.168.0.0/16
iptables -A INPUT -m set --match-set hash_ip1 src -j ACCEPT
while [ 1 ]
do
# ... Ongoing traffic...
        ipset create hash_ip2 hash:net family inet hashsize 1024 maxelem 1048576
        ipset add hash_ip2 172.20.0.0/16
        ipset swap hash_ip1 hash_ip2
        ipset destroy hash_ip2
        sleep 0.05
done

In the race case the possible order of the operations are

CPU0 CPU1
ip_set_test
ipset swap hash_ip1 hash_ip2
ipset destroy hash_ip2
hash_net_kadt

Swap replaces hash_ip1 with hash_ip2 and then destroy removes hash_ip2 which
is the original hash_ip1. ip_set_test was called on hash_ip1 and because destroy
removed it, hash_net_kadt crashes.

The fix is to protect both the list of the sets and the set pointers in an extended RCU
region and before calling destroy, wait to finish all started rcu_read_lock().

The first version of the patch was written by Linkui Xiao <xiaolinkui@kylinos.cn>.

Closes: https://lore.kernel.org/all/69e7963b-e7f8-3ad0-210-7b86eebf7f78@netfilter.org/
Reported by: Linkui Xiao <xiaolinkui@kylinos.cn>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
20 months agotests: increase timeout to cope with slow virtual test machine
Jozsef Kadlecsik [Wed, 18 Oct 2023 09:04:14 +0000 (11:04 +0200)] 
tests: increase timeout to cope with slow virtual test machine

21 months agoipset 7.19 released v7.19
Jozsef Kadlecsik [Thu, 21 Sep 2023 06:14:18 +0000 (08:14 +0200)] 
ipset 7.19 released

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
21 months agobuild: Fix the double-prefix in pkgconfig
Sam James [Wed, 20 Sep 2023 13:34:17 +0000 (14:34 +0100)] 
build: Fix the double-prefix in pkgconfig

Remove the extraneous pkgconfigdir definition and use the proper
one from pkg.m4 via PKG_INSTALLDIR.

Fixes: 326932be0c4f47756f9809cad5a103ac310f700d
Signed-off-by: Sam James <sam@gentoo.org>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
21 months agoMerge branch 'master' of ssh://git.netfilter.org:60084/ipset
Jozsef Kadlecsik [Tue, 19 Sep 2023 18:15:24 +0000 (20:15 +0200)] 
Merge branch 'master' of ssh://git.netfilter.org:60084/ipset

21 months agoipset 7.18 released v7.18
Jozsef Kadlecsik [Tue, 19 Sep 2023 18:13:41 +0000 (20:13 +0200)] 
ipset 7.18 released

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
21 months agoAdd json output to list command
Thomas Oberhammer [Mon, 18 Sep 2023 21:24:59 +0000 (23:24 +0200)] 
Add json output to list command

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
21 months agonetfilter: ipset: Fix race between IPSET_CMD_CREATE and IPSET_CMD_SWAP
Jozsef Kadlecsik [Mon, 18 Sep 2023 21:10:51 +0000 (23:10 +0200)] 
netfilter: ipset: Fix race between IPSET_CMD_CREATE and IPSET_CMD_SWAP

Kyle Zeng reported that there is a race between IPSET_CMD_ADD and IPSET_CMD_SWAP
in netfilter/ip_set, which can lead to the invocation of `__ip_set_put` on a wrong
`set`, triggering the `BUG_ON(set->ref == 0);` check in it.

The race is caused by using the wrong reference counter, i.e. the ref counter instead
of ref_netlink.

Reported-by: Kyle Zeng <zengyhkyle@gmail.com>
Tested-by: Kyle Zeng <zengyhkyle@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
21 months agonetfilter: ipset: add the missing IP_SET_HASH_WITH_NET0 macro for ip_set_hash_netport...
Kyle Zeng [Tue, 5 Sep 2023 22:04:09 +0000 (15:04 -0700)] 
netfilter: ipset: add the missing IP_SET_HASH_WITH_NET0 macro for ip_set_hash_netportnet.c

The missing IP_SET_HASH_WITH_NET0 macro in ip_set_hash_netportnet can
lead to the use of wrong `CIDR_POS(c)` for calculating array offsets,
which can lead to integer underflow. As a result, it leads to slab
out-of-bound access.
This patch adds back the IP_SET_HASH_WITH_NET0 macro to
ip_set_hash_netportnet to address the issue.

Fixes: 886503f34d63 ("netfilter: ipset: actually allow allowable CIDR 0 in hash:net,port,net")
Suggested-by: Jozsef Kadlecsik <kadlec@netfilter.org>
Signed-off-by: Kyle Zeng <zengyhkyle@gmail.com>
Acked-by: Jozsef Kadlecsik <kadlec@netfilter.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
21 months agocompatibility: handle strscpy_pad()
Jozsef Kadlecsik [Mon, 18 Sep 2023 21:06:59 +0000 (23:06 +0200)] 
compatibility: handle strscpy_pad()

21 months agonetfilter: ipset: refactor deprecated strncpy
Justin Stitt [Mon, 18 Sep 2023 20:37:09 +0000 (22:37 +0200)] 
netfilter: ipset: refactor deprecated strncpy

Use `strscpy_pad` instead of `strncpy`.

Link: https://github.com/KSPP/linux/issues/90
Cc: linux-hardening@vger.kernel.org
Signed-off-by: Justin Stitt <justinstitt@google.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
21 months agonetfilter: ipset: remove rcu_read_lock_bh pair from ip_set_test
Florian Westphal [Tue, 6 Jun 2023 11:58:27 +0000 (13:58 +0200)] 
netfilter: ipset: remove rcu_read_lock_bh pair from ip_set_test

Callers already hold rcu_read_lock.

Prior to RCU conversion this used to be a read_lock_bh(), but now the
bh-disable isn't needed anymore.

Cc: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
21 months agonetfilter: ipset: Replace strlcpy with strscpy
Azeem Shaikh [Tue, 13 Jun 2023 00:34:37 +0000 (00:34 +0000)] 
netfilter: ipset: Replace strlcpy with strscpy

strlcpy() reads the entire source buffer first.
This read may exceed the destination size limit.
This is both inefficient and can lead to linear read
overflows if a source string is not NUL-terminated [1].
In an effort to remove strlcpy() completely [2], replace
strlcpy() here with strscpy().

Direct replacement is safe here since return value from all
callers of STRLCPY macro were ignored.

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89

Signed-off-by: Azeem Shaikh <azeemshaikh38@gmail.com>
Acked-by: Jozsef Kadlecsik <kadlec@netfilter.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20230613003437.3538694-1-azeemshaikh38@gmail.com
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
21 months agonetfilter: ipset: Add schedule point in call_ad().
Kuniyuki Iwashima [Thu, 18 May 2023 17:33:00 +0000 (10:33 -0700)] 
netfilter: ipset: Add schedule point in call_ad().

syzkaller found a repro that causes Hung Task [0] with ipset.  The repro
first creates an ipset and then tries to delete a large number of IPs
from the ipset concurrently:

  IPSET_ATTR_IPADDR_IPV4 : 172.20.20.187
  IPSET_ATTR_CIDR        : 2

The first deleting thread hogs a CPU with nfnl_lock(NFNL_SUBSYS_IPSET)
held, and other threads wait for it to be released.

Previously, the same issue existed in set->variant->uadt() that could run
so long under ip_set_lock(set).  Commit 5e29dc36bd5e ("netfilter: ipset:
Rework long task execution when adding/deleting entries") tried to fix it,
but the issue still exists in the caller with another mutex.

While adding/deleting many IPs, we should release the CPU periodically to
prevent someone from abusing ipset to hang the system.

Note we need to increment the ipset's refcnt to prevent the ipset from
being destroyed while rescheduling.

[0]:
INFO: task syz-executor174:268 blocked for more than 143 seconds.
      Not tainted 6.4.0-rc1-00145-gba79e9a73284 #1
"echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
task:syz-executor174 state:D stack:0     pid:268   ppid:260    flags:0x0000000d
Call trace:
 __switch_to+0x308/0x714 arch/arm64/kernel/process.c:556
 context_switch kernel/sched/core.c:5343 [inline]
 __schedule+0xd84/0x1648 kernel/sched/core.c:6669
 schedule+0xf0/0x214 kernel/sched/core.c:6745
 schedule_preempt_disabled+0x58/0xf0 kernel/sched/core.c:6804
 __mutex_lock_common kernel/locking/mutex.c:679 [inline]
 __mutex_lock+0x6fc/0xdb0 kernel/locking/mutex.c:747
 __mutex_lock_slowpath+0x14/0x20 kernel/locking/mutex.c:1035
 mutex_lock+0x98/0xf0 kernel/locking/mutex.c:286
 nfnl_lock net/netfilter/nfnetlink.c:98 [inline]
 nfnetlink_rcv_msg+0x480/0x70c net/netfilter/nfnetlink.c:295
 netlink_rcv_skb+0x1c0/0x350 net/netlink/af_netlink.c:2546
 nfnetlink_rcv+0x18c/0x199c net/netfilter/nfnetlink.c:658
 netlink_unicast_kernel net/netlink/af_netlink.c:1339 [inline]
 netlink_unicast+0x664/0x8cc net/netlink/af_netlink.c:1365
 netlink_sendmsg+0x6d0/0xa4c net/netlink/af_netlink.c:1913
 sock_sendmsg_nosec net/socket.c:724 [inline]
 sock_sendmsg net/socket.c:747 [inline]
 ____sys_sendmsg+0x4b8/0x810 net/socket.c:2503
 ___sys_sendmsg net/socket.c:2557 [inline]
 __sys_sendmsg+0x1f8/0x2a4 net/socket.c:2586
 __do_sys_sendmsg net/socket.c:2595 [inline]
 __se_sys_sendmsg net/socket.c:2593 [inline]
 __arm64_sys_sendmsg+0x80/0x94 net/socket.c:2593
 __invoke_syscall arch/arm64/kernel/syscall.c:38 [inline]
 invoke_syscall+0x84/0x270 arch/arm64/kernel/syscall.c:52
 el0_svc_common+0x134/0x24c arch/arm64/kernel/syscall.c:142
 do_el0_svc+0x64/0x198 arch/arm64/kernel/syscall.c:193
 el0_svc+0x2c/0x7c arch/arm64/kernel/entry-common.c:637
 el0t_64_sync_handler+0x84/0xf0 arch/arm64/kernel/entry-common.c:655
 el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:591

Reported-by: syzkaller <syzkaller@googlegroups.com>
Fixes: a7b4f989a629 ("netfilter: ipset: IP set core support")
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Acked-by: Jozsef Kadlecsik <kadlec@netfilter.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
21 months agonet: Kconfig: fix spellos
Randy Dunlap [Mon, 18 Sep 2023 20:13:03 +0000 (22:13 +0200)] 
net: Kconfig: fix spellos

Fix spelling in net/ Kconfig files.
(reported by codespell)

Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
Cc: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: Jozsef Kadlecsik <kadlec@netfilter.org>
Cc: Florian Westphal <fw@strlen.de>
Cc: coreteam@netfilter.org
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: Cong Wang <xiyou.wangcong@gmail.com>
Cc: Jiri Pirko <jiri@resnulli.us>
Link: https://lore.kernel.org/r/20230124181724.18166-1-rdunlap@infradead.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
22 months agobash-completion: fix syntax error
Jeremy Sowden [Fri, 21 Jul 2023 22:13:11 +0000 (23:13 +0100)] 
bash-completion: fix syntax error

There is a syntax error in a redirection:

  $ bash -x utils/ipset_bash_completion/ipset
  + shopt -s extglob
  utils/ipset_bash_completion/ipset: line 365: syntax error near unexpected token `('
  utils/ipset_bash_completion/ipset: line 365: `done < <(PATH=${PATH}:/sbin ( command ip -o link show ) )'

Move the environment variable assignment into the sub-shell.

Fixes: da6242e17583 ("Updated utilities")
Link: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1041605
Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2 years agotests: hash:ip,port.t: Replace VRRP by GRE protocol
Phil Sutter [Fri, 10 Mar 2023 17:46:20 +0000 (18:46 +0100)] 
tests: hash:ip,port.t: Replace VRRP by GRE protocol

Some systems may not have "vrrp" as alias to "carp" yet, so use a
protocol which is less likely to cause problems for testing purposes.

Fixes: a67aa712ed912 ("tests: hash:ip,port.t: 'vrrp' is printed as 'carp'")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: hash:ip,port.t: 'vrrp' is printed as 'carp'
Phil Sutter [Tue, 7 Mar 2023 13:43:39 +0000 (14:43 +0100)] 
tests: hash:ip,port.t: 'vrrp' is printed as 'carp'

| % grep vrrp /etc/protocols
| carp 112 CARP vrrp # Common Address Redundancy Protocol

Nowadays, carp seems to be the preferred name for protocol 112. Simply
change the expected output for lack of idea for a backwards compatible
change which is not simply using another protocol.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: cidr.sh: Add ipcalc fallback
Phil Sutter [Sun, 5 Mar 2023 14:36:05 +0000 (15:36 +0100)] 
tests: cidr.sh: Add ipcalc fallback

If netmask is not available, ipcalc may be a viable replacement.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: xlate: Make test input valid
Phil Sutter [Sun, 5 Mar 2023 11:46:49 +0000 (12:46 +0100)] 
tests: xlate: Make test input valid

Make sure ipset at least accepts the test input by running it against
plain ipset once for sanity. This exposed two issues:

* Set 'hip5' doesn't have comment support, so add the commented elements
  to 'hip6' instead (likely a typo).
* Set 'bip1' range 2.0.0.1-2.1.0.1 exceeds the max allowed for bitmap
  sets. Reduce it accordingly.

Fixes: 7587d1c4b5465 ("tests: add tests ipset to nftables")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: xlate: Test built binary by default
Phil Sutter [Sun, 5 Mar 2023 11:43:23 +0000 (12:43 +0100)] 
tests: xlate: Test built binary by default

Testing the host's iptables-translate by default is unintuitive. Since
the ipset-translate symlink is created upon 'make install', add a local
symlink to the repository pointing at a built binary in src/. Using this
by default is consistent with the regular testsuite.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoxlate: Drop dead code
Phil Sutter [Wed, 22 Feb 2023 16:53:45 +0000 (17:53 +0100)] 
xlate: Drop dead code

Set type is not needed when manipulating elements, the assigned
variable was unused in that case.

Fixes: 325af556cd3a6 ("add ipset to nftables translation infrastructure")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoxlate: Fix for fd leak in error path
Phil Sutter [Wed, 22 Feb 2023 16:30:20 +0000 (17:30 +0100)] 
xlate: Fix for fd leak in error path

A rather cosmetic issue though, the program will terminate anyway.

Fixes: 325af556cd3a6 ("add ipset to nftables translation infrastructure")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoconfigure.ac: fix bashisms
Sam James [Sat, 28 Jan 2023 18:25:33 +0000 (19:25 +0100)] 
configure.ac: fix bashisms

configure scripts need to be runnable with a POSIX-compliant /bin/sh.

On many (but not all!) systems, /bin/sh is provided by Bash, so errors
like this aren't spotted. Notably Debian defaults to /bin/sh provided
by dash which doesn't tolerate such bashisms as '=='.

This retains compatibility with bash.

Signed-off-by: Sam James <sam@gentoo.org>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
2 years agolib/Makefile.am: fix pkgconfig dir
Sam James [Sat, 28 Jan 2023 18:23:54 +0000 (19:23 +0100)] 
lib/Makefile.am: fix pkgconfig dir

Signed-off-by: Sam James <sam@gentoo.org>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
2 years agonetfilter: ipset: Fix overflow before widen in the bitmap_ip_create() function.
Gavrilov Ilia [Sat, 28 Jan 2023 18:09:52 +0000 (19:09 +0100)] 
netfilter: ipset: Fix overflow before widen in the bitmap_ip_create() function.

When first_ip is 0, last_ip is 0xFFFFFFFF, and netmask is 31, the value of
an arithmetic expression 2 << (netmask - mask_bits - 1) is subject
to overflow due to a failure casting operands to a larger data type
before performing the arithmetic.

Note that it's harmless since the value will be checked at the next step.

Found by InfoTeCS on behalf of Linux Verification Center
(linuxtesting.org) with SVACE.

Fixes: b9fed748185a ("netfilter: ipset: Check and reject crazy /0 input parameters")
Signed-off-by: Ilia.Gavrilov <Ilia.Gavrilov@infotecs.ru>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
2 years agoipset 7.17 released v7.17
Jozsef Kadlecsik [Fri, 30 Dec 2022 11:57:30 +0000 (12:57 +0100)] 
ipset 7.17 released

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
2 years agoTests: When verifying comments/timeouts, make sure entries don't expire
Jozsef Kadlecsik [Fri, 30 Dec 2022 11:50:36 +0000 (12:50 +0100)] 
Tests: When verifying comments/timeouts, make sure entries don't expire

2 years agoTests: Make sure the internal batches add the correct number of elements
Jozsef Kadlecsik [Fri, 30 Dec 2022 11:49:46 +0000 (12:49 +0100)] 
Tests: Make sure the internal batches add the correct number of elements

2 years agoTests: Verify that hash:net,port,net type can handle 0/0 properly
Jozsef Kadlecsik [Fri, 30 Dec 2022 11:48:54 +0000 (12:48 +0100)] 
Tests: Verify that hash:net,port,net type can handle 0/0 properly

2 years agonetfilter: ipset: Rework long task execution when adding/deleting entries
Jozsef Kadlecsik [Fri, 30 Dec 2022 11:32:37 +0000 (12:32 +0100)] 
netfilter: ipset: Rework long task execution when adding/deleting entries

When adding/deleting large number of elements in one step in ipset, it can
take a reasonable amount of time and can result in soft lockup errors. The
patch 5f7b51bf09ba ("netfilter: ipset: Limit the maximal range of
consecutive elements to add/delete") tried to fix it by limiting the max
elements to process at all. However it was not enough, it is still possible
that we get hung tasks. Lowering the limit is not reasonable, so the
approach in this patch is as follows: rely on the method used at resizing
sets and save the state when we reach a smaller internal batch limit,
unlock/lock and proceed from the saved state. Thus we can avoid long
continuous tasks and at the same time removed the limit to add/delete large
number of elements in one step.

The nfnl mutex is held during the whole operation which prevents one to issue
other ipset commands in parallel.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
Reported-by: syzbot+9204e7399656300bf271@syzkaller.appspotmail.com
Fixes: 5f7b51bf09ba ("netfilter: ipset: Limit the maximal range of consecutive elements to add/delete")
2 years agonetfilter: ipset: fix hash:net,port,net hang with /0 subnet
Jozsef Kadlecsik [Thu, 29 Dec 2022 14:00:21 +0000 (15:00 +0100)] 
netfilter: ipset: fix hash:net,port,net hang with /0 subnet

The hash:net,port,net set type supports /0 subnets. However, the patch
commit 5f7b51bf09baca8e titled "netfilter: ipset: Limit the maximal range
of consecutive elements to add/delete" did not take into account it and
resulted in an endless loop. The bug is actually older but the patch
5f7b51bf09baca8e brings it out earlier.

Handle /0 subnets properly in hash:net,port,net set types.

Reported-by: Марк Коренберг <socketpair@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
2 years agoMakefile: Create LZMA-compressed dist-files
Phil Sutter [Thu, 8 Dec 2022 00:16:05 +0000 (01:16 +0100)] 
Makefile: Create LZMA-compressed dist-files

Use a more modern alternative to gzip.

Suggested-by: Jan Engelhardt <jengelh@inai.de>
Suggested-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
2 years agoipset 7.16 released v7.16
Jozsef Kadlecsik [Mon, 21 Nov 2022 12:39:47 +0000 (13:39 +0100)] 
ipset 7.16 released

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
2 years agoAdd new ipset_parse_bitmask() function to the library interface.
Jozsef Kadlecsik [Mon, 21 Nov 2022 12:37:38 +0000 (13:37 +0100)] 
Add new ipset_parse_bitmask() function to the library interface.

2 years agotest: Make sure no more than 64 clashing elements can be added to hash:net,iface...
Jozsef Kadlecsik [Mon, 21 Nov 2022 12:20:05 +0000 (13:20 +0100)] 
test: Make sure no more than 64 clashing elements can be added to hash:net,iface sets

2 years agonetfilter: ipset: restore allowing 64 clashing elements in hash:net,iface
Jozsef Kadlecsik [Mon, 21 Nov 2022 12:16:56 +0000 (13:16 +0100)] 
netfilter: ipset: restore allowing 64 clashing elements in hash:net,iface

The patch "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.

2 years agoFix all debug mode warnings
Jozsef Kadlecsik [Sun, 20 Nov 2022 21:43:59 +0000 (22:43 +0100)] 
Fix all debug mode warnings

2 years agonetfilter: ipset: add tests for the new bitmask feature
Vishwanath Pai [Thu, 10 Nov 2022 21:31:31 +0000 (16:31 -0500)] 
netfilter: ipset: add tests for the new bitmask feature

The hash:ip type had a test for netmask, add a similar test for bitmask
feature as well, and add another test where bitmask is not a valid
netmask.

Repeat the same three tests for hash:ip,port and hash:net,net.

Add a test to make sure bitmask and netmask options cannot be added at the
same time.

Signed-off-by: Vishwanath Pai <vpai@akamai.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
2 years agonetfilter: ipset: Update the man page to include netmask/bitmask options
Vishwanath Pai [Thu, 10 Nov 2022 21:31:30 +0000 (16:31 -0500)] 
netfilter: ipset: Update the man page to include netmask/bitmask options

We added bitmask support to hash:ip and added both netmask and bitmask
to hash:net,net and hash:ip,port

Signed-off-by: Vishwanath Pai <vpai@akamai.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
2 years agonetfilter: ipset: Add bitmask support to hash:netnet
Vishwanath Pai [Thu, 10 Nov 2022 21:31:29 +0000 (16:31 -0500)] 
netfilter: ipset: Add bitmask support to hash:netnet

Create a new revision of hash:netnet and add support for bitmask
parameter. The set did not support netmask so we'll add both netmask and
bitmask.

Signed-off-by: Vishwanath Pai <vpai@akamai.com>
Signed-off-by: Joshua Hunt <johunt@akamai.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
2 years agonetfilter: ipset: Add bitmask support to hash:ipport
Vishwanath Pai [Thu, 10 Nov 2022 21:31:28 +0000 (16:31 -0500)] 
netfilter: ipset: Add bitmask support to hash:ipport

Create a new revision of hash:ipport and add support for bitmask
parameter. The set did not support netmask so we'll add both netmask and
bitmask.

Signed-off-by: Vishwanath Pai <vpai@akamai.com>
Signed-off-by: Joshua Hunt <johunt@akamai.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
2 years agonetfilter: ipset: Add bitmask support to hash:ip
Vishwanath Pai [Thu, 10 Nov 2022 21:31:27 +0000 (16:31 -0500)] 
netfilter: ipset: Add bitmask support to hash:ip

Create a new revision of hash:ip and add support for bitmask parameter.
The set already had support for netmask so only add bitmask here.

Signed-off-by: Vishwanath Pai <vpai@akamai.com>
Signed-off-by: Joshua Hunt <johunt@akamai.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
2 years agonetfilter: ipset: Add support for new bitmask parameter
Vishwanath Pai [Thu, 10 Nov 2022 21:31:26 +0000 (16:31 -0500)] 
netfilter: ipset: Add support for new bitmask parameter

Add a new parameter to complement the existing 'netmask' option. The
main difference between netmask and bitmask is that bitmask takes any
arbitrary ip address as input, it does not have to be a valid netmask.

The name of the new parameter is 'bitmask'. This lets us mask out
arbitrary bits in the ip address, for example:
ipset create set1 hash:ip bitmask 255.128.255.0
ipset create set2 hash:ip,port family inet6 bitmask ffff::ff80

Signed-off-by: Vishwanath Pai <vpai@akamai.com>
Signed-off-by: Joshua Hunt <johunt@akamai.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>