]> git.ipfire.org Git - thirdparty/ipset.git/log
thirdparty/ipset.git
3 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>
3 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>
3 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>
3 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>
3 years agoCompatibility: check for kvzalloc() and GFP_KERNEL_ACCOUNT
Jozsef Kadlecsik [Thu, 19 Nov 2020 14:01:37 +0000 (15:01 +0100)] 
Compatibility: check for kvzalloc() and GFP_KERNEL_ACCOUNT

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
3 years agonetfilter: ipset: enable memory accounting for ipset allocations
Vasily Averin [Thu, 19 Nov 2020 13:59:51 +0000 (14:59 +0100)] 
netfilter: ipset: enable memory accounting for ipset allocations

Currently netadmin inside non-trusted container can quickly allocate
whole node's memory via request of huge ipset hashtable.
Other ipset-related memory allocations should be restricted too.

v2: fixed typo ALLOC -> ACCOUNT

Signed-off-by: Vasily Averin <vvs@virtuozzo.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
3 years agonetfilter: ipset: prevent uninit-value in hash_ip6_add
Eric Dumazet [Thu, 19 Nov 2020 13:07:48 +0000 (14:07 +0100)] 
netfilter: ipset: prevent uninit-value in hash_ip6_add

syzbot found that we are not validating user input properly
before copying 16 bytes [1].

Using NLA_BINARY in ipaddr_policy[] for IPv6 address is not correct,
since it ensures at most 16 bytes were provided.

We should instead make sure user provided exactly 16 bytes.

In old kernels (before v4.20), fix would be to remove the NLA_BINARY,
since NLA_POLICY_EXACT_LEN() was not yet available.

[1]
BUG: KMSAN: uninit-value in hash_ip6_add+0x1cba/0x3a50
net/netfilter/ipset/ip_set_hash_gen.h:892
CPU: 1 PID: 11611 Comm: syz-executor.0 Not tainted 5.10.0-rc4-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
 __dump_stack lib/dump_stack.c:77 [inline]
 dump_stack+0x21c/0x280 lib/dump_stack.c:118
 kmsan_report+0xf7/0x1e0 mm/kmsan/kmsan_report.c:118
 __msan_warning+0x5f/0xa0 mm/kmsan/kmsan_instr.c:197
 hash_ip6_add+0x1cba/0x3a50 net/netfilter/ipset/ip_set_hash_gen.h:892
 hash_ip6_uadt+0x976/0xbd0 net/netfilter/ipset/ip_set_hash_ip.c:267
 call_ad+0x329/0xd00 net/netfilter/ipset/ip_set_core.c:1720
 ip_set_ad+0x111f/0x1440 net/netfilter/ipset/ip_set_core.c:1808
 ip_set_uadd+0xf6/0x110 net/netfilter/ipset/ip_set_core.c:1833
 nfnetlink_rcv_msg+0xc7d/0xdf0 net/netfilter/nfnetlink.c:252
 netlink_rcv_skb+0x70a/0x820 net/netlink/af_netlink.c:2494
 nfnetlink_rcv+0x4f0/0x4380 net/netfilter/nfnetlink.c:600
 netlink_unicast_kernel net/netlink/af_netlink.c:1304 [inline]
 netlink_unicast+0x11da/0x14b0 net/netlink/af_netlink.c:1330
 netlink_sendmsg+0x173c/0x1840 net/netlink/af_netlink.c:1919
 sock_sendmsg_nosec net/socket.c:651 [inline]
 sock_sendmsg net/socket.c:671 [inline]
 ____sys_sendmsg+0xc7a/0x1240 net/socket.c:2353
 ___sys_sendmsg net/socket.c:2407 [inline]
 __sys_sendmsg+0x6d5/0x830 net/socket.c:2440
 __do_sys_sendmsg net/socket.c:2449 [inline]
 __se_sys_sendmsg+0x97/0xb0 net/socket.c:2447
 __x64_sys_sendmsg+0x4a/0x70 net/socket.c:2447
 do_syscall_64+0x9f/0x140 arch/x86/entry/common.c:48
 entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x45deb9
Code: 0d b4 fb ff c3 66 2e 0f 1f 84 00 00 00 00 00 66 90 48 89 f8 48 89 f7 48 89
d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 0f 83 db b3
fb ff c3 66 2e 0f 1f 84 00 00 00 00
RSP: 002b:00007fe2e503fc78 EFLAGS: 00000246 ORIG_RAX: 000000000000002e
RAX: ffffffffffffffda RBX: 0000000000029ec0 RCX: 000000000045deb9
RDX: 0000000000000000 RSI: 0000000020000140 RDI: 0000000000000003
RBP: 000000000118bf60 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 000000000118bf2c
R13: 000000000169fb7f R14: 00007fe2e50409c0 R15: 000000000118bf2c

Uninit was stored to memory at:
 kmsan_save_stack_with_flags mm/kmsan/kmsan.c:121 [inline]
 kmsan_internal_chain_origin+0xad/0x130 mm/kmsan/kmsan.c:289
 __msan_chain_origin+0x57/0xa0 mm/kmsan/kmsan_instr.c:147
 ip6_netmask include/linux/netfilter/ipset/pfxlen.h:49 [inline]
 hash_ip6_netmask net/netfilter/ipset/ip_set_hash_ip.c:185 [inline]
 hash_ip6_uadt+0xb1c/0xbd0 net/netfilter/ipset/ip_set_hash_ip.c:263
 call_ad+0x329/0xd00 net/netfilter/ipset/ip_set_core.c:1720
 ip_set_ad+0x111f/0x1440 net/netfilter/ipset/ip_set_core.c:1808
 ip_set_uadd+0xf6/0x110 net/netfilter/ipset/ip_set_core.c:1833
 nfnetlink_rcv_msg+0xc7d/0xdf0 net/netfilter/nfnetlink.c:252
 netlink_rcv_skb+0x70a/0x820 net/netlink/af_netlink.c:2494
 nfnetlink_rcv+0x4f0/0x4380 net/netfilter/nfnetlink.c:600
 netlink_unicast_kernel net/netlink/af_netlink.c:1304 [inline]
 netlink_unicast+0x11da/0x14b0 net/netlink/af_netlink.c:1330
 netlink_sendmsg+0x173c/0x1840 net/netlink/af_netlink.c:1919
 sock_sendmsg_nosec net/socket.c:651 [inline]
 sock_sendmsg net/socket.c:671 [inline]
 ____sys_sendmsg+0xc7a/0x1240 net/socket.c:2353
 ___sys_sendmsg net/socket.c:2407 [inline]
 __sys_sendmsg+0x6d5/0x830 net/socket.c:2440
 __do_sys_sendmsg net/socket.c:2449 [inline]
 __se_sys_sendmsg+0x97/0xb0 net/socket.c:2447
 __x64_sys_sendmsg+0x4a/0x70 net/socket.c:2447
 do_syscall_64+0x9f/0x140 arch/x86/entry/common.c:48
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

Uninit was stored to memory at:
 kmsan_save_stack_with_flags mm/kmsan/kmsan.c:121 [inline]
 kmsan_internal_chain_origin+0xad/0x130 mm/kmsan/kmsan.c:289
 kmsan_memcpy_memmove_metadata+0x25e/0x2d0 mm/kmsan/kmsan.c:226
 kmsan_memcpy_metadata+0xb/0x10 mm/kmsan/kmsan.c:246
 __msan_memcpy+0x46/0x60 mm/kmsan/kmsan_instr.c:110
 ip_set_get_ipaddr6+0x2cb/0x370 net/netfilter/ipset/ip_set_core.c:310
 hash_ip6_uadt+0x439/0xbd0 net/netfilter/ipset/ip_set_hash_ip.c:255
 call_ad+0x329/0xd00 net/netfilter/ipset/ip_set_core.c:1720
 ip_set_ad+0x111f/0x1440 net/netfilter/ipset/ip_set_core.c:1808
 ip_set_uadd+0xf6/0x110 net/netfilter/ipset/ip_set_core.c:1833
 nfnetlink_rcv_msg+0xc7d/0xdf0 net/netfilter/nfnetlink.c:252
 netlink_rcv_skb+0x70a/0x820 net/netlink/af_netlink.c:2494
 nfnetlink_rcv+0x4f0/0x4380 net/netfilter/nfnetlink.c:600
 netlink_unicast_kernel net/netlink/af_netlink.c:1304 [inline]
 netlink_unicast+0x11da/0x14b0 net/netlink/af_netlink.c:1330
 netlink_sendmsg+0x173c/0x1840 net/netlink/af_netlink.c:1919
 sock_sendmsg_nosec net/socket.c:651 [inline]
 sock_sendmsg net/socket.c:671 [inline]
 ____sys_sendmsg+0xc7a/0x1240 net/socket.c:2353
 ___sys_sendmsg net/socket.c:2407 [inline]
 __sys_sendmsg+0x6d5/0x830 net/socket.c:2440
 __do_sys_sendmsg net/socket.c:2449 [inline]
 __se_sys_sendmsg+0x97/0xb0 net/socket.c:2447
 __x64_sys_sendmsg+0x4a/0x70 net/socket.c:2447
 do_syscall_64+0x9f/0x140 arch/x86/entry/common.c:48
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

