1. 07 6月, 2021 2 次提交
  2. 05 5月, 2021 1 次提交
    • E
      netfilter: nfnetlink: add a missing rcu_read_unlock() · 7072a355
      Eric Dumazet 提交于
      Reported by syzbot :
      BUG: sleeping function called from invalid context at include/linux/sched/mm.h:201
      in_atomic(): 0, irqs_disabled(): 0, non_block: 0, pid: 26899, name: syz-executor.5
      1 lock held by syz-executor.5/26899:
       #0: ffffffff8bf797a0 (rcu_read_lock){....}-{1:2}, at: nfnetlink_get_subsys net/netfilter/nfnetlink.c:148 [inline]
       #0: ffffffff8bf797a0 (rcu_read_lock){....}-{1:2}, at: nfnetlink_rcv_msg+0x1da/0x1300 net/netfilter/nfnetlink.c:226
      Preemption disabled at:
      [<ffffffff8917799e>] preempt_schedule_irq+0x3e/0x90 kernel/sched/core.c:5533
      CPU: 1 PID: 26899 Comm: syz-executor.5 Not tainted 5.12.0-next-20210504-syzkaller #0
      Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
      Call Trace:
       __dump_stack lib/dump_stack.c:79 [inline]
       dump_stack+0x141/0x1d7 lib/dump_stack.c:120
       ___might_sleep.cold+0x1f1/0x237 kernel/sched/core.c:8338
       might_alloc include/linux/sched/mm.h:201 [inline]
       slab_pre_alloc_hook mm/slab.h:500 [inline]
       slab_alloc_node mm/slub.c:2845 [inline]
       kmem_cache_alloc_node+0x33d/0x3e0 mm/slub.c:2960
       __alloc_skb+0x20b/0x340 net/core/skbuff.c:413
       alloc_skb include/linux/skbuff.h:1107 [inline]
       nlmsg_new include/net/netlink.h:953 [inline]
       netlink_ack+0x1ed/0xaa0 net/netlink/af_netlink.c:2437
       netlink_rcv_skb+0x33d/0x420 net/netlink/af_netlink.c:2508
       nfnetlink_rcv+0x1ac/0x420 net/netfilter/nfnetlink.c:650
       netlink_unicast_kernel net/netlink/af_netlink.c:1312 [inline]
       netlink_unicast+0x533/0x7d0 net/netlink/af_netlink.c:1338
       netlink_sendmsg+0x856/0xd90 net/netlink/af_netlink.c:1927
       sock_sendmsg_nosec net/socket.c:654 [inline]
       sock_sendmsg+0xcf/0x120 net/socket.c:674
       ____sys_sendmsg+0x6e8/0x810 net/socket.c:2350
       ___sys_sendmsg+0xf3/0x170 net/socket.c:2404
       __sys_sendmsg+0xe5/0x1b0 net/socket.c:2433
       do_syscall_64+0x3a/0xb0 arch/x86/entry/common.c:47
       entry_SYSCALL_64_after_hwframe+0x44/0xae
      RIP: 0033:0x4665f9
      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 bc ff ff ff f7 d8 64 89 01 48
      RSP: 002b:00007fa8a03ee188 EFLAGS: 00000246 ORIG_RAX: 000000000000002e
      RAX: ffffffffffffffda RBX: 000000000056bf60 RCX: 00000000004665f9
      RDX: 0000000000000000 RSI: 0000000020000480 RDI: 0000000000000004
      RBP: 00000000004bfce1 R08: 0000000000000000 R09: 0000000000000000
      R10: 0000000000000000 R11: 0000000000000246 R12: 000000000056bf60
      R13: 00007fffe864480f R14: 00007fa8a03ee300 R15: 0000000000022000
      
      ================================================
      WARNING: lock held when returning to user space!
      5.12.0-next-20210504-syzkaller #0 Tainted: G        W
      ------------------------------------------------
      syz-executor.5/26899 is leaving the kernel with locks still held!
      1 lock held by syz-executor.5/26899:
       #0: ffffffff8bf797a0 (rcu_read_lock){....}-{1:2}, at: nfnetlink_get_subsys net/netfilter/nfnetlink.c:148 [inline]
       #0: ffffffff8bf797a0 (rcu_read_lock){....}-{1:2}, at: nfnetlink_rcv_msg+0x1da/0x1300 net/netfilter/nfnetlink.c:226
      ------------[ cut here ]------------
      WARNING: CPU: 0 PID: 26899 at kernel/rcu/tree_plugin.h:359 rcu_note_context_switch+0xfd/0x16e0 kernel/rcu/tree_plugin.h:359
      Modules linked in:
      CPU: 0 PID: 26899 Comm: syz-executor.5 Tainted: G        W         5.12.0-next-20210504-syzkaller #0
      Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
      RIP: 0010:rcu_note_context_switch+0xfd/0x16e0 kernel/rcu/tree_plugin.h:359
      Code: 48 89 fa 48 c1 ea 03 0f b6 14 02 48 89 f8 83 e0 07 83 c0 03 38 d0 7c 08 84 d2 0f 85 2e 0d 00 00 8b bd cc 03 00 00 85 ff 7e 02 <0f> 0b 65 48 8b 2c 25 00 f0 01 00 48 8d bd cc 03 00 00 48 b8 00 00
      RSP: 0000:ffffc90002fffdb0 EFLAGS: 00010002
      RAX: 0000000000000007 RBX: ffff8880b9c36080 RCX: ffffffff8dc99bac
      RDX: 0000000000000000 RSI: 0000000000000008 RDI: 0000000000000001
      RBP: ffff88808b9d1c80 R08: 0000000000000000 R09: ffffffff8dc96917
      R10: fffffbfff1b92d22 R11: 0000000000000000 R12: 0000000000000000
      R13: ffff88808b9d1c80 R14: ffff88808b9d1c80 R15: ffffc90002ff8000
      FS:  00007fa8a03ee700(0000) GS:ffff8880b9c00000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      CR2: 00007f09896ed000 CR3: 0000000032070000 CR4: 00000000001526f0
      DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
      DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
      Call Trace:
       __schedule+0x214/0x23e0 kernel/sched/core.c:5044
       schedule+0xcf/0x270 kernel/sched/core.c:5226
       exit_to_user_mode_loop kernel/entry/common.c:162 [inline]
       exit_to_user_mode_prepare+0x13e/0x280 kernel/entry/common.c:208
       irqentry_exit_to_user_mode+0x5/0x40 kernel/entry/common.c:314
       asm_sysvec_reschedule_ipi+0x12/0x20 arch/x86/include/asm/idtentry.h:637
      RIP: 0033:0x4665f9
      
      Fixes: 50f2db9e ("netfilter: nfnetlink: consolidate callback types")
      Signed-off-by: NEric Dumazet <edumazet@google.com>
      Reported-by: Nsyzbot <syzkaller@googlegroups.com>
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      7072a355
  3. 27 4月, 2021 3 次提交
  4. 26 4月, 2021 1 次提交
  5. 06 4月, 2021 2 次提交
  6. 30 10月, 2020 1 次提交
    • P
      netfilter: nf_tables: missing validation from the abort path · c0391b6a
      Pablo Neira Ayuso 提交于
      If userspace does not include the trailing end of batch message, then
      nfnetlink aborts the transaction. This allows to check that ruleset
      updates trigger no errors.
      
      After this patch, invoking this command from the prerouting chain:
      
       # nft -c add rule x y fib saddr . oif type local
      
      fails since oif is not supported there.
      
      This patch fixes the lack of rule validation from the abort/check path
      to catch configuration errors such as the one above.
      
      Fixes: a654de8f ("netfilter: nf_tables: fix chain dependency validation")
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      c0391b6a
  7. 05 10月, 2020 1 次提交
    • F
      netfilter: nfnetlink: place subsys mutexes in distinct lockdep classes · ab6c41ee
      Florian Westphal 提交于
      From time to time there are lockdep reports similar to this one:
      
       WARNING: possible circular locking dependency detected
       ------------------------------------------------------
       000000004f61aa56 (&table[i].mutex){+.+.}, at: nfnl_lock [nfnetlink]
       but task is already holding lock:
       [..] (&net->nft.commit_mutex){+.+.}, at: nf_tables_valid_genid [nf_tables]
       which lock already depends on the new lock.
       the existing dependency chain (in reverse order) is:
       -> #1 (&net->nft.commit_mutex){+.+.}:
       [..]
              nf_tables_valid_genid+0x18/0x60 [nf_tables]
              nfnetlink_rcv_batch+0x24c/0x620 [nfnetlink]
              nfnetlink_rcv+0x110/0x140 [nfnetlink]
              netlink_unicast+0x12c/0x1e0
       [..]
              sys_sendmsg+0x18/0x40
              linux_sparc_syscall+0x34/0x44
       -> #0 (&table[i].mutex){+.+.}:
       [..]
              nfnl_lock+0x24/0x40 [nfnetlink]
              ip_set_nfnl_get_byindex+0x19c/0x280 [ip_set]
              set_match_v1_checkentry+0x14/0xc0 [xt_set]
              xt_check_match+0x238/0x260 [x_tables]
              __nft_match_init+0x160/0x180 [nft_compat]
       [..]
              sys_sendmsg+0x18/0x40
              linux_sparc_syscall+0x34/0x44
       other info that might help us debug this:
        Possible unsafe locking scenario:
              CPU0                    CPU1
              ----                    ----
         lock(&net->nft.commit_mutex);
                                      lock(&table[i].mutex);
                                      lock(&net->nft.commit_mutex);
         lock(&table[i].mutex);
      
      Lockdep considers this an ABBA deadlock because the different nfnl subsys
      mutexes reside in the same lockdep class, but this is a false positive.
      
      CPU1 table[i] refers to the nftables subsys mutex, whereas CPU1 locks
      the ipset subsys mutex.
      
      Yi Che reported a similar lockdep splat, this time between ipset and
      ctnetlink subsys mutexes.
      
      Time to place them in distinct classes to avoid these warnings.
      Signed-off-by: NFlorian Westphal <fw@strlen.de>
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      ab6c41ee
  8. 29 8月, 2020 1 次提交
    • P
      netfilter: nfnetlink: nfnetlink_unicast() reports EAGAIN instead of ENOBUFS · ee921183
      Pablo Neira Ayuso 提交于
      Frontend callback reports EAGAIN to nfnetlink to retry a command, this
      is used to signal that module autoloading is required. Unfortunately,
      nlmsg_unicast() reports EAGAIN in case the receiver socket buffer gets
      full, so it enters a busy-loop.
      
      This patch updates nfnetlink_unicast() to turn EAGAIN into ENOBUFS and
      to use nlmsg_unicast(). Remove the flags field in nfnetlink_unicast()
      since this is always MSG_DONTWAIT in the existing code which is exactly
      what nlmsg_unicast() passes to netlink_unicast() as parameter.
      
      Fixes: 96518518 ("netfilter: add nftables")
      Reported-by: NPhil Sutter <phil@nwl.cc>
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      ee921183
  9. 25 6月, 2020 1 次提交
  10. 25 1月, 2020 1 次提交
    • P
      netfilter: nf_tables: autoload modules from the abort path · eb014de4
      Pablo Neira Ayuso 提交于
      This patch introduces a list of pending module requests. This new module
      list is composed of nft_module_request objects that contain the module
      name and one status field that tells if the module has been already
      loaded (the 'done' field).
      
      In the first pass, from the preparation phase, the netlink command finds
      that a module is missing on this list. Then, a module request is
      allocated and added to this list and nft_request_module() returns
      -EAGAIN. This triggers the abort path with the autoload parameter set on
      from nfnetlink, request_module() is called and the module request enters
      the 'done' state. Since the mutex is released when loading modules from
      the abort phase, the module list is zapped so this is iteration occurs
      over a local list. Therefore, the request_module() calls happen when
      object lists are in consistent state (after fulling aborting the
      transaction) and the commit list is empty.
      
      On the second pass, the netlink command will find that it already tried
      to load the module, so it does not request it again and
      nft_request_module() returns 0. Then, there is a look up to find the
      object that the command was missing. If the module was successfully
      loaded, the command proceeds normally since it finds the missing object
      in place, otherwise -ENOENT is reported to userspace.
      
      This patch also updates nfnetlink to include the reason to enter the
      abort phase, which is required for this new autoload module rationale.
      
      Fixes: ec7470b8 ("netfilter: nf_tables: store transaction list locally while requesting module")
      Reported-by: syzbot+29125d208b3dae9a7019@syzkaller.appspotmail.com
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      eb014de4
  11. 15 7月, 2019 1 次提交
    • F
      netfilter: nfnetlink: avoid deadlock due to synchronous request_module · 1b0890cd
      Florian Westphal 提交于
      Thomas and Juliana report a deadlock when running:
      
      (rmmod nf_conntrack_netlink/xfrm_user)
      
        conntrack -e NEW -E &
        modprobe -v xfrm_user
      
      They provided following analysis:
      
      conntrack -e NEW -E
          netlink_bind()
              netlink_lock_table() -> increases "nl_table_users"
                  nfnetlink_bind()
                  # does not unlock the table as it's locked by netlink_bind()
                      __request_module()
                          call_usermodehelper_exec()
      
      This triggers "modprobe nf_conntrack_netlink" from kernel, netlink_bind()
      won't return until modprobe process is done.
      
      "modprobe xfrm_user":
          xfrm_user_init()
              register_pernet_subsys()
                  -> grab pernet_ops_rwsem
                      ..
                      netlink_table_grab()
                          calls schedule() as "nl_table_users" is non-zero
      
      so modprobe is blocked because netlink_bind() increased
      nl_table_users while also holding pernet_ops_rwsem.
      
      "modprobe nf_conntrack_netlink" runs and inits nf_conntrack_netlink:
          ctnetlink_init()
              register_pernet_subsys()
                  -> blocks on "pernet_ops_rwsem" thanks to xfrm_user module
      
      both modprobe processes wait on one another -- neither can make
      progress.
      
      Switch netlink_bind() to "nowait" modprobe -- this releases the netlink
      table lock, which then allows both modprobe instances to complete.
      Reported-by: NThomas Jarosch <thomas.jarosch@intra2net.com>
      Reported-by: NJuliana Rodrigueiro <juliana.rodrigueiro@intra2net.com>
      Signed-off-by: NFlorian Westphal <fw@strlen.de>
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      1b0890cd
  12. 28 4月, 2019 1 次提交
    • J
      netlink: make validation more configurable for future strictness · 8cb08174
      Johannes Berg 提交于
      We currently have two levels of strict validation:
      
       1) liberal (default)
           - undefined (type >= max) & NLA_UNSPEC attributes accepted
           - attribute length >= expected accepted
           - garbage at end of message accepted
       2) strict (opt-in)
           - NLA_UNSPEC attributes accepted
           - attribute length >= expected accepted
      
      Split out parsing strictness into four different options:
       * TRAILING     - check that there's no trailing data after parsing
                        attributes (in message or nested)
       * MAXTYPE      - reject attrs > max known type
       * UNSPEC       - reject attributes with NLA_UNSPEC policy entries
       * STRICT_ATTRS - strictly validate attribute size
      
      The default for future things should be *everything*.
      The current *_strict() is a combination of TRAILING and MAXTYPE,
      and is renamed to _deprecated_strict().
      The current regular parsing has none of this, and is renamed to
      *_parse_deprecated().
      
      Additionally it allows us to selectively set one of the new flags
      even on old policies. Notably, the UNSPEC flag could be useful in
      this case, since it can be arranged (by filling in the policy) to
      not be an incompatible userspace ABI change, but would then going
      forward prevent forgetting attribute entries. Similar can apply
      to the POLICY flag.
      
      We end up with the following renames:
       * nla_parse           -> nla_parse_deprecated
       * nla_parse_strict    -> nla_parse_deprecated_strict
       * nlmsg_parse         -> nlmsg_parse_deprecated
       * nlmsg_parse_strict  -> nlmsg_parse_deprecated_strict
       * nla_parse_nested    -> nla_parse_nested_deprecated
       * nla_validate_nested -> nla_validate_nested_deprecated
      
      Using spatch, of course:
          @@
          expression TB, MAX, HEAD, LEN, POL, EXT;
          @@
          -nla_parse(TB, MAX, HEAD, LEN, POL, EXT)
          +nla_parse_deprecated(TB, MAX, HEAD, LEN, POL, EXT)
      
          @@
          expression NLH, HDRLEN, TB, MAX, POL, EXT;
          @@
          -nlmsg_parse(NLH, HDRLEN, TB, MAX, POL, EXT)
          +nlmsg_parse_deprecated(NLH, HDRLEN, TB, MAX, POL, EXT)
      
          @@
          expression NLH, HDRLEN, TB, MAX, POL, EXT;
          @@
          -nlmsg_parse_strict(NLH, HDRLEN, TB, MAX, POL, EXT)
          +nlmsg_parse_deprecated_strict(NLH, HDRLEN, TB, MAX, POL, EXT)
      
          @@
          expression TB, MAX, NLA, POL, EXT;
          @@
          -nla_parse_nested(TB, MAX, NLA, POL, EXT)
          +nla_parse_nested_deprecated(TB, MAX, NLA, POL, EXT)
      
          @@
          expression START, MAX, POL, EXT;
          @@
          -nla_validate_nested(START, MAX, POL, EXT)
          +nla_validate_nested_deprecated(START, MAX, POL, EXT)
      
          @@
          expression NLH, HDRLEN, MAX, POL, EXT;
          @@
          -nlmsg_validate(NLH, HDRLEN, MAX, POL, EXT)
          +nlmsg_validate_deprecated(NLH, HDRLEN, MAX, POL, EXT)
      
      For this patch, don't actually add the strict, non-renamed versions
      yet so that it breaks compile if I get it wrong.
      
      Also, while at it, make nla_validate and nla_parse go down to a
      common __nla_validate_parse() function to avoid code duplication.
      
      Ultimately, this allows us to have very strict validation for every
      new caller of nla_parse()/nlmsg_parse() etc as re-introduced in the
      next patch, while existing things will continue to work as is.
      
      In effect then, this adds fully strict validation for any new command.
      Signed-off-by: NJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      8cb08174
  13. 18 7月, 2018 3 次提交
  14. 13 6月, 2018 1 次提交
    • F
      netfilter: nf_tables: fix module unload race · 71ad00c5
      Florian Westphal 提交于
      We must first remove the nfnetlink protocol handler when nf_tables module
      is unloaded -- we don't want userspace to submit new change requests once
      we've started to tear down nft state.
      
      Furthermore, nfnetlink must not call any subsystem function after
      call_batch returned -EAGAIN.
      
      EAGAIN means the subsys mutex was dropped, so its unlikely but possible that
      nf_tables subsystem was removed due to 'rmmod nf_tables' on another cpu.
      
      Therefore, we must abort batch completely and not move on to next part of
      the batch.
      
      Last, we can't invoke ->abort unless we've checked that the subsystem is
      still registered.
      
      Change netns exit path of nf_tables to make sure any incompleted
      transaction gets removed on exit.
      Signed-off-by: NFlorian Westphal <fw@strlen.de>
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      71ad00c5
  15. 01 6月, 2018 2 次提交
    • K
      netfilter: nfnetlink: Remove VLA usage · 7b7744e2
      Kees Cook 提交于
      In the quest to remove all stack VLA usage from the kernel[1], this
      allocates the maximum size expected for all possible attrs and adds
      sanity-checks at both registration and usage to make sure nothing
      gets out of sync.
      
      [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.comSigned-off-by: NKees Cook <keescook@chromium.org>
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      7b7744e2
    • P
      netfilter: nf_tables: fix chain dependency validation · a654de8f
      Pablo Neira Ayuso 提交于
      The following ruleset:
      
       add table ip filter
       add chain ip filter input { type filter hook input priority 4; }
       add chain ip filter ap
       add rule ip filter input jump ap
       add rule ip filter ap masquerade
      
      results in a panic, because the masquerade extension should be rejected
      from the filter chain. The existing validation is missing a chain
      dependency check when the rule is added to the non-base chain.
      
      This patch fixes the problem by walking down the rules from the
      basechains, searching for either immediate or lookup expressions, then
      jumping to non-base chains and again walking down the rules to perform
      the expression validation, so we make sure the full ruleset graph is
      validated. This is done only once from the commit phase, in case of
      problem, we abort the transaction and perform fine grain validation for
      error reporting. This patch requires 00308791 ("netfilter:
      nfnetlink: allow commit to fail") to achieve this behaviour.
      
      This patch also adds a cleanup callback to nfnl batch interface to reset
      the validate state from the exit path.
      
      As a result of this patch, nf_tables_check_loops() doesn't use
      ->validate to check for loops, instead it just checks for immediate
      expressions.
      Reported-by: NTaehee Yoo <ap420073@gmail.com>
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      a654de8f
  16. 29 5月, 2018 2 次提交
  17. 28 3月, 2018 1 次提交
  18. 09 3月, 2018 1 次提交
  19. 20 1月, 2018 1 次提交
    • P
      netfilter: remove messages print and boot/module load time · e5531166
      Pablo Neira Ayuso 提交于
      Several reasons for this:
      
      * Several modules maintain internal version numbers, that they print at
        boot/module load time, that are not exposed to userspace, as a
        primitive mechanism to make revision number control from the earlier
        days of Netfilter.
      
      * IPset shows the protocol version at boot/module load time, instead
        display this via module description, as Jozsef suggested.
      
      * Remove copyright notice at boot/module load time in two spots, the
        Netfilter codebase is a collective development effort, if we would
        have to display copyrights for each contributor at boot/module load
        time for each extensions we have, we would probably fill up logs with
        lots of useless information - from a technical standpoint.
      
      So let's be consistent and remove them all.
      Acked-by: NFlorian Westphal <fw@strlen.de>
      Acked-by: NJozsef Kadlecsik <kadlec@blackhole.kfki.hu>
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      e5531166
  20. 17 7月, 2017 1 次提交
    • M
      netfilter: nfnetlink: Improve input length sanitization in nfnetlink_rcv · f55ce7b0
      Mateusz Jurczyk 提交于
      Verify that the length of the socket buffer is sufficient to cover the
      nlmsghdr structure before accessing the nlh->nlmsg_len field for further
      input sanitization. If the client only supplies 1-3 bytes of data in
      sk_buff, then nlh->nlmsg_len remains partially uninitialized and
      contains leftover memory from the corresponding kernel allocation.
      Operating on such data may result in indeterminate evaluation of the
      nlmsg_len < NLMSG_HDRLEN expression.
      
      The bug was discovered by a runtime instrumentation designed to detect
      use of uninitialized memory in the kernel. The patch prevents this and
      other similar tools (e.g. KMSAN) from flagging this behavior in the future.
      Signed-off-by: NMateusz Jurczyk <mjurczyk@google.com>
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      f55ce7b0
  21. 20 6月, 2017 1 次提交
  22. 14 4月, 2017 3 次提交
    • J
      netlink: pass extended ACK struct where available · fe52145f
      Johannes Berg 提交于
      This is an add-on to the previous patch that passes the extended ACK
      structure where it's already available by existing genl_info or extack
      function arguments.
      
      This was done with this spatch (with some manual adjustment of
      indentation):
      
      @@
      expression A, B, C, D, E;
      identifier fn, info;
      @@
      fn(..., struct genl_info *info, ...) {
      ...
      -nlmsg_parse(A, B, C, D, E, NULL)
      +nlmsg_parse(A, B, C, D, E, info->extack)
      ...
      }
      
      @@
      expression A, B, C, D, E;
      identifier fn, info;
      @@
      fn(..., struct genl_info *info, ...) {
      <...
      -nla_parse_nested(A, B, C, D, NULL)
      +nla_parse_nested(A, B, C, D, info->extack)
      ...>
      }
      
      @@
      expression A, B, C, D, E;
      identifier fn, extack;
      @@
      fn(..., struct netlink_ext_ack *extack, ...) {
      <...
      -nlmsg_parse(A, B, C, D, E, NULL)
      +nlmsg_parse(A, B, C, D, E, extack)
      ...>
      }
      
      @@
      expression A, B, C, D, E;
      identifier fn, extack;
      @@
      fn(..., struct netlink_ext_ack *extack, ...) {
      <...
      -nla_parse(A, B, C, D, E, NULL)
      +nla_parse(A, B, C, D, E, extack)
      ...>
      }
      
      @@
      expression A, B, C, D, E;
      identifier fn, extack;
      @@
      fn(..., struct netlink_ext_ack *extack, ...) {
      ...
      -nlmsg_parse(A, B, C, D, E, NULL)
      +nlmsg_parse(A, B, C, D, E, extack)
      ...
      }
      
      @@
      expression A, B, C, D;
      identifier fn, extack;
      @@
      fn(..., struct netlink_ext_ack *extack, ...) {
      <...
      -nla_parse_nested(A, B, C, D, NULL)
      +nla_parse_nested(A, B, C, D, extack)
      ...>
      }
      
      @@
      expression A, B, C, D;
      identifier fn, extack;
      @@
      fn(..., struct netlink_ext_ack *extack, ...) {
      <...
      -nlmsg_validate(A, B, C, D, NULL)
      +nlmsg_validate(A, B, C, D, extack)
      ...>
      }
      
      @@
      expression A, B, C, D;
      identifier fn, extack;
      @@
      fn(..., struct netlink_ext_ack *extack, ...) {
      <...
      -nla_validate(A, B, C, D, NULL)
      +nla_validate(A, B, C, D, extack)
      ...>
      }
      
      @@
      expression A, B, C;
      identifier fn, extack;
      @@
      fn(..., struct netlink_ext_ack *extack, ...) {
      <...
      -nla_validate_nested(A, B, C, NULL)
      +nla_validate_nested(A, B, C, extack)
      ...>
      }
      Signed-off-by: NJohannes Berg <johannes.berg@intel.com>
      Reviewed-by: NJiri Pirko <jiri@mellanox.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      fe52145f
    • J
      netlink: pass extended ACK struct to parsing functions · fceb6435
      Johannes Berg 提交于
      Pass the new extended ACK reporting struct to all of the generic
      netlink parsing functions. For now, pass NULL in almost all callers
      (except for some in the core.)
      Signed-off-by: NJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      fceb6435
    • J
      netlink: extended ACK reporting · 2d4bc933
      Johannes Berg 提交于
      Add the base infrastructure and UAPI for netlink extended ACK
      reporting. All "manual" calls to netlink_ack() pass NULL for now and
      thus don't get extended ACK reporting.
      
      Big thanks goes to Pablo Neira Ayuso for not only bringing up the
      whole topic at netconf (again) but also coming up with the nlattr
      passing trick and various other ideas.
      Signed-off-by: NJohannes Berg <johannes.berg@intel.com>
      Reviewed-by: NDavid Ahern <dsa@cumulusnetworks.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      2d4bc933
  23. 08 4月, 2017 1 次提交
  24. 21 2月, 2017 1 次提交
  25. 12 2月, 2017 3 次提交
  26. 25 12月, 2016 1 次提交
  27. 19 2月, 2016 1 次提交
  28. 08 2月, 2016 1 次提交
    • P
      netfilter: nfnetlink: correctly validate length of batch messages · c58d6c93
      Phil Turnbull 提交于
      If nlh->nlmsg_len is zero then an infinite loop is triggered because
      'skb_pull(skb, msglen);' pulls zero bytes.
      
      The calculation in nlmsg_len() underflows if 'nlh->nlmsg_len <
      NLMSG_HDRLEN' which bypasses the length validation and will later
      trigger an out-of-bound read.
      
      If the length validation does fail then the malformed batch message is
      copied back to userspace. However, we cannot do this because the
      nlh->nlmsg_len can be invalid. This leads to an out-of-bounds read in
      netlink_ack:
      
          [   41.455421] ==================================================================
          [   41.456431] BUG: KASAN: slab-out-of-bounds in memcpy+0x1d/0x40 at addr ffff880119e79340
          [   41.456431] Read of size 4294967280 by task a.out/987
          [   41.456431] =============================================================================
          [   41.456431] BUG kmalloc-512 (Not tainted): kasan: bad access detected
          [   41.456431] -----------------------------------------------------------------------------
          ...
          [   41.456431] Bytes b4 ffff880119e79310: 00 00 00 00 d5 03 00 00 b0 fb fe ff 00 00 00 00  ................
          [   41.456431] Object ffff880119e79320: 20 00 00 00 10 00 05 00 00 00 00 00 00 00 00 00   ...............
          [   41.456431] Object ffff880119e79330: 14 00 0a 00 01 03 fc 40 45 56 11 22 33 10 00 05  .......@EV."3...
          [   41.456431] Object ffff880119e79340: f0 ff ff ff 88 99 aa bb 00 14 00 0a 00 06 fe fb  ................
                                                  ^^ start of batch nlmsg with
                                                     nlmsg_len=4294967280
          ...
          [   41.456431] Memory state around the buggy address:
          [   41.456431]  ffff880119e79400: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
          [   41.456431]  ffff880119e79480: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
          [   41.456431] >ffff880119e79500: 00 00 00 00 fc fc fc fc fc fc fc fc fc fc fc fc
          [   41.456431]                                ^
          [   41.456431]  ffff880119e79580: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
          [   41.456431]  ffff880119e79600: fc fc fc fc fc fc fc fc fc fc fb fb fb fb fb fb
          [   41.456431] ==================================================================
      
      Fix this with better validation of nlh->nlmsg_len and by setting
      NFNL_BATCH_FAILURE if any batch message fails length validation.
      
      CAP_NET_ADMIN is required to trigger the bugs.
      
      Fixes: 9ea2aa8b ("netfilter: nfnetlink: validate nfnetlink header from batch")
      Signed-off-by: NPhil Turnbull <phil.turnbull@oracle.com>
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      c58d6c93