Commit Graph

1800 Commits

Author SHA1 Message Date
CKI Backport Bot 1e51ea6e75 netfilter: fib: check correct rtable in vrf setups
JIRA: https://issues.redhat.com/browse/RHEL-73708

commit 05ef7055debc804e8083737402127975e7244fc4
Author: Florian Westphal <fw@strlen.de>
Date:   Wed Oct 9 09:19:02 2024 +0200

    netfilter: fib: check correct rtable in vrf setups

    We need to init l3mdev unconditionally, else main routing table is searched
    and incorrect result is returned unless strict (iif keyword) matching is
    requested.

    Next patch adds a selftest for this.

    Fixes: 2a8a7c0eaa87 ("netfilter: nft_fib: Fix for rpath check with VRF devices")
    Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1761
    Signed-off-by: Florian Westphal <fw@strlen.de>
    Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

Signed-off-by: CKI Backport Bot <cki-ci-bot+cki-gitlab-backport-bot@redhat.com>
2025-01-13 15:04:38 +00:00
CKI Backport Bot 9b155e3c63 netfilter: nf_reject: Fix build warning when CONFIG_BRIDGE_NETFILTER=n
JIRA: https://issues.redhat.com/browse/RHEL-66865
CVE: CVE-2024-50256

commit fc56878ca1c288e49b5cbb43860a5938e3463654
Author: Simon Horman <horms@kernel.org>
Date:   Mon Sep 16 10:50:34 2024 +0100

    netfilter: nf_reject: Fix build warning when CONFIG_BRIDGE_NETFILTER=n

    If CONFIG_BRIDGE_NETFILTER is not enabled, which is the case for x86_64
    defconfig, then building nf_reject_ipv4.c and nf_reject_ipv6.c with W=1
    using gcc-14 results in the following warnings, which are treated as
    errors:

    net/ipv4/netfilter/nf_reject_ipv4.c: In function 'nf_send_reset':
    net/ipv4/netfilter/nf_reject_ipv4.c:243:23: error: variable 'niph' set but not used [-Werror=unused-but-set-variable]
      243 |         struct iphdr *niph;
          |                       ^~~~
    cc1: all warnings being treated as errors
    net/ipv6/netfilter/nf_reject_ipv6.c: In function 'nf_send_reset6':
    net/ipv6/netfilter/nf_reject_ipv6.c:286:25: error: variable 'ip6h' set but not used [-Werror=unused-but-set-variable]
      286 |         struct ipv6hdr *ip6h;
          |                         ^~~~
    cc1: all warnings being treated as errors

    Address this by reducing the scope of these local variables to where
    they are used, which is code only compiled when CONFIG_BRIDGE_NETFILTER
    enabled.

    Compile tested and run through netfilter selftests.

    Reported-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
    Closes: https://lore.kernel.org/netfilter-devel/20240906145513.567781-1-andriy.shevchenko@linux.intel.com/
    Signed-off-by: Simon Horman <horms@kernel.org>
    Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

Signed-off-by: CKI Backport Bot <cki-ci-bot+cki-gitlab-backport-bot@redhat.com>
2024-11-29 12:42:21 +08:00
Rado Vrbovsky fab2ecdb92 Merge: [9.6 P1] netfilter: stable backport from upstream
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/5304

JIRA: https://issues.redhat.com/browse/RHEL-60554

Signed-off-by: Florian Westphal <fwestpha@redhat.com>

Approved-by: Phil Sutter <psutter@redhat.com>
Approved-by: Antoine Tenart <atenart@redhat.com>
Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com>

Merged-by: Rado Vrbovsky <rvrbovsk@redhat.com>
2024-10-20 09:03:23 +00:00
Florian Westphal 8e207d3cc1 netfilter: nf_tables: prevent nf_skb_duplicated corruption
JIRA: https://issues.redhat.com/browse/RHEL-60554
Upstream Status: commit 92ceba94de6f

commit 92ceba94de6fb4cee2bf40b485979c342f44a492
Author: Eric Dumazet <edumazet@google.com>
Date:   Thu Sep 26 18:56:11 2024 +0000

    netfilter: nf_tables: prevent nf_skb_duplicated corruption

    syzbot found that nf_dup_ipv4() or nf_dup_ipv6() could write
    per-cpu variable nf_skb_duplicated in an unsafe way [1].

    Disabling preemption as hinted by the splat is not enough,
    we have to disable soft interrupts as well.

    [1]
    BUG: using __this_cpu_write() in preemptible [00000000] code: syz.4.282/6316
     caller is nf_dup_ipv4+0x651/0x8f0 net/ipv4/netfilter/nf_dup_ipv4.c:87
    CPU: 0 UID: 0 PID: 6316 Comm: syz.4.282 Not tainted 6.11.0-rc7-syzkaller-00104-g7052622fccb1 #0
    Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/06/2024
    Call Trace:
     <TASK>
      __dump_stack lib/dump_stack.c:93 [inline]
      dump_stack_lvl+0x241/0x360 lib/dump_stack.c:119
      check_preemption_disabled+0x10e/0x120 lib/smp_processor_id.c:49
      nf_dup_ipv4+0x651/0x8f0 net/ipv4/netfilter/nf_dup_ipv4.c:87
      nft_dup_ipv4_eval+0x1db/0x300 net/ipv4/netfilter/nft_dup_ipv4.c:30
      expr_call_ops_eval net/netfilter/nf_tables_core.c:240 [inline]
      nft_do_chain+0x4ad/0x1da0 net/netfilter/nf_tables_core.c:288
      nft_do_chain_ipv4+0x202/0x320 net/netfilter/nft_chain_filter.c:23
      nf_hook_entry_hookfn include/linux/netfilter.h:154 [inline]
      nf_hook_slow+0xc3/0x220 net/netfilter/core.c:626
      nf_hook+0x2c4/0x450 include/linux/netfilter.h:269
      NF_HOOK_COND include/linux/netfilter.h:302 [inline]
      ip_output+0x185/0x230 net/ipv4/ip_output.c:433
      ip_local_out net/ipv4/ip_output.c:129 [inline]
      ip_send_skb+0x74/0x100 net/ipv4/ip_output.c:1495
      udp_send_skb+0xacf/0x1650 net/ipv4/udp.c:981
      udp_sendmsg+0x1c21/0x2a60 net/ipv4/udp.c:1269
      sock_sendmsg_nosec net/socket.c:730 [inline]
      __sock_sendmsg+0x1a6/0x270 net/socket.c:745
      ____sys_sendmsg+0x525/0x7d0 net/socket.c:2597
      ___sys_sendmsg net/socket.c:2651 [inline]
      __sys_sendmmsg+0x3b2/0x740 net/socket.c:2737
      __do_sys_sendmmsg net/socket.c:2766 [inline]
      __se_sys_sendmmsg net/socket.c:2763 [inline]
      __x64_sys_sendmmsg+0xa0/0xb0 net/socket.c:2763
      do_syscall_x64 arch/x86/entry/common.c:52 [inline]
      do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
     entry_SYSCALL_64_after_hwframe+0x77/0x7f
    RIP: 0033:0x7f4ce4f7def9
    Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 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 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48
    RSP: 002b:00007f4ce5d4a038 EFLAGS: 00000246 ORIG_RAX: 0000000000000133
    RAX: ffffffffffffffda RBX: 00007f4ce5135f80 RCX: 00007f4ce4f7def9
    RDX: 0000000000000001 RSI: 0000000020005d40 RDI: 0000000000000006
    RBP: 00007f4ce4ff0b76 R08: 0000000000000000 R09: 0000000000000000
    R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
    R13: 0000000000000000 R14: 00007f4ce5135f80 R15: 00007ffd4cbc6d68
     </TASK>

    Fixes: d877f07112 ("netfilter: nf_tables: add nft_dup expression")
    Reported-by: syzbot <syzkaller@googlegroups.com>
    Signed-off-by: Eric Dumazet <edumazet@google.com>
    Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

