1. 27 4月, 2021 1 次提交
  2. 26 4月, 2021 1 次提交
  3. 06 4月, 2021 2 次提交
  4. 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
  5. 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
  6. 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
  7. 25 6月, 2020 1 次提交
  8. 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
  9. 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
  10. 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
  11. 18 7月, 2018 3 次提交
  12. 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
  13. 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
  14. 29 5月, 2018 2 次提交
  15. 28 3月, 2018 1 次提交
  16. 09 3月, 2018 1 次提交
  17. 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
  18. 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
  19. 20 6月, 2017 1 次提交
  20. 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
  21. 08 4月, 2017 1 次提交
  22. 21 2月, 2017 1 次提交
  23. 12 2月, 2017 3 次提交
  24. 25 12月, 2016 1 次提交
  25. 19 2月, 2016 1 次提交
  26. 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
  27. 01 2月, 2016 1 次提交
  28. 29 12月, 2015 2 次提交
  29. 15 12月, 2015 1 次提交
  30. 11 12月, 2015 1 次提交
    • P
      netfilter: nfnetlink: fix splat due to incorrect socket memory accounting in skbuff clones · bd678e09
      Pablo Neira Ayuso 提交于
      If we attach the sk to the skb from nfnetlink_rcv_batch(), then
      netlink_skb_destructor() will underflow the socket receive memory
      counter and we get warning splat when releasing the socket.
      
      $ cat /proc/net/netlink
      sk       Eth Pid    Groups   Rmem     Wmem     Dump     Locks     Drops     Inode
      ffff8800ca903000 12  0      00000000 -54144   0        0 2        0        17942
                                           ^^^^^^
      
      Rmem above shows an underflow.
      
      And here below the warning splat:
      
      [ 1363.815976] WARNING: CPU: 2 PID: 1356 at net/netlink/af_netlink.c:958 netlink_sock_destruct+0x80/0xb9()
      [...]
      [ 1363.816152] CPU: 2 PID: 1356 Comm: kworker/u16:1 Tainted: G        W       4.4.0-rc1+ #153
      [ 1363.816155] Hardware name: LENOVO 23259H1/23259H1, BIOS G2ET32WW (1.12 ) 05/30/2012
      [ 1363.816160] Workqueue: netns cleanup_net
      [ 1363.816163]  0000000000000000 ffff880119203dd0 ffffffff81240204 0000000000000000
      [ 1363.816169]  ffff880119203e08 ffffffff8104db4b ffffffff813d49a1 ffff8800ca771000
      [ 1363.816174]  ffffffff81a42b00 0000000000000000 ffff8800c0afe1e0 ffff880119203e18
      [ 1363.816179] Call Trace:
      [ 1363.816181]  <IRQ>  [<ffffffff81240204>] dump_stack+0x4e/0x79
      [ 1363.816193]  [<ffffffff8104db4b>] warn_slowpath_common+0x9a/0xb3
      [ 1363.816197]  [<ffffffff813d49a1>] ? netlink_sock_destruct+0x80/0xb9
      
      skb->sk was only needed to lookup for the netns, however we don't need
      this anymore since 633c9a84 ("netfilter: nfnetlink: avoid recurrent
      netns lookups in call_batch") so this patch removes this manual socket
      assignment to resolve this problem.
      Reported-by: NArturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
      Reported-by: NBen Hutchings <ben@decadent.org.uk>
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      Tested-by: NArturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
      bd678e09