Uninit was created at:
 kmsan_save_stack_with_flags mm/kmsan/kmsan.c:121 [inline]
 kmsan_internal_poison_shadow+0x5c/0xf0 mm/kmsan/kmsan.c:104
 kmsan_slab_alloc+0x8d/0xe0 mm/kmsan/kmsan_hooks.c:76
 slab_alloc_node mm/slub.c:2906 [inline]
 __kmalloc_node_track_caller+0xc61/0x15f0 mm/slub.c:4512
 __kmalloc_reserve net/core/skbuff.c:142 [inline]
 __alloc_skb+0x309/0xae0 net/core/skbuff.c:210
 alloc_skb include/linux/skbuff.h:1094 [inline]
 netlink_alloc_large_skb net/netlink/af_netlink.c:1176 [inline]
 netlink_sendmsg+0xdb8/0x1840 net/netlink/af_netlink.c:1894
 sock_sendmsg_nosec net/socket.c:651 [inline]
 sock_sendmsg net/socket.c:671 [inline]
 ____sys_sendmsg+0xc7a/0x1240 net/socket.c:2353
 ___sys_sendmsg net/socket.c:2407 [inline]
 __sys_sendmsg+0x6d5/0x830 net/socket.c:2440
 __do_sys_sendmsg net/socket.c:2449 [inline]
 __se_sys_sendmsg+0x97/0xb0 net/socket.c:2447
 __x64_sys_sendmsg+0x4a/0x70 net/socket.c:2447
 do_syscall_64+0x9f/0x140 arch/x86/entry/common.c:48
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

Fixes: a7b4f989a629 ("netfilter: ipset: IP set core support")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: syzbot <syzkaller@googlegroups.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
3 years agoCompatibility: use skb_policy() from if_vlan.h if available
Jozsef Kadlecsik [Thu, 19 Nov 2020 12:50:02 +0000 (13:50 +0100)] 
Compatibility: use skb_policy() from if_vlan.h if available

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
3 years agoCompatibility: Check for the fourth arg of list_for_each_entry_rcu()
Jozsef Kadlecsik [Thu, 19 Nov 2020 12:05:45 +0000 (13:05 +0100)] 
Compatibility: Check for the fourth arg of list_for_each_entry_rcu()

A forth argument of list_for_each_entry_rcu() was introduced, handle the
compatibility issue.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
3 years agoBackward compatibility fix for the package copy of <linux/jhash.h>
Jozsef Kadlecsik [Sun, 8 Nov 2020 20:54:01 +0000 (21:54 +0100)] 
Backward compatibility fix for the package copy of <linux/jhash.h>

The patch "Use fallthrough pseudo-keyword in the package copy of
<linux/jhash.h> too" missed to include the compatibility header file.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
3 years agoipset 7.7 released v7.7
Jozsef Kadlecsik [Tue, 22 Sep 2020 07:31:19 +0000 (09:31 +0200)] 
ipset 7.7 released

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
3 years agoExpose the initval hash parameter to userspace
Jozsef Kadlecsik [Mon, 21 Sep 2020 18:13:07 +0000 (20:13 +0200)] 
Expose the initval hash parameter to userspace

It makes possible to reproduce exactly the same set after a save/restore.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
3 years agoHandle all variable header parts in helper scripts instead ot test tasks
Jozsef Kadlecsik [Mon, 21 Sep 2020 18:12:23 +0000 (20:12 +0200)] 
Handle all variable header parts in helper scripts instead ot test tasks

Thus the tests tasks can be simplified and all exceptions can be handled in
the helper scripts.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
3 years agoAdd bucketsize parameter to all hash types
Jozsef Kadlecsik [Mon, 21 Sep 2020 08:21:39 +0000 (10:21 +0200)] 
Add bucketsize parameter to all hash types

The parameter defines the upper limit in any hash bucket at adding new entries
from userspace - if the limit would be exceeded, ipset doubles the hash size
and rehashes. It means the set may consume more memory but gives faster
evaluation at matching in the set.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
3 years agoUse fallthrough pseudo-keyword in the package copy of <linux/jhash.h> too
Jozsef Kadlecsik [Sun, 20 Sep 2020 20:48:28 +0000 (22:48 +0200)] 
Use fallthrough pseudo-keyword in the package copy of <linux/jhash.h> too

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
3 years agoSupport the -exist flag with the destroy command
Jozsef Kadlecsik [Sun, 20 Sep 2020 11:06:59 +0000 (13:06 +0200)] 
Support the -exist flag with the destroy command

The -exist flag was supported with the create, add and delete commands.
In order to gracefully handle the destroy command with nonexistent sets,
the -exist flag is added to destroy too.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
3 years agonetfilter: Use fallthrough pseudo-keyword
Gustavo A. R. Silva [Wed, 8 Jul 2020 20:09:39 +0000 (15:09 -0500)] 
netfilter: Use fallthrough pseudo-keyword

Replace the existing /* fall through */ comments and its variants with
the new pseudo-keyword macro fallthrough[1]. Also, remove unnecessary
fall-through markings when it is the case.

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html?highlight=fallthrough#implicit-switch-case-fall-through

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
3 years agonetfilter: Replace zero-length array with flexible-array member
Gustavo A. R. Silva [Thu, 20 Feb 2020 13:59:14 +0000 (07:59 -0600)] 
netfilter: Replace zero-length array with flexible-array member

The current codebase makes use of the zero-length array language
extension to the C90 standard, but the preferred mechanism to declare
variable-length types such as these ones is a flexible array member[1][2],
introduced in C99:

struct foo {
        int stuff;
        struct boo array[];
};

By making use of the mechanism above, we will get a compiler warning
in case the flexible array does not occur last in the structure, which
will help us prevent some kind of undefined behavior bugs from being
inadvertently introduced[3] to the codebase from now on.

Also, notice that, dynamic memory allocations won't be affected by
this change:

"Flexible array members have incomplete type, and so the sizeof operator
may not be applied. As a quirk of the original implementation of
zero-length arrays, sizeof evaluates to zero."[1]

Lastly, fix checkpatch.pl warning
WARNING: __aligned(size) is preferred over __attribute__((aligned(size)))
in net/bridge/netfilter/ebtables.c

This issue was found with the help of Coccinelle.