Signed-off-by: Florian Westphal <fwestpha@redhat.com>
2024-10-03 19:07:59 +02:00
Phil Sutter 760e8022a0 netfilter: tproxy: bail out if IP has been disabled on the device
CVE: CVE-2024-36270
JIRA: https://issues.redhat.com/browse/RHEL-44369
Upstream Status: commit 21a673bddc8fd4873c370caf9ae70ffc6d47e8d3

commit 21a673bddc8fd4873c370caf9ae70ffc6d47e8d3
Author: Florian Westphal <fw@strlen.de>
Date:   Mon May 13 12:27:15 2024 +0200

    netfilter: tproxy: bail out if IP has been disabled on the device

    syzbot reports:
    general protection fault, probably for non-canonical address 0xdffffc0000000003: 0000 [#1] PREEMPT SMP KASAN PTI
    KASAN: null-ptr-deref in range [0x0000000000000018-0x000000000000001f]
    [..]
    RIP: 0010:nf_tproxy_laddr4+0xb7/0x340 net/ipv4/netfilter/nf_tproxy_ipv4.c:62
    Call Trace:
     nft_tproxy_eval_v4 net/netfilter/nft_tproxy.c:56 [inline]
     nft_tproxy_eval+0xa9a/0x1a00 net/netfilter/nft_tproxy.c:168

    __in_dev_get_rcu() can return NULL, so check for this.

    Reported-and-tested-by: syzbot+b94a6818504ea90d7661@syzkaller.appspotmail.com
    Fixes: cc6eb43385 ("tproxy: use the interface primary IP address as a default value for --on-ip")
    Signed-off-by: Florian Westphal <fw@strlen.de>
    Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

Signed-off-by: Phil Sutter <psutter@redhat.com>
Signed-off-by: Herton R. Krzesinski <herton@redhat.com>
2024-09-05 15:57:34 -03:00
Lucas Zampieri 1af02080b4 Merge: nftables: backport changes to allow rpfilter in INPUT and FORWARD chains
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/4617

JIRA: https://issues.redhat.com/browse/RHEL-36316
Upstream Status: all mainline

Signed-off-by: Florian Westphal <fwestpha@redhat.com>

Approved-by: Xin Long <lxin@redhat.com>
Approved-by: Antoine Tenart <atenart@redhat.com>
Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com>

Merged-by: Lucas Zampieri <lzampier@redhat.com>
2024-07-16 19:44:12 +00:00
Lucas Zampieri d2a03fe81d Merge: netfilter: validate user input for expected length
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/4532

CVE: CVE-2024-35896
JIRA: https://issues.redhat.com/browse/RHEL-37212
Upstream Status: commit 0c83842df40f86e529db6842231154772c20edcc

commit 0c83842df40f86e529db6842231154772c20edcc
Author: Eric Dumazet <edumazet@google.com>
Date:   Thu Apr 4 12:20:51 2024 +0000

    netfilter: validate user input for expected length

    I got multiple syzbot reports showing old bugs exposed
    by BPF after commit 20f2505fb4 ("bpf: Try to avoid kzalloc
    in cgroup/{s,g}etsockopt")

    setsockopt() @optlen argument should be taken into account
    before copying data.

     BUG: KASAN: slab-out-of-bounds in copy_from_sockptr_offset include/linux/sockptr.h:49 [inline]
     BUG: KASAN: slab-out-of-bounds in copy_from_sockptr include/linux/sockptr.h:55 [inline]
     BUG: KASAN: slab-out-of-bounds in do_replace net/ipv4/netfilter/ip_tables.c:1111 [inline]
     BUG: KASAN: slab-out-of-bounds in do_ipt_set_ctl+0x902/0x3dd0 net/ipv4/netfilter/ip_tables.c:1627
    Read of size 96 at addr ffff88802cd73da0 by task syz-executor.4/7238

    CPU: 1 PID: 7238 Comm: syz-executor.4 Not tainted 6.9.0-rc2-next-20240403-syzkaller #0
    Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 03/27/2024
    Call Trace:
     [...]

Signed-off-by: Phil Sutter <psutter@redhat.com>

Approved-by: Florian Westphal <fwestpha@redhat.com>
Approved-by: Antoine Tenart <atenart@redhat.com>
Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com>

Merged-by: Lucas Zampieri <lzampier@redhat.com>
2024-07-09 14:03:27 +00:00
Florian Westphal 8b8a586eb8 netfilter: nft_fib: reverse path filter for policy-based routing on iif
JIRA: https://issues.redhat.com/browse/RHEL-36316
Upstream Status: commit be8be04e5ddb

commit be8be04e5ddb9842d4ff2c1e4eaeec6ca801c573
Author: Pablo Neira Ayuso <pablo@netfilter.org>
Date:   Thu Mar 31 17:14:47 2022 +0200

    netfilter: nft_fib: reverse path filter for policy-based routing on iif

    If policy-based routing using the iif selector is used, then the fib
    expression fails to look up for the reverse path from the prerouting
    hook because the input interface cannot be inferred. In order to support
    this scenario, extend the fib expression to allow to use after the route
    lookup, from the forward hook.

    This patch also adds support for the input hook for usability reasons.
    Since the prerouting hook cannot be used for the scenario described
    above, users need two rules: one for the forward chain and another rule
    for the input chain to check for the reverse path check for locally
    targeted traffic.

    Acked-by: Florian Westphal <fw@strlen.de>
    Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

Signed-off-by: Florian Westphal <fwestpha@redhat.com>
2024-06-27 16:52:21 +02:00
Phil Sutter 61a0a99ad1 netfilter: complete validation of user input
CVE: CVE-2024-35896
JIRA: https://issues.redhat.com/browse/RHEL-37212
Upstream Status: commit 65acf6e0501ac8880a4f73980d01b5d27648b956

commit 65acf6e0501ac8880a4f73980d01b5d27648b956
Author: Eric Dumazet <edumazet@google.com>
Date:   Tue Apr 9 12:07:41 2024 +0000

    netfilter: complete validation of user input

    In my recent commit, I missed that do_replace() handlers
    use copy_from_sockptr() (which I fixed), followed
    by unsafe copy_from_sockptr_offset() calls.

    In all functions, we can perform the @optlen validation
    before even calling xt_alloc_table_info() with the following
    check:

    if ((u64)optlen < (u64)tmp.size + sizeof(tmp))
            return -EINVAL;

    Fixes: 0c83842df40f ("netfilter: validate user input for expected length")
    Reported-by: syzbot <syzkaller@googlegroups.com>
    Signed-off-by: Eric Dumazet <edumazet@google.com>
    Reviewed-by: Pablo Neira Ayuso <pablo@netfilter.org>
    Link: https://lore.kernel.org/r/20240409120741.3538135-1-edumazet@google.com
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Phil Sutter <psutter@redhat.com>
2024-06-27 10:51:35 +02:00
Florian Westphal 6fa5dcc3ff netfilter: bridge: replace physindev with physinif in nf_bridge_info
JIRA: https://issues.redhat.com/browse/RHEL-37040
JIRA: https://issues.redhat.com/browse/RHEL-37041
Upstream Status: commit 9874808878d9
CVE: CVE-2024-35839

commit 9874808878d9eed407e3977fd11fee49de1e1d86
Author: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Date:   Thu Jan 11 23:06:40 2024 +0800

    netfilter: bridge: replace physindev with physinif in nf_bridge_info

    An skb can be added to a neigh->arp_queue while waiting for an arp
    reply. Where original skb's skb->dev can be different to neigh's
    neigh->dev. For instance in case of bridging dnated skb from one veth to
    another, the skb would be added to a neigh->arp_queue of the bridge.

    As skb->dev can be reset back to nf_bridge->physindev and used, and as
    there is no explicit mechanism that prevents this physindev from been
    freed under us (for instance neigh_flush_dev doesn't cleanup skbs from
    different device's neigh queue) we can crash on e.g. this stack:

    arp_process
      neigh_update
        skb = __skb_dequeue(&neigh->arp_queue)
          neigh_resolve_output(..., skb)
            ...
              br_nf_dev_xmit
                br_nf_pre_routing_finish_bridge_slow
                  skb->dev = nf_bridge->physindev
                  br_handle_frame_finish

    Let's use plain ifindex instead of net_device link. To peek into the
    original net_device we will use dev_get_by_index_rcu(). Thus either we
    get device and are safe to use it or we don't get it and drop skb.

    Fixes: c4e70a87d9 ("netfilter: bridge: rename br_netfilter.c to br_netfilter_hooks.c")
    Suggested-by: Florian Westphal <fw@strlen.de>
    Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
    Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

Signed-off-by: Florian Westphal <fwestpha@redhat.com>
2024-06-24 11:47:17 +02:00
Florian Westphal 5d49130285 netfilter: propagate net to nf_bridge_get_physindev
JIRA: https://issues.redhat.com/browse/RHEL-37040
JIRA: https://issues.redhat.com/browse/RHEL-37041
Upstream Status: commit a54e72197037
CVE: CVE-2024-35839

commit a54e72197037d2c9bfcd70dddaac8c8ccb5b41ba
Author: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Date:   Thu Jan 11 23:06:39 2024 +0800

    netfilter: propagate net to nf_bridge_get_physindev

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

    Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
    Reviewed-by: Simon Horman <horms@kernel.org>
    Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

Signed-off-by: Florian Westphal <fwestpha@redhat.com>
2024-06-24 11:47:15 +02:00
Phil Sutter 860b023115 netfilter: validate user input for expected length
CVE: CVE-2024-35896
JIRA: https://issues.redhat.com/browse/RHEL-37212
Upstream Status: commit 0c83842df40f86e529db6842231154772c20edcc

commit 0c83842df40f86e529db6842231154772c20edcc
Author: Eric Dumazet <edumazet@google.com>
Date:   Thu Apr 4 12:20:51 2024 +0000

    netfilter: validate user input for expected length

    I got multiple syzbot reports showing old bugs exposed
    by BPF after commit 20f2505fb4 ("bpf: Try to avoid kzalloc
    in cgroup/{s,g}etsockopt")

    setsockopt() @optlen argument should be taken into account
    before copying data.

     BUG: KASAN: slab-out-of-bounds in copy_from_sockptr_offset include/linux/sockptr.h:49 [inline]
     BUG: KASAN: slab-out-of-bounds in copy_from_sockptr include/linux/sockptr.h:55 [inline]
     BUG: KASAN: slab-out-of-bounds in do_replace net/ipv4/netfilter/ip_tables.c:1111 [inline]
     BUG: KASAN: slab-out-of-bounds in do_ipt_set_ctl+0x902/0x3dd0 net/ipv4/netfilter/ip_tables.c:1627
    Read of size 96 at addr ffff88802cd73da0 by task syz-executor.4/7238

    CPU: 1 PID: 7238 Comm: syz-executor.4 Not tainted 6.9.0-rc2-next-20240403-syzkaller #0
    Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 03/27/2024
    Call Trace:
     <TASK>
      __dump_stack lib/dump_stack.c:88 [inline]
      dump_stack_lvl+0x241/0x360 lib/dump_stack.c:114
      print_address_description mm/kasan/report.c:377 [inline]
      print_report+0x169/0x550 mm/kasan/report.c:488
      kasan_report+0x143/0x180 mm/kasan/report.c:601
      kasan_check_range+0x282/0x290 mm/kasan/generic.c:189
      __asan_memcpy+0x29/0x70 mm/kasan/shadow.c:105
      copy_from_sockptr_offset include/linux/sockptr.h:49 [inline]
      copy_from_sockptr include/linux/sockptr.h:55 [inline]
      do_replace net/ipv4/netfilter/ip_tables.c:1111 [inline]
      do_ipt_set_ctl+0x902/0x3dd0 net/ipv4/netfilter/ip_tables.c:1627
      nf_setsockopt+0x295/0x2c0 net/netfilter/nf_sockopt.c:101
      do_sock_setsockopt+0x3af/0x720 net/socket.c:2311
      __sys_setsockopt+0x1ae/0x250 net/socket.c:2334
      __do_sys_setsockopt net/socket.c:2343 [inline]
      __se_sys_setsockopt net/socket.c:2340 [inline]
      __x64_sys_setsockopt+0xb5/0xd0 net/socket.c:2340
     do_syscall_64+0xfb/0x240
     entry_SYSCALL_64_after_hwframe+0x72/0x7a
    RIP: 0033:0x7fd22067dde9
    Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 e1 20 00 00 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 73 01 c3 48 c7 c1 b0 ff ff ff f7 d8 64 89 01 48
    RSP: 002b:00007fd21f9ff0c8 EFLAGS: 00000246 ORIG_RAX: 0000000000000036
    RAX: ffffffffffffffda RBX: 00007fd2207abf80 RCX: 00007fd22067dde9
    RDX: 0000000000000040 RSI: 0000000000000000 RDI: 0000000000000003
    RBP: 00007fd2206ca47a R08: 0000000000000001 R09: 0000000000000000
    R10: 0000000020000880 R11: 0000000000000246 R12: 0000000000000000
    R13: 000000000000000b R14: 00007fd2207abf80 R15: 00007ffd2d0170d8
     </TASK>

    Allocated by task 7238:
      kasan_save_stack mm/kasan/common.c:47 [inline]
      kasan_save_track+0x3f/0x80 mm/kasan/common.c:68
      poison_kmalloc_redzone mm/kasan/common.c:370 [inline]
      __kasan_kmalloc+0x98/0xb0 mm/kasan/common.c:387
      kasan_kmalloc include/linux/kasan.h:211 [inline]
      __do_kmalloc_node mm/slub.c:4069 [inline]
      __kmalloc_noprof+0x200/0x410 mm/slub.c:4082
      kmalloc_noprof include/linux/slab.h:664 [inline]
      __cgroup_bpf_run_filter_setsockopt+0xd47/0x1050 kernel/bpf/cgroup.c:1869
      do_sock_setsockopt+0x6b4/0x720 net/socket.c:2293
      __sys_setsockopt+0x1ae/0x250 net/socket.c:2334
      __do_sys_setsockopt net/socket.c:2343 [inline]
      __se_sys_setsockopt net/socket.c:2340 [inline]
      __x64_sys_setsockopt+0xb5/0xd0 net/socket.c:2340
     do_syscall_64+0xfb/0x240
     entry_SYSCALL_64_after_hwframe+0x72/0x7a

    The buggy address belongs to the object at ffff88802cd73da0
     which belongs to the cache kmalloc-8 of size 8
    The buggy address is located 0 bytes inside of
     allocated 1-byte region [ffff88802cd73da0, ffff88802cd73da1)

    The buggy address belongs to the physical page:
    page: refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff88802cd73020 pfn:0x2cd73
    flags: 0xfff80000000000(node=0|zone=1|lastcpupid=0xfff)
    page_type: 0xffffefff(slab)
    raw: 00fff80000000000 ffff888015041280 dead000000000100 dead000000000122
    raw: ffff88802cd73020 000000008080007f 00000001ffffefff 0000000000000000
    page dumped because: kasan: bad access detected
    page_owner tracks the page as allocated
    page last allocated via order 0, migratetype Unmovable, gfp_mask 0x12cc0(GFP_KERNEL|__GFP_NOWARN|__GFP_NORETRY), pid 5103, tgid 2119833701 (syz-executor.4), ts 5103, free_ts 70804600828
      set_page_owner include/linux/page_owner.h:32 [inline]
      post_alloc_hook+0x1f3/0x230 mm/page_alloc.c:1490
      prep_new_page mm/page_alloc.c:1498 [inline]
      get_page_from_freelist+0x2e7e/0x2f40 mm/page_alloc.c:3454
      __alloc_pages_noprof+0x256/0x6c0 mm/page_alloc.c:4712
      __alloc_pages_node_noprof include/linux/gfp.h:244 [inline]
      alloc_pages_node_noprof include/linux/gfp.h:271 [inline]
      alloc_slab_page+0x5f/0x120 mm/slub.c:2249
      allocate_slab+0x5a/0x2e0 mm/slub.c:2412
      new_slab mm/slub.c:2465 [inline]
      ___slab_alloc+0xcd1/0x14b0 mm/slub.c:3615
      __slab_alloc+0x58/0xa0 mm/slub.c:3705
      __slab_alloc_node mm/slub.c:3758 [inline]
      slab_alloc_node mm/slub.c:3936 [inline]
      __do_kmalloc_node mm/slub.c:4068 [inline]
      kmalloc_node_track_caller_noprof+0x286/0x450 mm/slub.c:4089
      kstrdup+0x3a/0x80 mm/util.c:62
      device_rename+0xb5/0x1b0 drivers/base/core.c:4558
      dev_change_name+0x275/0x860 net/core/dev.c:1232
      do_setlink+0xa4b/0x41f0 net/core/rtnetlink.c:2864
      __rtnl_newlink net/core/rtnetlink.c:3680 [inline]
      rtnl_newlink+0x180b/0x20a0 net/core/rtnetlink.c:3727
      rtnetlink_rcv_msg+0x89b/0x10d0 net/core/rtnetlink.c:6594
      netlink_rcv_skb+0x1e3/0x430 net/netlink/af_netlink.c:2559
      netlink_unicast_kernel net/netlink/af_netlink.c:1335 [inline]
      netlink_unicast+0x7ea/0x980 net/netlink/af_netlink.c:1361
    page last free pid 5146 tgid 5146 stack trace:
      reset_page_owner include/linux/page_owner.h:25 [inline]
      free_pages_prepare mm/page_alloc.c:1110 [inline]
      free_unref_page+0xd3c/0xec0 mm/page_alloc.c:2617
      discard_slab mm/slub.c:2511 [inline]
      __put_partials+0xeb/0x130 mm/slub.c:2980
      put_cpu_partial+0x17c/0x250 mm/slub.c:3055
      __slab_free+0x2ea/0x3d0 mm/slub.c:4254
      qlink_free mm/kasan/quarantine.c:163 [inline]
      qlist_free_all+0x9e/0x140 mm/kasan/quarantine.c:179
      kasan_quarantine_reduce+0x14f/0x170 mm/kasan/quarantine.c:286
      __kasan_slab_alloc+0x23/0x80 mm/kasan/common.c:322
      kasan_slab_alloc include/linux/kasan.h:201 [inline]
      slab_post_alloc_hook mm/slub.c:3888 [inline]
      slab_alloc_node mm/slub.c:3948 [inline]
      __do_kmalloc_node mm/slub.c:4068 [inline]
      __kmalloc_node_noprof+0x1d7/0x450 mm/slub.c:4076
      kmalloc_node_noprof include/linux/slab.h:681 [inline]
      kvmalloc_node_noprof+0x72/0x190 mm/util.c:634
      bucket_table_alloc lib/rhashtable.c:186 [inline]
      rhashtable_rehash_alloc+0x9e/0x290 lib/rhashtable.c:367
      rht_deferred_worker+0x4e1/0x2440 lib/rhashtable.c:427
      process_one_work kernel/workqueue.c:3218 [inline]
      process_scheduled_works+0xa2c/0x1830 kernel/workqueue.c:3299
      worker_thread+0x86d/0xd70 kernel/workqueue.c:3380
      kthread+0x2f0/0x390 kernel/kthread.c:388
      ret_from_fork+0x4b/0x80 arch/x86/kernel/process.c:147
      ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:243

    Memory state around the buggy address:
     ffff88802cd73c80: 07 fc fc fc 05 fc fc fc 05 fc fc fc fa fc fc fc
     ffff88802cd73d00: fa fc fc fc fa fc fc fc fa fc fc fc fa fc fc fc
    >ffff88802cd73d80: fa fc fc fc 01 fc fc fc fa fc fc fc fa fc fc fc
                                   ^
     ffff88802cd73e00: fa fc fc fc fa fc fc fc 05 fc fc fc 07 fc fc fc
     ffff88802cd73e80: 07 fc fc fc 07 fc fc fc 07 fc fc fc 07 fc fc fc

    Fixes: 1da177e4c3 ("Linux-2.6.12-rc2")
    Reported-by: syzbot <syzkaller@googlegroups.com>
    Signed-off-by: Eric Dumazet <edumazet@google.com>
    Reviewed-by: Pablo Neira Ayuso <pablo@netfilter.org>
    Link: https://lore.kernel.org/r/20240404122051.2303764-1-edumazet@google.com
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Phil Sutter <psutter@redhat.com>
2024-06-21 23:47:04 +02:00
Phil Sutter 455150209c netfilter: xt_mangle: only check verdict part of return value
JIRA: https://issues.redhat.com/browse/RHEL-6037
Upstream Status: commit e15e5027106f3f6009d2fb46b3a1bb3d9e6a1b77
Conflicts: Context change due to missing commits:
 * 44b5990e7b46 ("netfilter: ip6tables: allow use of ip6t_do_table as
   hookfn")
 * 8844e01062dd ("netfilter: iptables: allow use of ipt_do_table as
   hookfn")

commit e15e5027106f3f6009d2fb46b3a1bb3d9e6a1b77
Author: Florian Westphal <fw@strlen.de>
Date:   Wed Oct 11 09:59:34 2023 +0200

    netfilter: xt_mangle: only check verdict part of return value

    These checks assume that the caller only returns NF_DROP without
    any errno embedded in the upper bits.

    This is fine right now, but followup patches will start to propagate
    such errors to allow kfree_skb_drop_reason() in the called functions,
    those would then indicate 'errno << 8 | NF_STOLEN'.

    To not break things we have to mask those parts out.

    Signed-off-by: Florian Westphal <fw@strlen.de>

Signed-off-by: Phil Sutter <psutter@redhat.com>
2023-12-12 16:32:36 +01:00
Prarit Bhargava c92cfc1f59 treewide: Remove mark_hardware_deprecated()
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2181611
Upstream Status: RHEL only

Remove calls to mark_hardware_deprecated().  A new function to track
deprecated hardware will be added in a later commit in this series.

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
Signed-off-by: Scott Weaver <scweaver@redhat.com>
2023-11-09 18:13:00 -05:00
Phil Sutter 55895d03af netfilter: nf_tables: Extend nft_expr_ops::dump callback parameters
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1925492
Upstream Status: commit 7d34aa3e03b6a
Conflicts:
* Context changes due to missing expression reduce support
* Dropped chunks applying to TCP option stripping, 16byte cmp fast ops
  and inner header matching

commit 7d34aa3e03b6a56306296bd98b26c6a1710cd57b
Author: Phil Sutter <phil@nwl.cc>
Date:   Fri Oct 14 23:45:58 2022 +0200

    netfilter: nf_tables: Extend nft_expr_ops::dump callback parameters

    Add a 'reset' flag just like with nft_object_ops::dump. This will be
    useful to reset "anonymous stateful objects", e.g. simple rule counters.

    No functional change intended.

    Signed-off-by: Phil Sutter <phil@nwl.cc>
    Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

Signed-off-by: Phil Sutter <psutter@redhat.com>
2023-07-28 18:18:30 +02:00
Florian Westphal 344967de97 netfilter: tproxy: fix deadlock due to missing BH disable
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2189550
Upstream Status: commit 4a02426787bf0

commit 4a02426787bf024dafdb79b362285ee325de3f5e
Author: Florian Westphal <fw@strlen.de>
Date:   Fri Mar 3 10:58:56 2023 +0100

    netfilter: tproxy: fix deadlock due to missing BH disable

    The xtables packet traverser performs an unconditional local_bh_disable(),
    but the nf_tables evaluation loop does not.

    Functions that are called from either xtables or nftables must assume
    that they can be called in process context.

    inet_twsk_deschedule_put() assumes that no softirq interrupt can occur.
    If tproxy is used from nf_tables its possible that we'll deadlock
    trying to aquire a lock already held in process context.

    Add a small helper that takes care of this and use it.

    Link: https://lore.kernel.org/netfilter-devel/401bd6ed-314a-a196-1cdc-e13c720cc8f2@balasys.hu/
    Fixes: 4ed8eb6570 ("netfilter: nf_tables: Add native tproxy support")
    Reported-and-tested-by: Major Dávid <major.david@balasys.hu>
    Signed-off-by: Florian Westphal <fw@strlen.de>
    Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

Signed-off-by: Florian Westphal <fwestpha@redhat.com>
2023-06-12 15:22:48 +02:00
Florian Westphal eaddfeb949 netfilter: ebtables: fix table blob use-after-free
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2189550
Upstream Status: commit e58a171d35e32

commit e58a171d35e32e6e8c37cfe0e8a94406732a331f
Author: Florian Westphal <fw@strlen.de>
Date:   Fri Feb 17 23:20:06 2023 +0100

    netfilter: ebtables: fix table blob use-after-free

    We are not allowed to return an error at this point.
    Looking at the code it looks like ret is always 0 at this
    point, but its not.

    t = find_table_lock(net, repl->name, &ret, &ebt_mutex);

    ... this can return a valid table, with ret != 0.

    This bug causes update of table->private with the new
    blob, but then frees the blob right away in the caller.

    Syzbot report:

    BUG: KASAN: vmalloc-out-of-bounds in __ebt_unregister_table+0xc00/0xcd0 net/bridge/netfilter/ebtables.c:1168
    Read of size 4 at addr ffffc90005425000 by task kworker/u4:4/74
    Workqueue: netns cleanup_net
    Call Trace:
     kasan_report+0xbf/0x1f0 mm/kasan/report.c:517
     __ebt_unregister_table+0xc00/0xcd0 net/bridge/netfilter/ebtables.c:1168
     ebt_unregister_table+0x35/0x40 net/bridge/netfilter/ebtables.c:1372
     ops_exit_list+0xb0/0x170 net/core/net_namespace.c:169
     cleanup_net+0x4ee/0xb10 net/core/net_namespace.c:613
    ...

    ip(6)tables appears to be ok (ret should be 0 at this point) but make
    this more obvious.

    Fixes: c58dd2dd44 ("netfilter: Can't fail and free after table replacement")
    Reported-by: syzbot+f61594de72d6705aea03@syzkaller.appspotmail.com
    Signed-off-by: Florian Westphal <fw@strlen.de>
    Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

Signed-off-by: Florian Westphal <fwestpha@redhat.com>
2023-06-12 15:22:48 +02:00
Florian Westphal 539491426c netfilter: conntrack: Fix data-races around ct mark
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2180943
Upstream Status: commit 52d1aa8b8249f

commit 52d1aa8b8249ff477aaa38b6f74a8ced780d079c
Author: Daniel Xu <dxu@dxuuu.xyz>
Date:   Wed Nov 9 12:39:07 2022 -0700

    netfilter: conntrack: Fix data-races around ct mark

    nf_conn:mark can be read from and written to in parallel. Use
    READ_ONCE()/WRITE_ONCE() for reads and writes to prevent unwanted
    compiler optimizations.

    Fixes: 1da177e4c3 ("Linux-2.6.12-rc2")
    Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
    Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

Signed-off-by: Florian Westphal <fwestpha@redhat.com>
2023-03-24 11:20:55 +01:00
Guillaume Nault 7298dceca8 netfilter: rpfilter/fib: Set ->flowic_uid correctly for user namespaces.
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2162116
Upstream Status: linux.git

commit 1fcc064b305a1aadeff0d4bff961094d27660acd
Author: Guillaume Nault <gnault@redhat.com>
Date:   Thu Oct 13 16:37:47 2022 +0200

    netfilter: rpfilter/fib: Set ->flowic_uid correctly for user namespaces.

    Currently netfilter's rpfilter and fib modules implicitely initialise
    ->flowic_uid with 0. This is normally the root UID. However, this isn't
    the case in user namespaces, where user ID 0 is mapped to a different
    kernel UID. By initialising ->flowic_uid with sock_net_uid(), we get
    the root UID of the user namespace, thus keeping the same behaviour
    whether or not we're running in a user namepspace.

    Note, this is similar to commit 8bcfd0925e ("ipv4: add missing
    initialization for flowi4_uid"), which fixed the rp_filter sysctl.

    Fixes: 622ec2c9d5 ("net: core: add UID to flows, rules, and routes")
    Signed-off-by: Guillaume Nault <gnault@redhat.com>
    Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

Signed-off-by: Guillaume Nault <gnault@redhat.com>
2023-01-18 20:45:44 +01:00
Guillaume Nault 27ce10b0b3 ip: Fix data-races around sysctl_ip_default_ttl.
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2149949
Upstream Status: linux.git
Conflicts: The drivers/net/ethernet/netronome/nfp/flower/action.c chunk
           was already backported by Centos Stream commit ab569013af.

commit 8281b7ec5c56b71cb2cc5a1728b41607be66959c
Author: Kuniyuki Iwashima <kuniyu@amazon.com>
Date:   Wed Jul 13 13:51:51 2022 -0700

    ip: Fix data-races around sysctl_ip_default_ttl.

    While reading sysctl_ip_default_ttl, it can be changed concurrently.
    Thus, we need to add READ_ONCE() to its readers.

    Fixes: 1da177e4c3 ("Linux-2.6.12-rc2")
    Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Guillaume Nault <gnault@redhat.com>
2022-12-22 11:37:53 +01:00
Frantisek Hrbata c76915ca89 Merge: net/mptcp: phase-1 rebase for RHEL-9.2
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/1536

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2137858
Tested: ./run_kselftest.sh -c net/mptcp, all OK
Conflicts: see individual patches

Signed-off-by: Davide Caratti <dcaratti@redhat.com>

Approved-by: Florian Westphal <fwestpha@redhat.com>
Approved-by: Paolo Abeni <pabeni@redhat.com>

Signed-off-by: Frantisek Hrbata <fhrbata@redhat.com>
2022-11-12 03:10:42 -05:00
Davide Caratti 728983215c tcp: Access &tcp_hashinfo via net.
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2137858
Upstream Status: net.git commit 4461568aa4e5
Conflicts:
 - net/ipv4/tcp_ipv4.c: context mismatch as we don't have upstream
   commit 28044fc1d495 ("net: Add a bhash2 table hashed by port and
   address") and 08eaef904031 ("tcp: Clean up some functions.")
 - net/ipv6/tcp_ipv6.c: context mismatch as we don't have upstream
   commit 28044fc1d495 ("net: Add a bhash2 table hashed by port and
   address")
 - net/ipv4/tcp_minisocks.c: hunk applied manually to fix a build issue
   caused by missing upstream commit 08eaef904031 ("tcp: Clean up some
   functions.")

commit 4461568aa4e565de2c336f4875ddf912f26da8a5
Author: Kuniyuki Iwashima <kuniyu@amazon.com>
Date:   Wed Sep 7 18:10:20 2022 -0700

    tcp: Access &tcp_hashinfo via net.

    We will soon introduce an optional per-netns ehash.

    This means we cannot use tcp_hashinfo directly in most places.

    Instead, access it via net->ipv4.tcp_death_row.hashinfo.

    The access will be valid only while initialising tcp_hashinfo
    itself and creating/destroying each netns.

    Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
    Reviewed-by: Eric Dumazet <edumazet@google.com>
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Davide Caratti <dcaratti@redhat.com>
2022-11-08 17:10:59 +01:00
Guillaume Nault b63d7c6467 netfilter: nft_fib: Fix for rpath check with VRF devices
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2134815
Upstream Status: linux.git

commit 2a8a7c0eaa8747c16aa4a48d573aa920d5c00a5c
Author: Phil Sutter <phil@nwl.cc>
Date:   Wed Sep 21 13:07:31 2022 +0200

    netfilter: nft_fib: Fix for rpath check with VRF devices

    Analogous to commit b575b24b8e ("netfilter: Fix rpfilter
    dropping vrf packets by mistake") but for nftables fib expression:
    Add special treatment of VRF devices so that typical reverse path
    filtering via 'fib saddr . iif oif' expression works as expected.

    Fixes: f6d0cbcf09 ("netfilter: nf_tables: add fib expression")
    Signed-off-by: Phil Sutter <phil@nwl.cc>
    Signed-off-by: Florian Westphal <fw@strlen.de>

Signed-off-by: Guillaume Nault <gnault@redhat.com>
2022-11-02 09:25:08 +01:00
Phil Sutter 37b3ad768e netfilter: rpfilter/fib: Populate flowic_l3mdev field
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2129093
Upstream Status: commit acc641ab95b66

commit acc641ab95b66b813c1ce856c377a2bbe71e7f52
Author: Phil Sutter <phil@nwl.cc>
Date:   Wed Oct 5 18:07:05 2022 +0200

    netfilter: rpfilter/fib: Populate flowic_l3mdev field

    Use the introduced field for correct operation with VRF devices instead
    of conditionally overwriting flowic_oif. This is a partial revert of
    commit b575b24b8e ("netfilter: Fix rpfilter dropping vrf packets by
    mistake"), implementing a simpler solution.

    Signed-off-by: Phil Sutter <phil@nwl.cc>
    Reviewed-by: David Ahern <dsahern@kernel.org>
    Reviewed-by: Guillaume Nault <gnault@redhat.com>
    Signed-off-by: Florian Westphal <fw@strlen.de>

Signed-off-by: Phil Sutter <psutter@redhat.com>
2022-10-28 22:35:32 +02:00
Phil Sutter 34f4f0e27e netfilter: nft_fib: Fix for rpath check with VRF devices
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2129093
Upstream Status: commit 2a8a7c0eaa874

commit 2a8a7c0eaa8747c16aa4a48d573aa920d5c00a5c
Author: Phil Sutter <phil@nwl.cc>
Date:   Wed Sep 21 13:07:31 2022 +0200

    netfilter: nft_fib: Fix for rpath check with VRF devices

    Analogous to commit b575b24b8e ("netfilter: Fix rpfilter
    dropping vrf packets by mistake") but for nftables fib expression:
    Add special treatment of VRF devices so that typical reverse path
    filtering via 'fib saddr . iif oif' expression works as expected.

    Fixes: f6d0cbcf09 ("netfilter: nf_tables: add fib expression")
    Signed-off-by: Phil Sutter <phil@nwl.cc>
    Signed-off-by: Florian Westphal <fw@strlen.de>

Signed-off-by: Phil Sutter <psutter@redhat.com>
2022-10-28 22:35:32 +02:00
Florian Westphal de65c2df94 netfilter: h323: merge nat hook pointers into one
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2111270
Upstream Status: commit d3f2d0a292c2

commit d3f2d0a292c24fc624afb2b4f47f838e83775721
Author: Florian Westphal <fw@strlen.de>
Date:   Wed Jun 22 11:00:47 2022 +0200

    netfilter: h323: merge nat hook pointers into one

    sparse complains about incorrect rcu usage.

    Code uses the correct rcu access primitives, but the function pointers
    lack rcu annotations.

    Collapse all of them into a single structure, then annotate the pointer.

    Signed-off-by: Florian Westphal <fw@strlen.de>
    Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

Signed-off-by: Florian Westphal <fwestpha@redhat.com>
2022-07-27 01:03:04 +02:00
Florian Westphal ce05567675 netfilter: conntrack: pptp: use single option structure
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2111270
Upstream Status: commit 20ff32024624

commit 20ff32024624102596f2b4083a17a97ca71d6cd8
Author: Florian Westphal <fw@strlen.de>
Date:   Thu Jan 20 16:09:13 2022 +0100

    netfilter: conntrack: pptp: use single option structure

    Instead of exposing the four hooks individually use a sinle hook ops
    structure.

    Signed-off-by: Florian Westphal <fw@strlen.de>
    Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

Signed-off-by: Florian Westphal <fwestpha@redhat.com>
2022-07-27 00:34:33 +02:00
Florian Westphal 300d820934 netfilter: nf_nat_h323: eliminate anonymous module_init & module_exit
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2102148
Upstream Status: commit fd4213929053

commit fd4213929053bb58b0b2a080ca17f2dd1a9b6df4
Author: Randy Dunlap <rdunlap@infradead.org>
Date:   Wed Mar 16 12:20:05 2022 -0700

    netfilter: nf_nat_h323: eliminate anonymous module_init & module_exit

    Eliminate anonymous module_init() and module_exit(), which can lead to
    confusion or ambiguity when reading System.map, crashes/oops/bugs,
    or an initcall_debug log.

    Give each of these init and exit functions unique driver-specific
    names to eliminate the anonymous names.

    Example 1: (System.map)
     ffffffff832fc78c t init
     ffffffff832fc79e t init
     ffffffff832fc8f8 t init

    Example 2: (initcall_debug log)
     calling  init+0x0/0x12 @ 1
     initcall init+0x0/0x12 returned 0 after 15 usecs
     calling  init+0x0/0x60 @ 1
     initcall init+0x0/0x60 returned 0 after 2 usecs
     calling  init+0x0/0x9a @ 1
     initcall init+0x0/0x9a returned 0 after 74 usecs

    Fixes: f587de0e2f ("[NETFILTER]: nf_conntrack/nf_nat: add H.323 helper port")
    Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
    Acked-by: Florian Westphal <fw@strlen.de>
    Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

Signed-off-by: Florian Westphal <fwestpha@redhat.com>
2022-07-06 21:28:22 +02:00
Ivan Vecera 87d6a33df9 proc: remove PDE_DATA() completely
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2073492

Conflicts:
- Hunk for dell-smm-hwmon driver skipped as it is not applicable and
  does not use PDE_DATA()

commit 359745d78351c6f5442435f81549f0207ece28aa
Author: Muchun Song <songmuchun@bytedance.com>
Date:   Fri Jan 21 22:14:23 2022 -0800

    proc: remove PDE_DATA() completely

    Remove PDE_DATA() completely and replace it with pde_data().

    [akpm@linux-foundation.org: fix naming clash in drivers/nubus/proc.c]
    [akpm@linux-foundation.org: now fix it properly]

    Link: https://lkml.kernel.org/r/20211124081956.87711-2-songmuchun@bytedance.com
    Signed-off-by: Muchun Song <songmuchun@bytedance.com>
    Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
    Cc: Alexey Dobriyan <adobriyan@gmail.com>
    Cc: Alexey Gladkov <gladkov.alexey@gmail.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Signed-off-by: Ivan Vecera <ivecera@redhat.com>
2022-04-08 17:38:02 +02:00
Florian Westphal a5447fa1c3 netfilter: conntrack: fix boot failure with nf_conntrack.enable_hooks=1
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2028203
Upstream Status: commit 339031bafe6b

commit 339031bafe6b281cf2dcb8364217288b9fdab555
Author: Florian Westphal <fw@strlen.de>
Date:   Thu Sep 23 16:44:34 2021 +0200

    netfilter: conntrack: fix boot failure with nf_conntrack.enable_hooks=1

    This is a revert of
    7b1957b049 ("netfilter: nf_defrag_ipv4: use net_generic infra")
    and a partial revert of
    8b0adbe3e3 ("netfilter: nf_defrag_ipv6: use net_generic infra").

    If conntrack is builtin and kernel is booted with:
    nf_conntrack.enable_hooks=1

    .... kernel will fail to boot due to a NULL deref in
    nf_defrag_ipv4_enable(): Its called before the ipv4 defrag initcall is
    made, so net_generic() returns NULL.

    To resolve this, move the user refcount back to struct net so calls
    to those functions are possible even before their initcalls have run.

    Fixes: 7b1957b049 ("netfilter: nf_defrag_ipv4: use net_generic infra")
    Fixes: 8b0adbe3e3 ("netfilter: nf_defrag_ipv6: use net_generic infra").
    Signed-off-by: Florian Westphal <fw@strlen.de>
    Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

Signed-off-by: Florian Westphal <fwestpha@redhat.com>
2021-12-02 13:57:47 +01:00
Phil Sutter ce5b1ff711 netfilter: Add deprecation notices for xtables
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1945179
Upstream Status: RHEL-only

Upon loading legacy xtables table modules or the nft compat module,
print a warning indicating deprecation status.

Signed-off-by: Phil Sutter <psutter@redhat.com>
2021-10-05 17:15:08 +02:00
Florian Westphal 85554eb981 netfilter: nf_tables: add and use nft_sk helper
This allows to change storage placement later on without changing readers.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2021-05-29 01:04:53 +02:00
Florian Westphal 43016d02cf netfilter: arptables: use pernet ops struct during unregister
Like with iptables and ebtables, hook unregistration has to use the
pernet ops struct, not the template.

This triggered following splat:
  hook not found, pf 3 num 0
  WARNING: CPU: 0 PID: 224 at net/netfilter/core.c:480 __nf_unregister_net_hook+0x1eb/0x610 net/netfilter/core.c:480
[..]
 nf_unregister_net_hook net/netfilter/core.c:502 [inline]
 nf_unregister_net_hooks+0x117/0x160 net/netfilter/core.c:576
 arpt_unregister_table_pre_exit+0x67/0x80 net/ipv4/netfilter/arp_tables.c:1565

Fixes: f9006acc8d ("netfilter: arp_tables: pass table pointer via nf_hook_ops")
Reported-by: syzbot+dcccba8a1e41a38cb9df@syzkaller.appspotmail.com
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2021-05-03 23:04:01 +02:00
Florian Westphal 47a6959fa3 netfilter: allow to turn off xtables compat layer
The compat layer needs to parse untrusted input (the ruleset)
to translate it to a 64bit compatible format.

We had a number of bugs in this department in the past, so allow users
to turn this feature off.

Add CONFIG_NETFILTER_XTABLES_COMPAT kconfig knob and make it default to y
to keep existing behaviour.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2021-04-26 18:16:56 +02:00
Florian Westphal f9006acc8d netfilter: arp_tables: pass table pointer via nf_hook_ops
Same change as previous patch.  Only difference:
no need to handle NULL template_ops parameter, the only caller
(arptable_filter) always passes non-NULL argument.

This removes all remaining accesses to net->ipv4.arptable_filter.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2021-04-26 03:20:46 +02:00
Florian Westphal ae68933422 netfilter: ip_tables: pass table pointer via nf_hook_ops
iptable_x modules rely on 'struct net' to contain a pointer to the
table that should be evaluated.

In order to remove these pointers from struct net, pass them via
the 'priv' pointer in a similar fashion as nf_tables passes the
rule data.

To do that, duplicate the nf_hook_info array passed in from the
iptable_x modules, update the ops->priv pointers of the copy to
refer to the table and then change the hookfn implementations to
just pass the 'priv' argument to the traverser.

After this patch, the xt_table pointers can already be removed
from struct net.

However, changes to struct net result in re-compile of the entire
network stack, so do the removal after arptables and ip6tables
have been converted as well.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2021-04-26 03:20:46 +02:00
Florian Westphal a4aeafa28c netfilter: xt_nat: pass table to hookfn
This changes how ip(6)table nat passes the ruleset/table to the
evaluation loop.

At the moment, it will fetch the table from struct net.

This change stores the table in the hook_ops 'priv' argument
instead.

This requires to duplicate the hook_ops for each netns, so
they can store the (per-net) xt_table structure.

The dupliated nat hook_ops get stored in net_generic data area.
They are free'd in the namespace exit path.

This is a pre-requisite to remove the xt_table/ruleset pointers
from struct net.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2021-04-26 03:20:46 +02:00
Florian Westphal f68772ed67 netfilter: x_tables: remove paranoia tests
No need for these.
There is only one caller, the xtables core, when the table is registered
for the first time with a particular network namespace.

After ->table_init() call, the table is linked into the tables[af] list,
so next call to that function will skip the ->table_init().

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2021-04-26 03:20:46 +02:00
Florian Westphal 4d70539919 netfilter: arptables: unregister the tables by name
and again, this time for arptables.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2021-04-26 03:20:46 +02:00
Florian Westphal 20a9df3359 netfilter: iptables: unregister the tables by name
xtables stores the xt_table structs in the struct net.  This isn't
needed anymore, the structures could be passed via the netfilter hook
'private' pointer to the hook functions, which would allow us to remove
those pointers from struct net.

As a first step, reduce the number of accesses to the
net->ipv4.ip6table_{raw,filter,...} pointers.
This allows the tables to get unregistered by name instead of having to
pass the raw address.

The xt_table structure cane looked up by name+address family instead.

This patch is useless as-is (the backends still have the raw pointer
address), but it lowers the bar to remove those.

It also allows to put the 'was table registered in the first place' check
into ip_tables.c rather than have it in each table sub module.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2021-04-26 03:20:46 +02:00
Florian Westphal 7716bf090e netfilter: x_tables: remove ipt_unregister_table
Its the same function as ipt_unregister_table_exit.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2021-04-26 03:20:08 +02:00
Florian Westphal de8c12110a netfilter: disable defrag once its no longer needed
When I changed defrag hooks to no longer get registered by default I
intentionally made it so that registration can only be un-done by unloading
the nf_defrag_ipv4/6 module.

In hindsight this was too conservative; there is no reason to keep defrag
on while there is no feature dependency anymore.

Moreover, this won't work if user isn't allowed to remove nf_defrag module.

This adds the disable() functions for both ipv4 and ipv6 and calls them
from conntrack, TPROXY and the xtables socket module.

ipvs isn't converted here, it will behave as before this patch and
will need module removal.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2021-04-26 03:20:07 +02:00
Jakub Kicinski 8203c7ce4e Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
 - keep the ZC code, drop the code related to reinit
net/bridge/netfilter/ebtables.c
 - fix build after move to net_generic

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2021-04-17 11:08:07 -07:00
Florian Westphal b29c457a65 netfilter: x_tables: fix compat match/target pad out-of-bound write
xt_compat_match/target_from_user doesn't check that zeroing the area
to start of next rule won't write past end of allocated ruleset blob.

Remove this code and zero the entire blob beforehand.

Reported-by: syzbot+cfc0247ac173f597aaaa@syzkaller.appspotmail.com
Reported-by: Andy Nguyen <theflow@google.com>
Fixes: 9fa492cdc1 ("[NETFILTER]: x_tables: simplify compat API")
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2021-04-13 00:18:57 +02:00
Florian Westphal d163a925eb netfilter: arp_tables: add pre_exit hook for table unregister
Same problem that also existed in iptables/ip(6)tables, when
arptable_filter is removed there is no longer a wait period before the
table/ruleset is free'd.

Unregister the hook in pre_exit, then remove the table in the exit
function.
This used to work correctly because the old nf_hook_unregister API
did unconditional synchronize_net.

The per-net hook unregister function uses call_rcu instead.

Fixes: b9e69e1273 ("netfilter: xtables: don't hook tables by default")
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2021-04-10 21:18:24 +02:00
Florian Westphal 7b1957b049 netfilter: nf_defrag_ipv4: use net_generic infra
This allows followup patch to remove the defrag_ipv4 member from struct
net.  It also allows to auto-remove the hooks later on by adding a
_disable() function.  This will be done later in a follow patch series.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2021-04-06 00:34:52 +02:00
Florian Westphal f11d61e795 netfilter: nf_log_arp: merge with nf_log_syslog
similar to previous change: nf_log_syslog now covers ARP logging
as well, the old nf_log_arp module is removed.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2021-03-31 00:37:27 +02:00
Florian Westphal db3187ae21 netfilter: nf_log_ipv4: rename to nf_log_syslog
Netfilter has multiple log modules:
 nf_log_arp
 nf_log_bridge
 nf_log_ipv4
 nf_log_ipv6
 nf_log_netdev
 nfnetlink_log
 nf_log_common

With the exception of nfnetlink_log (packet is sent to userspace for
dissection/logging), all of them log to the kernel ringbuffer.

This is the first part of a series to merge all modules except
nfnetlink_log into a single module: nf_log_syslog.

This allows to reduce code.  After the series, only two log modules remain:
nfnetlink_log and nf_log_syslog. The latter provides the same
functionality as the old per-af log modules.

This renames nf_log_ipv4 to nf_log_syslog.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2021-03-31 00:37:27 +02:00
Mark Tomlinson d3d40f2374 Revert "netfilter: x_tables: Switch synchronization to RCU"
This reverts commit cc00bcaa58.

This (and the preceding) patch basically re-implemented the RCU
mechanisms of patch 784544739a. That patch was replaced because of the
performance problems that it created when replacing tables. Now, we have
the same issue: the call to synchronize_rcu() makes replacing tables
slower by as much as an order of magnitude.

Prior to using RCU a script calling "iptables" approx. 200 times was
taking 1.16s. With RCU this increased to 11.59s.

Revert these patches and fix the issue in a different way.

Signed-off-by: Mark Tomlinson <mark.tomlinson@alliedtelesis.co.nz>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2021-03-15 18:42:01 +01:00
Mark Tomlinson abe7034b9a Revert "netfilter: x_tables: Update remaining dereference to RCU"
This reverts commit 443d6e86f8.

This (and the following) patch basically re-implemented the RCU
mechanisms of patch 784544739a. That patch was replaced because of the
performance problems that it created when replacing tables. Now, we have
the same issue: the call to synchronize_rcu() makes replacing tables
slower by as much as an order of magnitude.

Revert these patches and fix the issue in a different way.

Signed-off-by: Mark Tomlinson <mark.tomlinson@alliedtelesis.co.nz>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2021-03-15 18:42:00 +01:00