]> git.ipfire.org Git - thirdparty/ipset.git/log
thirdparty/ipset.git
21 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

22 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>
22 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>
22 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

22 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>
22 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>
22 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>
22 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>
22 months agocompatibility: handle strscpy_pad()
Jozsef Kadlecsik [Mon, 18 Sep 2023 21:06:59 +0000 (23:06 +0200)] 
compatibility: handle strscpy_pad()

22 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>
22 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>
22 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>
22 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>
22 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>
23 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>
2 years agonetfilter: ipset: Add support for new bitmask parameter
Vishwanath Pai [Thu, 10 Nov 2022 21:30:26 +0000 (16:30 -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>
2 years agonetfilter: ipset: regression in ip_set_hash_ip.c
Vishwanath Pai [Wed, 28 Sep 2022 18:26:50 +0000 (14:26 -0400)] 
netfilter: ipset: regression in ip_set_hash_ip.c

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.

Reviewed-by: Joshua Hunt <johunt@akamai.com>
Signed-off-by: Vishwanath Pai <vpai@akamai.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
2 years agonetfilter: move from strlcpy with unused retval to strscpy
Wolfram Sang [Mon, 7 Nov 2022 21:09:04 +0000 (22:09 +0100)] 
netfilter: move from strlcpy with unused retval to strscpy

Follow the advice of the below link and prefer 'strscpy' in this
subsystem. Conversion is 1:1 because the return value is not used.
Generated by a coccinelle script.

Link: https://lore.kernel.org/r/CAHk-=wgfRnXz0W3D37d01q3JFkr_i_uTL=V6A6G1oUZcprmknw@mail.gmail.com/
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Simon Horman <horms@verge.net.au>
Signed-off-by: Florian Westphal <fw@strlen.de>
2 years agocompatibility: handle unsafe_memcpy()
Jozsef Kadlecsik [Mon, 7 Nov 2022 21:03:36 +0000 (22:03 +0100)] 
compatibility: handle unsafe_memcpy()

2 years agonetlink: Bounds-check struct nlmsgerr creation
Kees Cook [Mon, 7 Nov 2022 20:58:52 +0000 (21:58 +0100)] 
netlink: Bounds-check struct nlmsgerr creation

In preparation for FORTIFY_SOURCE doing bounds-check on memcpy(),
switch from __nlmsg_put to nlmsg_put(), and explain the bounds check
for dealing with the memcpy() across a composite flexible array struct.
Avoids this future run-time warning:

  memcpy: detected field-spanning write (size 32) of single field "&errmsg->msg" at net/netlink/af_netlink.c:2447 (size 16)

Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: Jozsef Kadlecsik <kadlec@netfilter.org>
Cc: Florian Westphal <fw@strlen.de>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: syzbot <syzkaller@googlegroups.com>
Cc: netfilter-devel@vger.kernel.org
Cc: coreteam@netfilter.org
Cc: netdev@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20220901071336.1418572-1-keescook@chromium.org
Signed-off-by: David S. Miller <davem@davemloft.net>
2 years agocompatibility: move to skb_protocol in the code from tc_skb_protocol
Jozsef Kadlecsik [Mon, 7 Nov 2022 20:50:05 +0000 (21:50 +0100)] 
compatibility: move to skb_protocol in the code from tc_skb_protocol

And fix a typo committed by me in em_sched.c too.

2 years agoCompatibility: check kvcalloc, kvfree, kvzalloc in slab.h too
Jozsef Kadlecsik [Mon, 7 Nov 2022 20:47:23 +0000 (21:47 +0100)] 
Compatibility: check kvcalloc, kvfree, kvzalloc in slab.h too

2 years agosched: consistently handle layer3 header accesses in the presence of VLANs
Toke Høiland-Jørgensen [Mon, 7 Nov 2022 20:26:00 +0000 (21:26 +0100)] 
sched: consistently handle layer3 header accesses in the presence of VLANs

There are a couple of places in net/sched/ that check skb->protocol and act
on the value there. However, in the presence of VLAN tags, the value stored
in skb->protocol can be inconsistent based on whether VLAN acceleration is
enabled. The commit quoted in the Fixes tag below fixed the users of
skb->protocol to use a helper that will always see the VLAN ethertype.

However, most of the callers don't actually handle the VLAN ethertype, but
expect to find the IP header type in the protocol field. This means that
things like changing the ECN field, or parsing diffserv values, stops
working if there's a VLAN tag, or if there are multiple nested VLAN
tags (QinQ).

To fix this, change the helper to take an argument that indicates whether
the caller wants to skip the VLAN tags or not. When skipping VLAN tags, we
make sure to skip all of them, so behaviour is consistent even in QinQ
mode.

To make the helper usable from the ECN code, move it to if_vlan.h instead
of pkt_sched.h.

v3:
- Remove empty lines
- Move vlan variable definitions inside loop in skb_protocol()
- Also use skb_protocol() helper in IP{,6}_ECN_decapsulate() and
  bpf_skb_ecn_set_ce()

v2:
- Use eth_type_vlan() helper in skb_protocol()
- Also fix code that reads skb->protocol directly
- Change a couple of 'if/else if' statements to switch constructs to avoid
  calling the helper twice

Reported-by: Ilya Ponetayev <i.ponetaev@ndmsystems.com>
Fixes: d8b9605d2697 ("net: sched: fix skb->protocol use in case of accelerated vlan path")
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2 years agotreewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500
Thomas Gleixner [Mon, 7 Nov 2022 20:20:10 +0000 (21:20 +0100)] 
treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500

em_sched.c was left out, fix it now.

2 years agoheaders: Remove some left-over license text in include/uapi/linux/netfilter/
Christophe JAILLET [Mon, 7 Nov 2022 20:11:28 +0000 (21:11 +0100)] 
headers: Remove some left-over license text in include/uapi/linux/netfilter/

When the SPDX-License-Identifier tag has been added, the corresponding
license text has not been removed.

Remove it now.

Also, in xt_connmark.h, move the copyright text at the top of the file
which is a much more common pattern.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Florian Westphal <fw@strlen.de>
2 years agonetfilter: ipset: enforce documented limit to prevent allocating huge memory
Jozsef Kadlecsik [Mon, 7 Nov 2022 20:06:50 +0000 (21:06 +0100)] 
netfilter: ipset: enforce documented limit to prevent allocating huge memory

Daniel Xu reported that the hash:net,iface type of the ipset subsystem does
not limit adding the same network with different interfaces to a set, which
can lead to huge memory usage or allocation failure.

The quick reproducer is

$ 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

The backtrace when vmalloc fails:

        [Tue Oct 25 00:13:08 2022] ipset: vmalloc error: size 1073741848, exceeds total pages
        <...>
        [Tue Oct 25 00:13:08 2022] Call Trace:
        [Tue Oct 25 00:13:08 2022]  <TASK>
        [Tue Oct 25 00:13:08 2022]  dump_stack_lvl+0x48/0x60
        [Tue Oct 25 00:13:08 2022]  warn_alloc+0x155/0x180
        [Tue Oct 25 00:13:08 2022]  __vmalloc_node_range+0x72a/0x760
        [Tue Oct 25 00:13:08 2022]  ? hash_netiface4_add+0x7c0/0xb20
        [Tue Oct 25 00:13:08 2022]  ? __kmalloc_large_node+0x4a/0x90
        [Tue Oct 25 00:13:08 2022]  kvmalloc_node+0xa6/0xd0
        [Tue Oct 25 00:13:08 2022]  ? hash_netiface4_resize+0x99/0x710
        <...>

The fix is to enforce the limit documented in the ipset(8) manpage:

>  The internal restriction of the hash:net,iface set type is that the same
>  network prefix cannot be stored with more than 64 different interfaces
>  in a single set.

Reported-by: Daniel Xu <dxu@dxuuu.xyz>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
2 years agonetfilter: ipset: Fix oversized kvmalloc() calls
Jozsef Kadlecsik [Mon, 6 Sep 2021 16:03:37 +0000 (18:03 +0200)] 
netfilter: ipset: Fix oversized kvmalloc() calls

commit 7661809d493b426e979f39ab512e3adf41fbcc69
Author: Linus Torvalds <torvalds@linux-foundation.org>
Date:   Wed Jul 14 09:45:49 2021 -0700

    mm: don't allow oversized kvmalloc() calls

limits the max allocatable memory via kvmalloc() to MAX_INT. Apply the
same limit in ipset.

Reported-by: syzbot+3493b1873fb3ea827986@syzkaller.appspotmail.com
Reported-by: syzbot+2b8443c35458a617c904@syzkaller.appspotmail.com
Reported-by: syzbot+ee5cb15f4a0e85e0d54e@syzkaller.appspotmail.com
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
2 years agoipset-translate: allow invoking with a path name
Quentin Armitage [Thu, 11 Aug 2022 16:52:18 +0000 (17:52 +0100)] 
ipset-translate: allow invoking with a path name

Executing /usr/sbin/ipset-translate results in the ipset functionality being run, rather than the ipset-translate functionality.

 # ipset-translate destroy fred
 This command is not supported, use `ipset-translate restore < file'

 # /usr/sbin/ipset-translate destroy fred
 ipset v7.15: The set with the given name does not exist

use basename() to resolve the issue.

Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1626
Signed-off-by: Quentin Armitage <quentin@armitage.org.uk>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agoFix IPv6 sets nftables translation
Pablo Neira Ayuso [Mon, 28 Feb 2022 18:52:57 +0000 (19:52 +0100)] 
Fix IPv6 sets nftables translation

The parser assumes the set is an IPv4 ipset because IPSET_OPT_FAMILY is
not set.

 # ipset-translate restore < ./ipset-mwan3_set_connected_ipv6.dump
 add table inet global
 add set inet global mwan3_connected_v6 { type ipv6_addr; flags interval; }
 flush set inet global mwan3_connected_v6
 ipset v7.15: Error in line 4: Syntax error: '64' is out of range 0-32

Remove ipset_xlate_type_get(), call ipset_xlate_set_get() instead to
obtain the set type and family.

Reported-by: Florian Eckert <fe@dev.tdt.de>
Fixes: 325af556cd3a ("add ipset to nftables translation infrastructure")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agoFix typo in ipset-translate man page
Bernhard M. Wiedemann [Wed, 29 Sep 2021 07:55:43 +0000 (09:55 +0200)] 
Fix typo in ipset-translate man page

originally reported in
https://lists.opensuse.org/archives/list/factory@lists.opensuse.org/thread/ZIXKNQHSSCQ4ZLEGYYKLAXQ4PQ5EYFGZ/
by Larry Len Rainey

Signed-off-by: Bernhard M. Wiedemann <bwiedemann@suse.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
4 years agoipset 7.15 released v7.15
Jozsef Kadlecsik [Wed, 4 Aug 2021 06:18:14 +0000 (08:18 +0200)] 
ipset 7.15 released

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agonetfilter: ipset: Fix maximal range check in hash_ipportnet4_uadt()
Nathan Chancellor [Tue, 3 Aug 2021 19:31:02 +0000 (21:31 +0200)] 
netfilter: ipset: Fix maximal range check in hash_ipportnet4_uadt()

Clang warns:

net/netfilter/ipset/ip_set_hash_ipportnet.c:249:29: warning: variable
'port_to' is uninitialized when used here [-Wuninitialized]
        if (((u64)ip_to - ip + 1)*(port_to - port + 1) > IPSET_MAX_RANGE)
                                   ^~~~~~~
net/netfilter/ipset/ip_set_hash_ipportnet.c:167:45: note: initialize the
variable 'port_to' to silence this warning
        u32 ip = 0, ip_to = 0, p = 0, port, port_to;
                                                   ^
                                                    = 0
net/netfilter/ipset/ip_set_hash_ipportnet.c:249:39: warning: variable
'port' is uninitialized when used here [-Wuninitialized]
        if (((u64)ip_to - ip + 1)*(port_to - port + 1) > IPSET_MAX_RANGE)
                                             ^~~~
net/netfilter/ipset/ip_set_hash_ipportnet.c:167:36: note: initialize the
variable 'port' to silence this warning
        u32 ip = 0, ip_to = 0, p = 0, port, port_to;
                                          ^
                                           = 0
2 warnings generated.

The range check was added before port and port_to are initialized.
Shuffle the check after the initialization so that the check works
properly.

Fixes: 7fb6c63025ff ("netfilter: ipset: Limit the maximal range of consecutive elements to
add/delete")

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoipset 7.14 released v7.14
Jozsef Kadlecsik [Wed, 28 Jul 2021 14:23:06 +0000 (16:23 +0200)] 
ipset 7.14 released

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years ago64bit division isn't allowed on 32bit, replace it with shift
Jozsef Kadlecsik [Wed, 28 Jul 2021 14:06:46 +0000 (16:06 +0200)] 
64bit division isn't allowed on 32bit, replace it with shift

The number of hosts in a netblock must be a power of two,
so use shift instead of division.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoAdd missing function to libipset.map and bump library version
Jozsef Kadlecsik [Wed, 28 Jul 2021 14:02:49 +0000 (16:02 +0200)] 
Add missing function to libipset.map and bump library version

A new function was not added to libipset.map at the previous release,
fix it. Reported by Jan Engelhardt.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoipset 7.13 released v7.13
Jozsef Kadlecsik [Tue, 27 Jul 2021 10:19:02 +0000 (12:19 +0200)] 
ipset 7.13 released

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoWhen parsing protocols by number, do not check it in /etc/protocols.
Jozsef Kadlecsik [Tue, 27 Jul 2021 10:16:47 +0000 (12:16 +0200)] 
When parsing protocols by number, do not check it in /etc/protocols.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoAdd missing hunk to patch "Allow specifying protocols by number"
Jozsef Kadlecsik [Fri, 16 Jul 2021 12:53:26 +0000 (14:53 +0200)] 
Add missing hunk to patch "Allow specifying protocols by number"

Actually, this is the part of it which allows specifying protocols
by number :-)

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoLimit the maximal range of consecutive elements to add/delete fix
Jozsef Kadlecsik [Fri, 16 Jul 2021 12:36:45 +0000 (14:36 +0200)] 
Limit the maximal range of consecutive elements to add/delete fix

Avoid possible number overflows when calculating the number of
consecutive elements. Also, compute properly the consecutive
elements in the case of hash:net* types.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoipset 7.12 released v7.12
Jozsef Kadlecsik [Wed, 14 Jul 2021 11:33:39 +0000 (13:33 +0200)] 
ipset 7.12 released

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoAllow specifying protocols by number
Haw Loeung [Wed, 14 Jul 2021 11:05:34 +0000 (13:05 +0200)] 
Allow specifying protocols by number

This allows us to optimise and reduce restore time by specifying
protocol numbers, especially for large ipsets.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoLimit the maximal range of consecutive elements to add/delete
Jozsef Kadlecsik [Wed, 14 Jul 2021 10:37:07 +0000 (12:37 +0200)] 
Limit the maximal range of consecutive elements to add/delete

The range size of consecutive elements were not limited. Thus one
could define a huge range which may result soft lockup errors due
to the long execution time. Now the range size is limited to 2^20
entries. Reported by Brad Spengler.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoFix example in ipset.8 manpage discovered by Pablo Neira Ayuso.
Jozsef Kadlecsik [Sun, 27 Jun 2021 19:13:46 +0000 (21:13 +0200)] 
Fix example in ipset.8 manpage discovered by Pablo Neira Ayuso.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agotests: add tests ipset to nftables
Pablo Neira Ayuso [Fri, 25 Jun 2021 20:30:43 +0000 (22:30 +0200)] 
tests: add tests ipset to nftables

This test checks that the translation from ipset to nftables is correct.

term$ cd tests/xlate
term$ ./runtest.sh

in case that the translation is not correct, it shows the diff with expected
translation output.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoadd ipset to nftables translation infrastructure
Pablo Neira Ayuso [Fri, 25 Jun 2021 20:30:42 +0000 (22:30 +0200)] 
add ipset to nftables translation infrastructure

This patch provides the ipset-translate utility which allows you to
translate your existing ipset file to nftables.

The ipset-translate utility is actually a symlink to ipset, which checks
for 'argv[0] == ipset-translate' to exercise the translation path.

You can translate your ipset file through:

ipset-translate restore < sets.ipt

This patch reuses the existing parser and API to represent the sets and
the elements.

There is a new ipset_xlate_set dummy object that allows to store a
created set to fetch the type without interactions with the kernel.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agolib: Detach restore routine from parser
Pablo Neira Ayuso [Fri, 25 Jun 2021 20:30:41 +0000 (22:30 +0200)] 
lib: Detach restore routine from parser

Do not call restore() from ipset_parser(). Instead, ipset_parser()
returns the IPSET_CMD_RESTORE command and the caller invokes restore().

This patch comes in preparation for the ipset to nftables translation
infrastructure.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agolib: split parser from command execution
Pablo Neira Ayuso [Fri, 25 Jun 2021 20:30:40 +0000 (22:30 +0200)] 
lib: split parser from command execution

ipset_parse_argv() parses, builds and send the netlink messages to the
kernel. This patch extracts the parser and wrap it around the new
ipset_parser() function.

This patch comes is preparation for the ipset to nftables translation
infrastructure.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoBackport "netfilter: use nfnetlink_unicast()"
Jozsef Kadlecsik [Sat, 26 Jun 2021 21:06:20 +0000 (23:06 +0200)] 
Backport "netfilter: use nfnetlink_unicast()"

Backport patch "netfilter: use nfnetlink_unicast()" from
Pablo Neira Ayuso <pablo@netfilter.org>.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoBackport "netfilter: nfnetlink: consolidate callback type"
Jozsef Kadlecsik [Sat, 26 Jun 2021 20:21:05 +0000 (22:21 +0200)] 
Backport "netfilter: nfnetlink: consolidate callback type"

Backport patch "netfilter: nfnetlink: consolidate callback type"
from Pablo Neira Ayuso <pablo@netfilter.org>.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoBackport "netfilter: nfnetlink: add struct nfnl_info and pass it to callbacks"
Jozsef Kadlecsik [Thu, 24 Jun 2021 11:24:09 +0000 (13:24 +0200)] 
Backport "netfilter: nfnetlink: add struct nfnl_info and pass it to callbacks"

Backport patch "netfilter: nfnetlink: add struct nfnl_info and pass it
to callbacks" from Pablo Neira Ayuso <pablo@netfilter.org>.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoBackport "netfilter: add helper function to set up the nfnetlink header and use it"
Jozsef Kadlecsik [Sat, 26 Jun 2021 20:17:58 +0000 (22:17 +0200)] 
Backport "netfilter: add helper function to set up the nfnetlink header and use it"

Backport patch "netfilter: add helper function to set up the nfnetlink
header and use it" from Pablo Neira Ayuso <pablo@netfilter.org>.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoFix patch "Parse port before trying by service name"
Jozsef Kadlecsik [Sat, 26 Jun 2021 20:14:38 +0000 (22:14 +0200)] 
Fix patch "Parse port before trying by service name"

The patch broke parsing service names: number parsing failures
are hard errors which erase data, thus making impossible to
parse input as a string. Fix it by enabling soft (warning)
failures in the case of port number parsing.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoipset 7.11 released v7.11
Jozsef Kadlecsik [Fri, 19 Feb 2021 20:30:58 +0000 (21:30 +0100)] 
ipset 7.11 released

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoParse port before trying by service name
Haw Loeung [Wed, 17 Feb 2021 09:15:07 +0000 (10:15 +0100)] 
Parse port before trying by service name

This improves performance for loading IP sets using port numbers,
especially large ones.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoSilence unused-but-set-variable warnings
Jozsef Kadlecsik [Wed, 17 Feb 2021 09:07:27 +0000 (10:07 +0100)] 
Silence unused-but-set-variable warnings

When ipset is compiled in non-debug mode, in some environments warnings
treated as errors emitted:

  session.c: In function 'build_msg':
  session.c:1985:28: warning: variable 'type' set but not used
[-Wunused-but-set-variable]
     const struct ipset_type *type;
                            ^
  session.c:2030:28: warning: variable 'type' set but not used
[-Wunused-but-set-variable]
     const struct ipset_type *type;
                            ^
Fix it by hiding the unused variable definitions/settings in non-debug mode.

Reported by Serhey Popovych.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoHandle -Werror=implicit-fallthrough= in debug mode compiling
Jozsef Kadlecsik [Tue, 9 Feb 2021 18:41:23 +0000 (19:41 +0100)] 
Handle -Werror=implicit-fallthrough= in debug mode compiling

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoipset: fix print format warning
Neutron Soutmun [Mon, 18 Jan 2021 04:58:30 +0000 (11:58 +0700)] 
ipset: fix print format warning

* Use PRIx64 for portablility over various architectures.
* The format string for the 64bit number printing is incorrect,
  the `%` sign is missing.
* The force types casting over the uint32_t and uint64_t are unnecessary
  which warned by the compiler on different architecture.

Signed-off-by: Neutron Soutmun <neo.neutron@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoUpdated utilities
Jozsef Kadlecsik [Tue, 19 Jan 2021 07:53:40 +0000 (08:53 +0100)] 
Updated utilities

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoArgument parsing buffer overflow in ipset_parse_argv fixed
Jozsef Kadlecsik [Tue, 19 Jan 2021 07:39:50 +0000 (08:39 +0100)] 
Argument parsing buffer overflow in ipset_parse_argv fixed

Argument length checking was simply missing. Fixes netfilter
bugzilla #1492, reported by Marshall Whittaker.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoipset 7.10 released v7.10
Jozsef Kadlecsik [Sun, 20 Dec 2020 14:44:11 +0000 (15:44 +0100)] 
ipset 7.10 released

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoFix patch "Handle false warning from -Wstringop-overflow"
Jozsef Kadlecsik [Sun, 20 Dec 2020 14:07:21 +0000 (15:07 +0100)] 
Fix patch "Handle false warning from -Wstringop-overflow"

Return code of strscpy() was not handled properly.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoBackward compatibility: handle renaming nla_strlcpy to nla_strscpy
Jozsef Kadlecsik [Sun, 20 Dec 2020 13:11:06 +0000 (14:11 +0100)] 
Backward compatibility: handle renaming nla_strlcpy to nla_strscpy

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agotreewide: rename nla_strlcpy to nla_strscpy.
Francis Laniel [Sun, 20 Dec 2020 12:31:40 +0000 (13:31 +0100)] 
treewide: rename nla_strlcpy to nla_strscpy.

Calls to nla_strlcpy are now replaced by calls to nla_strscpy which is the new
name of this function.

Signed-off-by: Francis Laniel <laniel_francis@privacyrequired.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
4 years agonetfilter: ipset: fix shift-out-of-bounds in htable_bits()
Vasily Averin [Sun, 20 Dec 2020 12:21:13 +0000 (13:21 +0100)] 
netfilter: ipset: fix shift-out-of-bounds in htable_bits()

htable_bits() can call jhash_size(32) and trigger shift-out-of-bounds

UBSAN: shift-out-of-bounds in net/netfilter/ipset/ip_set_hash_gen.h:151:6
shift exponent 32 is too large for 32-bit type 'unsigned int'
CPU: 0 PID: 8498 Comm: syz-executor519
 Not tainted 5.10.0-rc7-next-20201208-syzkaller #0
Call Trace:
 __dump_stack lib/dump_stack.c:79 [inline]
 dump_stack+0x107/0x163 lib/dump_stack.c:120
 ubsan_epilogue+0xb/0x5a lib/ubsan.c:148
 __ubsan_handle_shift_out_of_bounds.cold+0xb1/0x181 lib/ubsan.c:395
 htable_bits net/netfilter/ipset/ip_set_hash_gen.h:151 [inline]
 hash_mac_create.cold+0x58/0x9b net/netfilter/ipset/ip_set_hash_gen.h:1524
 ip_set_create+0x610/0x1380 net/netfilter/ipset/ip_set_core.c:1115
 nfnetlink_rcv_msg+0xecc/0x1180 net/netfilter/nfnetlink.c:252
 netlink_rcv_skb+0x153/0x420 net/netlink/af_netlink.c:2494
 nfnetlink_rcv+0x1ac/0x420 net/netfilter/nfnetlink.c:600
 netlink_unicast_kernel net/netlink/af_netlink.c:1304 [inline]
 netlink_unicast+0x533/0x7d0 net/netlink/af_netlink.c:1330
 netlink_sendmsg+0x907/0xe40 net/netlink/af_netlink.c:1919
 sock_sendmsg_nosec net/socket.c:652 [inline]
 sock_sendmsg+0xcf/0x120 net/socket.c:672
 ____sys_sendmsg+0x6e8/0x810 net/socket.c:2345
  __sys_sendmsg+0xe5/0x1b0 net/socket.c:2432
 do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

This patch replaces htable_bits() by simple fls(hashsize - 1) call:
it alone returns valid nbits both for round and non-round hashsizes.
It is normal to set any nbits here because it is validated inside
following htable_size() call which returns 0 for nbits>31.

Fixes: 1feab10d7e6d("netfilter: ipset: Unified hash type generation")
Reported-by: syzbot+d66bfadebca46cf61a2b@syzkaller.appspotmail.com
Signed-off-by: Vasily Averin <vvs@virtuozzo.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agonetfilter: ipset: fixes possible oops in mtype_resize
Vasily Averin [Sun, 20 Dec 2020 12:17:01 +0000 (13:17 +0100)] 
netfilter: ipset: fixes possible oops in mtype_resize

currently mtype_resize() can cause oops

        t = ip_set_alloc(htable_size(htable_bits));
        if (!t) {
                ret = -ENOMEM;
                goto out;
        }
        t->hregion = ip_set_alloc(ahash_sizeof_regions(htable_bits));

Increased htable_bits can force htable_size() to return 0.
In own turn ip_set_alloc(0) returns not 0 but ZERO_SIZE_PTR,
so follwoing access to t->hregion should trigger an OOPS.

Signed-off-by: Vasily Averin <vvs@virtuozzo.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoHandle false warning from -Wstringop-overflow
Jozsef Kadlecsik [Mon, 14 Dec 2020 09:19:34 +0000 (10:19 +0100)] 
Handle false warning from -Wstringop-overflow

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoBackward compatibility: handle missing strscpy with a wrapper of strlcpy.
Jozsef Kadlecsik [Mon, 14 Dec 2020 09:12:57 +0000 (10:12 +0100)] 
Backward compatibility: handle missing strscpy with a wrapper of strlcpy.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoMove compiler specific compatibility support to separated file
Jozsef Kadlecsik [Mon, 7 Dec 2020 14:35:56 +0000 (15:35 +0100)] 
Move compiler specific compatibility support to separated file

Kernel compatibility support was broken in 7.9, reported by Ed W.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoipset 7.9 released v7.9
Jozsef Kadlecsik [Thu, 19 Nov 2020 21:42:19 +0000 (22:42 +0100)] 
ipset 7.9 released

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoFix library versioning (Jan Engelhardt)
Jozsef Kadlecsik [Thu, 19 Nov 2020 21:41:22 +0000 (22:41 +0100)] 
Fix library versioning (Jan Engelhardt)

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoipset 7.8 released v7.8
Jozsef Kadlecsik [Thu, 19 Nov 2020 20:34:57 +0000 (21:34 +0100)] 
ipset 7.8 released

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoComplete backward compatibility fix for package copy of <linux/jhash.h>
Jozsef Kadlecsik [Thu, 19 Nov 2020 20:26:13 +0000 (21:26 +0100)] 
Complete backward compatibility fix for package copy of <linux/jhash.h>

An unnecessary condition prevented to compile pfxlen.c with the patch
202cfef66b3a1e0988d applied, it's fixed.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>