[1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
[2] https://github.com/KSPP/linux/issues/21
[3] commit 76497732932f ("cxgb3/l2t: Fix undefined behaviour")

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
3 years agonetfilter: ipset: call ip_set_free() instead of kfree()
Eric Dumazet [Tue, 30 Jun 2020 00:04:17 +0000 (17:04 -0700)] 
netfilter: ipset: call ip_set_free() instead of kfree()

Whenever ip_set_alloc() is used, allocated memory can either
use kmalloc() or vmalloc(). We should call kvfree() or
ip_set_free()

invalid opcode: 0000 [#1] PREEMPT SMP KASAN
CPU: 0 PID: 21935 Comm: syz-executor.3 Not tainted 5.8.0-rc2-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
RIP: 0010:__phys_addr+0xa7/0x110 arch/x86/mm/physaddr.c:28
Code: 1d 7a 09 4c 89 e3 31 ff 48 d3 eb 48 89 de e8 d0 58 3f 00 48 85 db 75 0d e8 26 5c 3f 00 4c 89 e0 5b 5d 41 5c c3 e8 19 5c 3f 00 <0f> 0b e8 12 5c 3f 00 48 c7 c0 10 10 a8 89 48 ba 00 00 00 00 00 fc
RSP: 0000:ffffc900018572c0 EFLAGS: 00010046
RAX: 0000000000040000 RBX: 0000000000000001 RCX: ffffc9000fac3000
RDX: 0000000000040000 RSI: ffffffff8133f437 RDI: 0000000000000007
RBP: ffffc90098aff000 R08: 0000000000000000 R09: ffff8880ae636cdb
R10: 0000000000000000 R11: 0000000000000000 R12: 0000408018aff000
R13: 0000000000080000 R14: 000000000000001d R15: ffffc900018573d8
FS:  00007fc540c66700(0000) GS:ffff8880ae600000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fc9dcd67200 CR3: 0000000059411000 CR4: 00000000001406f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
 virt_to_head_page include/linux/mm.h:841 [inline]
 virt_to_cache mm/slab.h:474 [inline]
 kfree+0x77/0x2c0 mm/slab.c:3749
 hash_net_create+0xbb2/0xd70 net/netfilter/ipset/ip_set_hash_gen.h:1536
 ip_set_create+0x6a2/0x13c0 net/netfilter/ipset/ip_set_core.c:1128
 nfnetlink_rcv_msg+0xbe8/0xea0 net/netfilter/nfnetlink.c:230
 netlink_rcv_skb+0x15a/0x430 net/netlink/af_netlink.c:2469
 nfnetlink_rcv+0x1ac/0x420 net/netfilter/nfnetlink.c:564
 netlink_unicast_kernel net/netlink/af_netlink.c:1303 [inline]
 netlink_unicast+0x533/0x7d0 net/netlink/af_netlink.c:1329
 netlink_sendmsg+0x856/0xd90 net/netlink/af_netlink.c:1918
 sock_sendmsg_nosec net/socket.c:652 [inline]
 sock_sendmsg+0xcf/0x120 net/socket.c:672
 ____sys_sendmsg+0x6e8/0x810 net/socket.c:2352
 ___sys_sendmsg+0xf3/0x170 net/socket.c:2406
 __sys_sendmsg+0xe5/0x1b0 net/socket.c:2439
 do_syscall_64+0x60/0xe0 arch/x86/entry/common.c:359
 entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x45cb19
Code: Bad RIP value.
RSP: 002b:00007fc540c65c78 EFLAGS: 00000246 ORIG_RAX: 000000000000002e
RAX: ffffffffffffffda RBX: 00000000004fed80 RCX: 000000000045cb19
RDX: 0000000000000000 RSI: 0000000020001080 RDI: 0000000000000003
RBP: 000000000078bf00 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00000000ffffffff
R13: 000000000000095e R14: 00000000004cc295 R15: 00007fc540c666d4

Fixes: f66ee0410b1c ("netfilter: ipset: Fix "INFO: rcu detected stall in hash_xxx" reports")
Fixes: 03c8b234e61a ("netfilter: ipset: Generalize extensions support")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: syzbot <syzkaller@googlegroups.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
3 years agonetfiler: ipset: fix unaligned atomic access
Russell King [Wed, 10 Jun 2020 20:51:11 +0000 (21:51 +0100)] 
netfiler: ipset: fix unaligned atomic access

When using ip_set with counters and comment, traffic causes the kernel
to panic on 32-bit ARM:

Alignment trap: not handling instruction e1b82f9f at [<bf01b0dc>]
Unhandled fault: alignment exception (0x221) at 0xea08133c
PC is at ip_set_match_extensions+0xe0/0x224 [ip_set]

The problem occurs when we try to update the 64-bit counters - the
faulting address above is not 64-bit aligned.  The problem occurs
due to the way elements are allocated, for example:

set->dsize = ip_set_elem_len(set, tb, 0, 0);
map = ip_set_alloc(sizeof(*map) + elements * set->dsize);

If the element has a requirement for a member to be 64-bit aligned,
and set->dsize is not a multiple of 8, but is a multiple of four,
then every odd numbered elements will be misaligned - and hitting
an atomic64_add() on that element will cause the kernel to panic.

ip_set_elem_len() must return a size that is rounded to the maximum
alignment of any extension field stored in the element.  This change
ensures that is the case.

Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
3 years agonetfilter: ipset: Fix subcounter update skip
Phil Sutter [Thu, 14 May 2020 11:31:21 +0000 (13:31 +0200)] 
netfilter: ipset: Fix subcounter update skip

If IPSET_FLAG_SKIP_SUBCOUNTER_UPDATE is set, user requested to not
update counters in sub sets. Therefore IPSET_FLAG_SKIP_COUNTER_UPDATE
must be set, not unset.

Fixes: 6e01781d1c80e ("netfilter: ipset: set match: add support to match the counters")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
3 years agoipset: Update byte and packet counters regardless of whether they match
Stefano Brivio [Mon, 24 Feb 2020 17:52:43 +0000 (18:52 +0100)] 
ipset: Update byte and packet counters regardless of whether they match

In ip_set_match_extensions(), for sets with counters, we take care of
updating counters themselves by calling ip_set_update_counter(), and of
checking if the given comparison and values match, by calling
ip_set_match_counter() if needed.

However, if a given comparison on counters doesn't match the configured
values, that doesn't mean the set entry itself isn't matching.

This fix restores the behaviour we had before commit 4750005a85f7
("netfilter: ipset: Fix "don't update counters" mode when counters used
at the matching"), without reintroducing the issue fixed there: back
then, mtype_data_match() first updated counters in any case, and then
took care of matching on counters.

Now, if the IPSET_FLAG_SKIP_COUNTER_UPDATE flag is set,
ip_set_update_counter() will anyway skip counter updates if desired.

The issue observed is illustrated by this reproducer:

  ipset create c hash:ip counters
  ipset add c 192.0.2.1
  iptables -I INPUT -m set --match-set c src --bytes-gt 800 -j DROP

if we now send packets from 192.0.2.1, bytes and packets counters
for the entry as shown by 'ipset list' are always zero, and, no
matter how many bytes we send, the rule will never match, because
counters themselves are not updated.

Reported-by: Mithil Mhatre <mmhatre@redhat.com>
Fixes: 4750005a85f7 ("netfilter: ipset: Fix "don't update counters" mode when counters used at the matching")
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
3 years agonetfilter: ipset: Pass lockdep expression to RCU lists
Amol Grover [Sun, 16 Feb 2020 17:26:54 +0000 (22:56 +0530)] 
netfilter: ipset: Pass lockdep expression to RCU lists

ip_set_type_list is traversed using list_for_each_entry_rcu
outside an RCU read-side critical section but under the protection
of ip_set_type_mutex.

Hence, add corresponding lockdep expression to silence false-positive
warnings, and harden RCU lists.

Signed-off-by: Amol Grover <frextrite@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
3 years agoRevert "Introduce --update-counters-first flag for the set target"
Jozsef Kadlecsik [Sun, 20 Sep 2020 08:21:15 +0000 (10:21 +0200)] 
Revert "Introduce --update-counters-first flag for the set target"

This reverts commit c2dfb6432aea5bb0a3522901b0c44f42d8adbd49.

4 years agoip_set: Fix compatibility with kernels between v3.3 and v4.5
Serhey Popovych [Thu, 5 Mar 2020 15:28:24 +0000 (17:28 +0200)] 
ip_set: Fix compatibility with kernels between v3.3 and v4.5

These kernels does not have in their @struct netlink_dump_control method
that is used to prepare for netlink dump ->start(). This affects all
kernels that does not contain commit fc9e50f5a5a4 ("netlink: add a start
callback for starting a netlink dump").

Introduce fake value of HAVE_NETLINK_DUMP_START_ARGS equal to 7 that
never spot in the wild and set HAVE_NETLINK_DUMP_START_ARGS to 4 only
after explicit test if ->start() is available.

Fixes: 7725bf5ba041 ("netfilter: ipset: fix suspicious RCU usage in find_set_and_id")
Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoIntroduce --update-counters-first flag for the set target
Jozsef Kadlecsik [Mon, 9 Mar 2020 11:01:42 +0000 (12:01 +0100)] 
Introduce --update-counters-first flag for the set target

Stefano Brivio reported that the patch 'netfilter: ipset:
Fix "don't update counters" mode when counters used at the matching'
changed the semantic of when the counters are updated. Before the patch
the counters were updated regardless of the results of the counter
matches, after the patch the counters were updated only if the counter
match conditions (if specified) matched the packet. In order to handle
both ways, the --update-counters-first flag is introduced: when the flag
is specified, the counters are updated before checking the counter match
conditions. Without the flag the current evaluation path (i.e. update
only if counter conditions match) works.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoip_set: Fix build on kernels without INIT_DEFERRABLE_WORK
Serhey Popovych [Thu, 5 Mar 2020 15:28:23 +0000 (17:28 +0200)] 
ip_set: Fix build on kernels without INIT_DEFERRABLE_WORK

There was macro rename in kernel with commit 203b42f73174 ("workqueue:
make deferrable delayed_work initializer names consistent") that renames
INIT_DELAYED_WORK_DEFERRABLE() to INIT_DEFERRABLE_WORK().

Fixes: 33f08da28324 ("netfilter: ipset: Fix "INFO: rcu detected stall in hash_xxx" reports")
Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoipset: Support kernels with at least system_wq support
Jozsef Kadlecsik [Mon, 9 Mar 2020 10:54:08 +0000 (11:54 +0100)] 
ipset: Support kernels with at least system_wq support

4 years agoip_set: Fix build on kernels without system_power_efficient_wq
Serhey Popovych [Thu, 5 Mar 2020 15:28:22 +0000 (17:28 +0200)] 
ip_set: Fix build on kernels without system_power_efficient_wq

This type of workqueue according to comment in <linux/workqueue.h> is
same as regular @system_wq when power efficiency scheduler options
disabled.

For old kernels where @system_power_efficient_wq is not available use
regular @system_wq to support ipset on kernels below 3.11.

Fixes: 33f08da28324 ("netfilter: ipset: Fix "INFO: rcu detected stall in hash_xxx" reports")
Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoMerge branch 'region_lock'
Jozsef Kadlecsik [Sat, 22 Feb 2020 12:01:35 +0000 (13:01 +0100)] 
Merge branch 'region_lock'

4 years agoipset 7.6 released region_lock v7.6
Jozsef Kadlecsik [Sat, 22 Feb 2020 11:53:21 +0000 (12:53 +0100)] 
ipset 7.6 released

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoAdd checking system_power_efficient_wq in the kernel source tree
Jozsef Kadlecsik [Sat, 22 Feb 2020 11:51:24 +0000 (12:51 +0100)] 
Add checking system_power_efficient_wq in the kernel source tree

4 years agonetfilter: ipset: Fix forceadd evaluation path
Jozsef Kadlecsik [Sat, 22 Feb 2020 10:24:20 +0000 (11:24 +0100)] 
netfilter: ipset: Fix forceadd evaluation path

When the forceadd option is enabled, the hash:* types should find and replace
the first entry in the bucket with the new one if there are no reuseable
(deleted or timed out) entries. However, the position index was just not set
to zero and remained the invalid -1 if there were no reuseable entries.

Reported-by: syzbot+6a86565c74ebe30aea18@syzkaller.appspotmail.com
Fixes: 23c42a403a9c ("netfilter: ipset: Introduction of new commands and protocol version 7")
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agonetfilter: ipset: Correct the reported memory size
Jozsef Kadlecsik [Fri, 21 Feb 2020 20:53:11 +0000 (21:53 +0100)] 
netfilter: ipset: Correct the reported memory size

The patch

netfilter: ipset: Fix "INFO: rcu detected stall in hash_xxx" reports

did not include the size of the comment extensions from the memory size
for set listing. Add it, so the proper size is printed.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoip_set: Include kernel header instead of UAPI
Serhey Popovych [Fri, 31 Jan 2020 16:28:34 +0000 (18:28 +0200)] 
ip_set: Include kernel header instead of UAPI

This header is used to build kernel modules not userspace thus it is
correct to include linux/in.h kernel variant and not UAPI.

This fixes build on old and not widely supported systems like RHEL6 and
Debian GNU/Linux 7 (wheezy) before headers split to UAPI and kernel.

Fixes: 62d787ba5e66 ("netfilter: added missing includes to a number of header-files.")
Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agonetfilter: ipset: Fix "INFO: rcu detected stall in hash_xxx" reports
Jozsef Kadlecsik [Fri, 7 Feb 2020 19:41:32 +0000 (20:41 +0100)] 
netfilter: ipset: Fix "INFO: rcu detected stall in hash_xxx" reports

In the case of huge hash:* types of sets, due to the single spinlock of
a set the processing of the whole set under spinlock protection could take
too long.

There were four places where the whole hash table of the set was processed
from bucket to bucket under holding the spinlock:

- During resizing a set, the original set was locked to exclude kernel side
  add/del element operations (userspace add/del is excluded by the
  nfnetlink mutex). The original set is actually just read during the
  resize, so the spinlocking is replaced with rcu locking of regions.
  However, thus there can be parallel kernel side add/del of entries.
  In order not to loose those operations a backlog is added and replayed
  after the successful resize.
- Garbage collection of timed out entries was also protected by the spinlock.
  In order not to lock too long, region locking is introduced and a single
  region is processed in one gc go. Also, the simple timer based gc running
  is replaced with a workqueue based solution. The internal book-keeping
  (number of elements, size of extensions) is moved to region level due to
  the region locking.
- Adding elements: when the max number of the elements is reached, the gc
  was called to evict the timed out entries. The new approach is that the gc
  is called just for the matching region, assuming that if the region
  (proportionally) seems to be full, then the whole set does. We could scan
  the other regions to check every entry under rcu locking, but for huge
  sets it'd mean a slowdown at adding elements.
- Listing the set header data: when the set was defined with timeout
  support, the garbage collector was called to clean up timed out entries
  to get the correct element numbers and set size values. Now the set is
  scanned to check non-timed out entries, without actually calling the gc
  for the whole set.

Thanks to Florian Westphal for helping me to solve the SOFTIRQ-safe ->
SOFTIRQ-unsafe lock order issues during working on the patch.

Reported-by: syzbot+4b0e9d4ff3cf117837e5@syzkaller.appspotmail.com
Reported-by: syzbot+c27b8d5010f45c666ed1@syzkaller.appspotmail.com
Reported-by: syzbot+68a806795ac89df3aa1c@syzkaller.appspotmail.com
Fixes: 23c42a403a9c ("netfilter: ipset: Introduction of new commands and protocol version 7")
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoip_set: Include kernel header instead of UAPI
Serhey Popovych [Fri, 31 Jan 2020 16:28:34 +0000 (18:28 +0200)] 
ip_set: Include kernel header instead of UAPI

This header is used to build kernel modules not userspace thus it is
correct to include linux/in.h kernel variant and not UAPI.

This fixes build on old and not widely supported systems like RHEL6 and
Debian GNU/Linux 7 (wheezy) before headers split to UAPI and kernel.

Fixes: 62d787ba5e66 ("netfilter: added missing includes to a number of header-files.")
Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years ago.gitignore: add temporary files to the list
Jozsef Kadlecsik [Sun, 26 Jan 2020 11:00:50 +0000 (12:00 +0100)] 
.gitignore: add temporary files to the list

4 years agonetfilter: ipset: fix suspicious RCU usage in find_set_and_id
Jozsef Kadlecsik [Sat, 25 Jan 2020 17:55:06 +0000 (18:55 +0100)] 
netfilter: ipset: fix suspicious RCU usage in find_set_and_id

find_set_and_id() is called when the NFNL_SUBSYS_IPSET mutex is held.
However, in the error path there can be a follow-up recvmsg() without
the mutex held. Use the start() function of struct netlink_dump_control
instead of dump() to verify and report if the specified set does not
exist.

Thanks to Pablo Neira Ayuso for helping me to understand the subleties
of the netlink protocol.

Reported-by: syzbot+fc69d7cb21258ab4ae4d@syzkaller.appspotmail.com
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoAdd compatibility support for bitmap_zalloc() and bitmap_zero()
Jozsef Kadlecsik [Mon, 20 Jan 2020 18:59:43 +0000 (19:59 +0100)] 
Add compatibility support for bitmap_zalloc() and bitmap_zero()

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agonetfilter: ipset: use bitmap infrastructure completely
Jozsef Kadlecsik [Sun, 19 Jan 2020 11:04:13 +0000 (12:04 +0100)] 
netfilter: ipset: use bitmap infrastructure completely

The bitmap allocation did not use full unsigned long sizes
when calculating the required size and that was triggered by KASAN
as slab-out-of-bounds read in several places. The patch fixes all
of them.

Reported-by: syzbot+fabca5cbf5e54f3fe2de@syzkaller.appspotmail.com
Reported-by: syzbot+827ced406c9a1d9570ed@syzkaller.appspotmail.com
Reported-by: syzbot+190d63957b22ef673ea5@syzkaller.appspotmail.com
Reported-by: syzbot+dfccdb2bdb4a12ad425e@syzkaller.appspotmail.com
Reported-by: syzbot+df0d0f5895ef1f41a65b@syzkaller.appspotmail.com
Reported-by: syzbot+b08bd19bb37513357fd4@syzkaller.appspotmail.com
Reported-by: syzbot+53cdd0ec0bbabd53370a@syzkaller.appspotmail.com
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agonetfilter: fix a use-after-free in mtype_destroy()
Cong Wang [Fri, 10 Jan 2020 19:53:08 +0000 (11:53 -0800)] 
netfilter: fix a use-after-free in mtype_destroy()

map->members is freed by ip_set_free() right before using it in
mtype_ext_cleanup() again. So we just have to move it down.

Reported-by: syzbot+4c3cc6dbe7259dbf9054@syzkaller.appspotmail.com
Fixes: 40cd63bf33b2 ("netfilter: ipset: Support extensions which need a per data destroy function")
Cc: Pablo Neira Ayuso <pablo@netfilter.org>
Acked-by: Jozsef Kadlecsik <kadlec@netfilter.org>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoipset 7.5 released v7.5
Jozsef Kadlecsik [Thu, 9 Jan 2020 19:28:32 +0000 (20:28 +0100)] 
ipset 7.5 released

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agonetfilter: ipset: avoid null deref when IPSET_ATTR_LINENO is present
Florian Westphal [Wed, 8 Jan 2020 23:17:13 +0000 (00:17 +0100)] 
netfilter: ipset: avoid null deref when IPSET_ATTR_LINENO is present

The set uadt functions assume lineno is never NULL, but it is in
case of ip_set_utest().

syzkaller managed to generate a netlink message that calls this with
LINENO attr present:

general protection fault: 0000 [#1] PREEMPT SMP KASAN
RIP: 0010:hash_mac4_uadt+0x1bc/0x470 net/netfilter/ipset/ip_set_hash_mac.c:104
Call Trace:
 ip_set_utest+0x55b/0x890 net/netfilter/ipset/ip_set_core.c:1867
 nfnetlink_rcv_msg+0xcf2/0xfb0 net/netfilter/nfnetlink.c:229
 netlink_rcv_skb+0x177/0x450 net/netlink/af_netlink.c:2477
 nfnetlink_rcv+0x1ba/0x460 net/netfilter/nfnetlink.c:563

pass a dummy lineno storage, its easier than patching all set
implementations.

This seems to be a day-0 bug.

Cc: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Reported-by: syzbot+34bd2369d38707f3f4a7@syzkaller.appspotmail.com
Fixes: a7b4f989a6294 ("netfilter: ipset: IP set core support")
Signed-off-by: Florian Westphal <fw@strlen.de>
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>
4 years agoip_set: Pass init_net when @net is missing in match check params data structure
Serhey Popovych [Fri, 29 Nov 2019 09:21:34 +0000 (11:21 +0200)] 
ip_set: Pass init_net when @net is missing in match check params data structure

It is better to restrict ipsets to default network namespace on old
kernels that does not contain @net parameter in @struct xt_mtchk_param
(i.e. ones prior to commit a83d8e8d099f ("netfilter: xtables:
add struct xt_mtchk_param::net"), tag v2.6.34) instead of panicing
on them.

Found and tested on RHEL 6 with 2.6.32 kernels.

Fixes: 90e279db0cf5 ("Add more compatibility checkings to support older kernel releases")
Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agonetfilter: xt_set: Do not restrict --map-set to the mangle table
Serhey Popovych [Fri, 29 Nov 2019 09:21:33 +0000 (11:21 +0200)] 
netfilter: xt_set: Do not restrict --map-set to the mangle table

While mangle table is primary place for packet modification setting
mark, traffic class priority or hardware NIC queue can be done in any
table with exception similar to using mark in policy-based routing
setups (configured with ip-rule(8)) should be done before routing
happens (i.e. in PREROUTING chain that usable in mangle or raw tables
only).

There is no such restriction in MARK target used to set packet mark and
CLASSIFY target used to set traffic class priority. Both are free to use
in any table. There is no known target that can modify hardware queue
for packet.

This helps in keeping filtering and packet modification rules together
in filter table.

Tested with rule in filter table with SET target using --map-prio and
HTB for scheduling packets at egress.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoem_ipset: Build on old kernels
Serhey Popovych [Fri, 29 Nov 2019 09:21:32 +0000 (11:21 +0200)] 
em_ipset: Build on old kernels

Make sure TCF_EM_IPSET defined and corresponds to current upstream value
if not defined in target kernel. You need iproute2 version that supports
em_ipset to communicate correctly. Include ip_set_compat.h after
pkt_cls.h to prevent TCF_EM_IPSET redefine error.

Detect skb->iif => skb->skb_iif rename after commit 8964be4a9a5c ("net:
rename skb->iif to skb->skb_iif").

Add dev_get_by_index_rcu() define pointing to __dev_get_by_index() to
build on RHEL6 kernels with explicit note that this may not work on all
architectures.

Always build em_ipset regardless of CONFIG_NET_EMATCH_IPSET option.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agocompat: Use skb_vlan_tag_present() instead of vlan_tx_tag_present()
Serhey Popovych [Fri, 29 Nov 2019 09:21:31 +0000 (11:21 +0200)] 
compat: Use skb_vlan_tag_present() instead of vlan_tx_tag_present()

Since RHEL6 provides it as preprocessor define and does not provide
vlan_tx_tag_present(). Add defines in case of vlan_tx_tag_present()
isn't available to back tc_skb_protocol() to old behaviour before
commit d8b9605d2697 ("net: sched: fix skb->protocol use in case
of accelerated vlan path").

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoconfigure.ac: Support building with old autoconf 2.63
Serhey Popovych [Fri, 29 Nov 2019 09:21:30 +0000 (11:21 +0200)] 
configure.ac: Support building with old autoconf 2.63

This version found on RHEL6 making autoreconf fail with following error:

  configure.ac:61: error: possibly undefined macro: AS_VAR_COPY
  If this token and others are legitimate, please use m4_pattern_allow.
  See the Autoconf documentation.

Apply fix from https://github.com/gdnsd/gdnsd/issues/85 to fix problem.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoconfigure.ac: Build on kernels without skb->vlan_proto correctly
Serhey Popovych [Fri, 29 Nov 2019 09:21:29 +0000 (11:21 +0200)] 
configure.ac: Build on kernels without skb->vlan_proto correctly

Support for EtherType other than ETH_P_8021Q for VLAN header introduced
with commit 86a9bad3ab6b ("net: vlan: add protocol argument to packet
tagging functions") in upstream kernel since v3.10.

To support build on older kernels check for ->vlan_proto presence in
@struct sk_buff and return htons(ETH_P_8021Q) when it is missing.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoconfigure.ac: Add cond_resched_rcu() checks
Serhey Popovych [Fri, 29 Nov 2019 09:21:28 +0000 (11:21 +0200)] 
configure.ac: Add cond_resched_rcu() checks

It was introduced with commit f6f3c437d09e ("sched: add cond_resched_rcu()
helper") since v3.11 upstream kernel.

To support building on older kernels add implementation to ip_set_compat.h.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoconfigure.ac: Better match for ipv6_skip_exthdr() frag_offp arg presence
Serhey Popovych [Fri, 29 Nov 2019 09:21:27 +0000 (11:21 +0200)] 
configure.ac: Better match for ipv6_skip_exthdr() frag_offp arg presence

On older kernels (i.e. ones before commit 5c3a0fd7d0fc ("ip*.h: Remove
extern from function prototypes") in upstream since v3.13) we fail to
match number of arguments ipv6_skip_exthdr() correctly. Configure
chooses 3 args, while function has actually 4 args.

This happens because on these kernels tab (\t) is used for intendation
between function result type and function name.

Fix by matching either space for kernels with mentioned change or tab
for older kernels to select number of arguments correctly.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoDocument explicitly that protocol is not stored in bitmap:port
Jozsef Kadlecsik [Thu, 14 Nov 2019 13:29:03 +0000 (14:29 +0100)] 
Document explicitly that protocol is not stored in bitmap:port

4 years agoipset 7.4 released v7.4
Jozsef Kadlecsik [Fri, 1 Nov 2019 15:13:11 +0000 (16:13 +0100)] 
ipset 7.4 released

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoFix compatibility support for netlink extended ACK and add synchronize_rcu_bh() checking
Jozsef Kadlecsik [Fri, 1 Nov 2019 14:40:33 +0000 (15:40 +0100)] 
Fix compatibility support for netlink extended ACK and add synchronize_rcu_bh() checking

4 years agoFix nla_policies to fully support NL_VALIDATE_STRICT
Jozsef Kadlecsik [Fri, 1 Nov 2019 14:36:44 +0000 (15:36 +0100)] 
Fix nla_policies to fully support NL_VALIDATE_STRICT

Since v5.2 (commit "netlink: re-add parse/validate functions in
strict mode") NL_VALIDATE_STRICT is enabled. Fix the ipset nla_policies
which did not support strict mode and thus the corresponding ipset
commands failed.

4 years agotreewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500
Thomas Gleixner [Thu, 31 Oct 2019 17:57:52 +0000 (18:57 +0100)] 
treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500

Based on 2 normalized pattern(s):

  this program is free software you can redistribute it and or modify
  it under the terms of the gnu general public license version 2 as
  published by the free software foundation

  this program is free software you can redistribute it and or modify
  it under the terms of the gnu general public license version 2 as
  published by the free software foundation #

extracted by the scancode license scanner the SPDX license identifier

  GPL-2.0-only

has been chosen to replace the boilerplate/reference in 4122 file(s).

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Enrico Weigelt <info@metux.net>
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Allison Randal <allison@lohutok.net>
Cc: linux-spdx@vger.kernel.org
Link: https://lkml.kernel.org/r/20190604081206.933168790@linutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
4 years agonetfilter: remove unnecessary spaces
yangxingwu [Tue, 16 Jul 2019 02:13:01 +0000 (10:13 +0800)] 
netfilter: remove unnecessary spaces

This patch removes extra spaces.

Signed-off-by: yangxingwu <xingwu.yang@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoipset: Add wildcard support to net,iface
Kristian Evensen [Thu, 26 Sep 2019 10:06:45 +0000 (12:06 +0200)] 
ipset: Add wildcard support to net,iface

The net,iface equal functions currently compares the full interface
names. In several cases, wildcard (or prefix) matching is useful. For
example, when converting a large iptables rule-set to make use of ipset,
I was able to significantly reduce the number of set elements by making
use of wildcard matching.

Wildcard matching is enabled by adding "wildcard" when adding an element
to a set. Internally, this causes the IPSET_FLAG_IFACE_WILDCARD-flag to
be set.  When this flag is set, only the initial part of the interface
name is used for comparison.

Wildcard matching is done per element and not per set, as there are many
cases where mixing wildcard and non-wildcard elements are useful. This
means that is up to the user to handle (avoid) overlapping interface
names.

Signed-off-by: Kristian Evensen <kristian.evensen@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoSort naturally instead of textual sort (bugzilla #1369)
Jozsef Kadlecsik [Thu, 31 Oct 2019 13:18:48 +0000 (14:18 +0100)] 
Sort naturally instead of textual sort (bugzilla #1369)

Sort 95.0.0.0 before 107.0.0.0 instead of the textual sorting.
Also, in the case of subnets, sort reversed, ie. most specific first.

4 years agoipset: Copy the right MAC address in hash:ip,mac IPv6 sets
Stefano Brivio [Thu, 10 Oct 2019 17:18:14 +0000 (19:18 +0200)] 
ipset: Copy the right MAC address in hash:ip,mac IPv6 sets

Same as commit 1b4a75108d5b ("netfilter: ipset: Copy the right MAC
address in bitmap:ip,mac and hash:ip,mac sets"), another copy and paste
went wrong in commit 8cc4ccf58379 ("netfilter: ipset: Allow matching on
destination MAC address for mac and ipmac sets").

When I fixed this for IPv4 in 1b4a75108d5b, I didn't realise that
hash:ip,mac sets also support IPv6 as family, and this is covered by a
separate function, hash_ipmac6_kadt().

In hash:ip,mac sets, the first dimension is the IP address, and the
second dimension is the MAC address: check the IPSET_DIM_TWO_SRC flag
in flags while deciding which MAC address to copy, destination or
source.

This way, mixing source and destination matches for the two dimensions
of ip,mac hash type works as expected, also for IPv6. With this setup:

  ip netns add A
  ip link add veth1 type veth peer name veth2 netns A
  ip addr add 2001:db8::1/64 dev veth1
  ip -net A addr add 2001:db8::2/64 dev veth2
  ip link set veth1 up
  ip -net A link set veth2 up

  dst=$(ip netns exec A cat /sys/class/net/veth2/address)

  ip netns exec A ipset create test_hash hash:ip,mac family inet6
  ip netns exec A ipset add test_hash 2001:db8::1,${dst}
  ip netns exec A ip6tables -A INPUT -p icmpv6 --icmpv6-type 135 -j ACCEPT
  ip netns exec A ip6tables -A INPUT -m set ! --match-set test_hash src,dst -j DROP

ipset now correctly matches a test packet:

  # ping -c1 2001:db8::2 >/dev/null
  # echo $?
  0

Reported-by: Chen, Yi <yiche@redhat.com>
Fixes: 8cc4ccf58379 ("netfilter: ipset: Allow matching on destination MAC address for mac and ipmac sets")
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoDo not return with error at 'make modules_install' when modules are not loaded
Jozsef Kadlecsik [Thu, 31 Oct 2019 11:12:31 +0000 (12:12 +0100)] 
Do not return with error at 'make modules_install' when modules are not loaded

The issue was reported by Oskar Berggren.

4 years agonetfilter: ipset: move ip_set_get_ip_port() to ip_set_bitmap_port.c.
Jeremy Sowden [Thu, 3 Oct 2019 19:56:07 +0000 (20:56 +0100)] 
netfilter: ipset: move ip_set_get_ip_port() to ip_set_bitmap_port.c.

ip_set_get_ip_port() is only used in ip_set_bitmap_port.c.  Move it
there and make it static.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agonetfilter: ipset: move function to ip_set_bitmap_ip.c.
Jeremy Sowden [Thu, 3 Oct 2019 19:56:06 +0000 (20:56 +0100)] 
netfilter: ipset: move function to ip_set_bitmap_ip.c.

One inline function in ip_set_bitmap.h is only called in
ip_set_bitmap_ip.c: move it and remove inline function specifier.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agonetfilter: ipset: make ip_set_put_flags extern.
Jeremy Sowden [Thu, 3 Oct 2019 19:56:05 +0000 (20:56 +0100)] 
netfilter: ipset: make ip_set_put_flags extern.

ip_set_put_flags is rather large for a static inline function in a
header-file.  Move it to ip_set_core.c and export it.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agonetfilter: ipset: move functions to ip_set_core.c.
Jeremy Sowden [Mon, 7 Oct 2019 19:46:41 +0000 (21:46 +0200)] 
netfilter: ipset: move functions to ip_set_core.c.

Several inline functions in ip_set.h are only called in ip_set_core.c:
move them and remove inline function specifier.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agonetfilter: ipset: move ip_set_comment functions from ip_set.h to ip_set_core.c.
Jeremy Sowden [Thu, 3 Oct 2019 19:56:03 +0000 (20:56 +0100)] 
netfilter: ipset: move ip_set_comment functions from ip_set.h to ip_set_core.c.

Most of the functions are only called from within ip_set_core.c.

The exception is ip_set_init_comment.  However, this is too complex to
be a good candidate for a static inline function.  Move it to
ip_set_core.c, change its linkage to extern and export it, leaving a
declaration in ip_set.h.

ip_set_comment_free is only used as an extension destructor, so change
its prototype to match and drop cast.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agonetfilter: ipset: remove inline from static functions in .c files.
Jeremy Sowden [Thu, 3 Oct 2019 19:56:02 +0000 (20:56 +0100)] 
netfilter: ipset: remove inline from static functions in .c files.

The inline function-specifier should not be used for static functions
defined in .c files since it bloats the kernel.  Instead leave the
compiler to decide which functions to inline.

While a couple of the files affected (ip_set_*_gen.h) are technically
headers, they contain templates for generating the common parts of
particular set-types and so we treat them like .c files.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agonetfilter: ipset: add a coding-style fix to ip_set_ext_destroy.
Jeremy Sowden [Thu, 3 Oct 2019 19:56:01 +0000 (20:56 +0100)] 
netfilter: ipset: add a coding-style fix to ip_set_ext_destroy.

Use a local variable to hold comment in order to align the arguments of
ip_set_comment_free properly.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agonetfilter: added missing includes to a number of header-files.
Jeremy Sowden [Wed, 7 Aug 2019 14:16:59 +0000 (15:16 +0100)] 
netfilter: added missing includes to a number of header-files.

A number of netfilter header-files used declarations and definitions
from other headers without including them.  Added include directives to
make those declarations and definitions available.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agonetfilter: inlined four headers files into another one.
Jeremy Sowden [Mon, 7 Oct 2019 19:08:42 +0000 (21:08 +0200)] 
netfilter: inlined four headers files into another one.

linux/netfilter/ipset/ip_set.h included four other header files:

  include/linux/netfilter/ipset/ip_set_comment.h
  include/linux/netfilter/ipset/ip_set_counter.h
  include/linux/netfilter/ipset/ip_set_skbinfo.h
  include/linux/netfilter/ipset/ip_set_timeout.h

Of these the first three were not included anywhere else.  The last,
ip_set_timeout.h, was included in a couple of other places, but defined
inline functions which call other inline functions defined in ip_set.h,
so ip_set.h had to be included before it.

Inlined all four into ip_set.h, and updated the other files that
included ip_set_timeout.h.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agonetfilter: ipset: Fix an error code in ip_set_sockfn_get()
Dan Carpenter [Sat, 24 Aug 2019 14:49:55 +0000 (17:49 +0300)] 
netfilter: ipset: Fix an error code in ip_set_sockfn_get()

The copy_to_user() function returns the number of bytes remaining to be
copied.  In this code, that positive return is checked at the end of the
function and we return zero/success.  What we should do instead is
return -EFAULT.

Fixes: a7b4f989a629 ("netfilter: ipset: IP set core support")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoipset 7.3 released v7.3
Jozsef Kadlecsik [Tue, 23 Jul 2019 08:34:26 +0000 (10:34 +0200)] 
ipset 7.3 released

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoFix rename concurrency with listing
Jozsef Kadlecsik [Tue, 23 Jul 2019 08:25:55 +0000 (10:25 +0200)] 
Fix rename concurrency with listing

Shijie Luo reported that when stress-testing ipset with multiple concurrent
create, rename, flush, list, destroy commands, it can result

ipset <version>: Broken LIST kernel message: missing DATA part!

error messages and broken list results. The problem was the rename operation
was not properly handled with respect of listing. The patch fixes the issue.

Reported-by: Shijie Luo <luoshijie1@huawei.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoipset: Copy the right MAC address in bitmap:ip,mac and hash:ip,mac sets
Stefano Brivio [Mon, 24 Jun 2019 13:20:12 +0000 (15:20 +0200)] 
ipset: Copy the right MAC address in bitmap:ip,mac and hash:ip,mac sets

In commit 8cc4ccf58379 ("ipset: Allow matching on destination MAC address
for mac and ipmac sets"), ipset.git commit 1543514c46a7, I added to the
KADT functions for sets matching on MAC addreses the copy of source or
destination MAC address depending on the configured match.

This was done correctly for hash:mac, but for hash:ip,mac and
bitmap:ip,mac, copying and pasting the same code block presents an
obvious problem: in these two set types, the MAC address is the second
dimension, not the first one, and we are actually selecting the MAC
address depending on whether the first dimension (IP address) specifies
source or destination.

Fix this by checking for the IPSET_DIM_TWO_SRC flag in option flags.

This way, mixing source and destination matches for the two dimensions
of ip,mac set types works as expected. With this setup:

  ip netns add A
  ip link add veth1 type veth peer name veth2 netns A
  ip addr add 192.0.2.1/24 dev veth1
  ip -net A addr add 192.0.2.2/24 dev veth2
  ip link set veth1 up
  ip -net A link set veth2 up

  dst=$(ip netns exec A cat /sys/class/net/veth2/address)

  ip netns exec A ipset create test_bitmap bitmap:ip,mac range 192.0.0.0/16
  ip netns exec A ipset add test_bitmap 192.0.2.1,${dst}
  ip netns exec A iptables -A INPUT -m set ! --match-set test_bitmap src,dst -j DROP

  ip netns exec A ipset create test_hash hash:ip,mac
  ip netns exec A ipset add test_hash 192.0.2.1,${dst}
  ip netns exec A iptables -A INPUT -m set ! --match-set test_hash src,dst -j DROP

ipset correctly matches a test packet:

  # ping -c1 192.0.2.2 >/dev/null
  # echo $?
  0

Reported-by: Chen Yi <yiche@redhat.com>
Fixes: 8cc4ccf58379 ("ipset: Allow matching on destination MAC address for mac and ipmac sets")
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoipset: Actually allow destination MAC address for hash:ip,mac sets too
Stefano Brivio [Mon, 24 Jun 2019 13:20:11 +0000 (15:20 +0200)] 
ipset: Actually allow destination MAC address for hash:ip,mac sets too

In commit 8cc4ccf58379 ("ipset: Allow matching on destination MAC address
for mac and ipmac sets"), ipset.git commit 1543514c46a7, I removed the
KADT check that prevents matching on destination MAC addresses for
hash:mac sets, but forgot to remove the same check for hash:ip,mac set.

Drop this check: functionality is now commented in man pages and there's
no reason to restrict to source MAC address matching anymore.

Reported-by: Chen Yi <yiche@redhat.com>
Fixes: 8cc4ccf58379 ("ipset: Allow matching on destination MAC address for mac and ipmac sets")
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoipset: fix spelling error in libipset.3 manpage
Neutron Soutmun [Fri, 28 Jun 2019 19:05:22 +0000 (21:05 +0200)] 
ipset: fix spelling error in libipset.3 manpage

Fix these spelling errors,
    s/lenght/length/
    s/controll/control/
    s/funtion/function/

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoExplicitly comment that we need ipset_nest_start(),
Jozsef Kadlecsik [Mon, 10 Jun 2019 11:12:34 +0000 (13:12 +0200)] 
Explicitly comment that we need ipset_nest_start(),
ipset_nest_end() in the package source.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
4 years agoipset 7.2 released
Jozsef Kadlecsik [Mon, 10 Jun 2019 10:10:11 +0000 (12:10 +0200)] 
ipset 7.2 released

4 years agoipset: update my email address
Jozsef Kadlecsik [Tue, 4 Jun 2019 18:47:34 +0000 (20:47 +0200)] 
ipset: update my email address

It's better to use my kadlec@netfilter.org email address in
the source code. I might not be able to use
kadlec@blackhole.kfki.hu in the future.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
4 years agoipset: Fix memory accounting for hash types on resize
Stefano Brivio [Sun, 26 May 2019 21:14:06 +0000 (23:14 +0200)] 
ipset: Fix memory accounting for hash types on resize

If a fresh array block is allocated during resize, the current in-memory
set size should be increased by the size of the block, not replaced by it.

Before the fix, adding entries to a hash set type, leading to a table
resize, caused an inconsistent memory size to be reported. This becomes
more obvious when swapping sets with similar sizes:

  # cat hash_ip_size.sh
  #!/bin/sh
  FAIL_RETRIES=10

  tries=0
  while [ ${tries} -lt ${FAIL_RETRIES} ]; do
   ipset create t1 hash:ip
   for i in `seq 1 4345`; do
   ipset add t1 1.2.$((i / 255)).$((i % 255))
   done
   t1_init="$(ipset list t1|sed -n 's/Size in memory: \(.*\)/\1/p')"

   ipset create t2 hash:ip
   for i in `seq 1 4360`; do
   ipset add t2 1.2.$((i / 255)).$((i % 255))
   done
   t2_init="$(ipset list t2|sed -n 's/Size in memory: \(.*\)/\1/p')"

   ipset swap t1 t2
   t1_swap="$(ipset list t1|sed -n 's/Size in memory: \(.*\)/\1/p')"
   t2_swap="$(ipset list t2|sed -n 's/Size in memory: \(.*\)/\1/p')"

   ipset destroy t1
   ipset destroy t2
   tries=$((tries + 1))

   if [ ${t1_init} -lt 10000 ] || [ ${t2_init} -lt 10000 ]; then
   echo "FAIL after ${tries} tries:"
   echo "T1 size ${t1_init}, after swap ${t1_swap}"
   echo "T2 size ${t2_init}, after swap ${t2_swap}"
   exit 1
   fi
  done
  echo "PASS"
  # echo -n 'func hash_ip4_resize +p' > /sys/kernel/debug/dynamic_debug/control
  # ./hash_ip_size.sh
  [ 2035.018673] attempt to resize set t1 from 10 to 11, t 00000000fe6551fa
  [ 2035.078583] set t1 resized from 10 (00000000fe6551fa) to 11 (00000000172a0163)
  [ 2035.080353] Table destroy by resize 00000000fe6551fa
  FAIL after 4 tries:
  T1 size 9064, after swap 71128
  T2 size 71128, after swap 9064

Reported-by: NOYB <JunkYardMail1@Frontier.com>
Fixes: 9e41f26a505c ("netfilter: ipset: Count non-static extension memory for userspace")
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
5 years agoFix error path in set_target_v3_checkentry()
Jozsef Kadlecsik [Fri, 18 Jan 2019 17:16:55 +0000 (18:16 +0100)] 
Fix error path in set_target_v3_checkentry()

Fix error path and release the references properly.

5 years agoFix the last missing check of nla_parse()
Jozsef Kadlecsik [Thu, 10 Jan 2019 20:00:16 +0000 (21:00 +0100)] 
Fix the last missing check of nla_parse()

In dump_init() the outdated comment was incorrect and we had a missing
validation check of nla_parse().

5 years agonetfilter: ipset: fix a missing check of nla_parse
Aditya Pakki [Tue, 8 Jan 2019 20:00:33 +0000 (21:00 +0100)] 
netfilter: ipset: fix a missing check of nla_parse

When nla_parse fails, we should not use the results (the first
argument). The fix checks if it fails, and if so, returns its error code
upstream.

Signed-off-by: Aditya Pakki <pakki001@umn.edu>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
5 years agonetfilter: ipset: merge uadd and udel functions
Florent Fourcot [Tue, 8 Jan 2019 19:55:55 +0000 (20:55 +0100)] 
netfilter: ipset: merge uadd and udel functions

Both functions are using exactly the same code, except the command value
passed to call_ad function.

Signed-off-by: Florent Fourcot <florent.fourcot@wifirst.fr>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
5 years agonetfilter: ipset: remove useless memset() calls
Florent Fourcot [Tue, 8 Jan 2019 19:37:33 +0000 (20:37 +0100)] 
netfilter: ipset: remove useless memset() calls

One of the memset call is buggy: it does not erase full array, but only
pointer size.
Moreover, after a check, first step of nla_parse_nested/nla_parse is to
erase tb array as well. We can remove both calls safely.

Signed-off-by: Florent Fourcot <florent.fourcot@wifirst.fr>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
5 years agoipset 7.1 released v7.1
Jozsef Kadlecsik [Mon, 10 Dec 2018 17:35:31 +0000 (18:35 +0100)] 
ipset 7.1 released

5 years agoAdd compatibility support for strscpy()
Jozsef Kadlecsik [Mon, 10 Dec 2018 17:29:48 +0000 (18:29 +0100)] 
Add compatibility support for strscpy()

5 years agonetfilter/ipset: replace a strncpy() with strscpy()
Qian Cai [Sun, 2 Dec 2018 04:06:01 +0000 (23:06 -0500)] 
netfilter/ipset: replace a strncpy() with strscpy()

To make overflows as obvious as possible and to prevent code from blithely
proceeding with a truncated string. This also has a side-effect to fix a
compilation warning when using GCC 8.2.1.

net/netfilter/ipset/ip_set_core.c: In function 'ip_set_sockfn_get':
net/netfilter/ipset/ip_set_core.c:2027:3: warning: 'strncpy' writing 32
bytes into a region of size 2 overflows the destination
[-Wstringop-overflow=]

Signed-off-by: Qian Cai <cai@gmx.us>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
5 years agoCorrect the manpage about the sort option, supported since 3713072d
Jozsef Kadlecsik [Fri, 30 Nov 2018 20:43:51 +0000 (21:43 +0100)] 
Correct the manpage about the sort option, supported since 3713072d

5 years agoAdd missing functions to libipset.map
Jozsef Kadlecsik [Wed, 28 Nov 2018 17:45:50 +0000 (18:45 +0100)] 
Add missing functions to libipset.map

Some new functions was not added to libipset.map at the previous
release, fix it.

5 years agonetfilter: ipset: fix ip_set_byindex function
Florent Fourcot [Tue, 27 Nov 2018 16:15:56 +0000 (17:15 +0100)] 
netfilter: ipset: fix ip_set_byindex function

New function added by "Introduction of new commands and protocol
version 7" is not working, since we return skb2 to user

Signed-off-by: Victorien Molle <victorien.molle@wifirst.fr>
Signed-off-by: Florent Fourcot <florent.fourcot@wifirst.fr>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
5 years agonetfilter: ipset: do not call ipset_nest_end after nla_nest_cancel
Pan Bian [Mon, 26 Nov 2018 10:42:10 +0000 (18:42 +0800)] 
netfilter: ipset: do not call ipset_nest_end after nla_nest_cancel

In the error handling block, nla_nest_cancel(skb, atd) is called to
cancel the nest operation. But then, ipset_nest_end(skb, atd) is
unexpected called to end the nest operation. This patch calls the
ipset_nest_end only on the branch that nla_nest_cancel is
not called.

Fixes: 45040978c89("netfilter: ipset: Fix set:list type crash when
flush/dump set in parallel")

Signed-off-by: Pan Bian <bianpan2016@163.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
5 years agoconfigure.ac: Fix build regression on RHEL/CentOS/SL
Serhey Popovych [Sun, 18 Nov 2018 19:08:23 +0000 (21:08 +0200)] 
configure.ac: Fix build regression on RHEL/CentOS/SL

This was introduced with commit 0f82228387ae ("Use more robust awk
patterns to check for backward compatibility") on RHEL 7.3+ because
it's kernel contains backported upstream commit 633c9a840d0b
("netfilter: nfnetlink: avoid recurrent netns lookups in call_batch")
that introduces @net of @struct net type parameter matched with $GREP
after $AWK returns whole @struct nfnl_callback.

This causes incorrect IPSET_CBFN() prototype choose for ->call()
of @struct nfnl_callback producing following warnings during the build:

  .../ipset/ip_set_core.c:2007:3: warning: initialization from
  incompatible pointer type [enabled by default]
     .call  = ip_set_destroy,
     ^
  ../ipset/ip_set_core.c:2007:3: warning: (near initialization
  for ‘ip_set_netlink_subsys_cb[3].call’) [enabled by default]

Fix by matching pattern to the end of first function pointer in
@struct nfnl_callback instead of end of struct.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
5 years agoImplement sorting for hash types in the ipset tool
Jozsef Kadlecsik [Mon, 26 Nov 2018 09:54:36 +0000 (10:54 +0100)] 
Implement sorting for hash types in the ipset tool

Support listing/saving with sorted entries for the hash types.
(bitmap and list types are automatically sorted.)

5 years agoFix to list/save into file specified by option
Jozsef Kadlecsik [Sat, 10 Nov 2018 16:34:57 +0000 (17:34 +0100)] 
Fix to list/save into file specified by option

list/save into file given by "-f filename" did not work in 7.0,
reported by Isaac Good.

5 years agoCorrect workaround in patch "Fix calling ip_set() macro at dumping"
Jozsef Kadlecsik [Tue, 30 Oct 2018 21:30:30 +0000 (22:30 +0100)] 
Correct workaround in patch "Fix calling ip_set() macro at dumping"

As Pablo pointed out, in order to fix the bogus warnings, there's
no need for the non-useful rcu_read_lock/unlock dancing. Call
rcu_dereference_raw() instead, the ref_netlink protects the set.

5 years agoipset 7.0 released v7.0
Jozsef Kadlecsik [Sat, 27 Oct 2018 16:09:10 +0000 (18:09 +0200)] 
ipset 7.0 released

5 years agoIntroduction of new commands and protocol version 7
Jozsef Kadlecsik [Mon, 22 Oct 2018 20:25:09 +0000 (22:25 +0200)] 
Introduction of new commands and protocol version 7

Two new commands (IPSET_CMD_GET_BYNAME, IPSET_CMD_GET_BYINDEX) are
introduced. The new commands makes possible to eliminate the getsockopt
operation (in iptables set/SET match/target) and thus use only netlink
communication between userspace and kernel for ipset. With the new
protocol version, userspace can exactly know which functionality is
supported by the running kernel.

Both the kernel and userspace is fully backward compatible.

5 years agoLicense cleanup: add SPDX license identifier to uapi header files with no license
Greg Kroah-Hartman [Mon, 22 Oct 2018 19:01:58 +0000 (21:01 +0200)] 
License cleanup: add SPDX license identifier to uapi header files with no license

Many user space API headers are missing licensing information, which
makes it hard for compliance tools to determine the correct license.

By default are files without license information under the default
license of the kernel, which is GPLV2.  Marking them GPLV2 would exclude
them from being included in non GPLV2 code, which is obviously not
intended. The user space API headers fall under the syscall exception
which is in the kernels COPYING file:

   NOTE! This copyright does *not* cover user programs that use kernel
   services by normal system calls - this is merely considered normal use
   of the kernel, and does *not* fall under the heading of "derived work".

otherwise syscall usage would not be possible.

Update the files which contain no license information with an SPDX
license identifier.  The chosen identifier is 'GPL-2.0 WITH
Linux-syscall-note' which is the officially assigned identifier for the
Linux syscall exception.  SPDX license identifiers are a legally binding
shorthand, which can be used instead of the full boiler plate text.

This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.  See the previous patch in this series for the
methodology of how this patch was researched.

Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>