1. 18 7月, 2018 1 次提交
  2. 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
  3. 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
  4. 29 5月, 2018 2 次提交
  5. 28 3月, 2018 1 次提交
  6. 09 3月, 2018 1 次提交
  7. 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
  8. 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
  9. 20 6月, 2017 1 次提交
  10. 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
  11. 08 4月, 2017 1 次提交
  12. 21 2月, 2017 1 次提交
  13. 12 2月, 2017 3 次提交
  14. 25 12月, 2016 1 次提交
  15. 19 2月, 2016 1 次提交
  16. 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
  17. 01 2月, 2016 1 次提交
  18. 29 12月, 2015 2 次提交
  19. 15 12月, 2015 1 次提交
  20. 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
  21. 10 12月, 2015 1 次提交
  22. 09 12月, 2015 1 次提交
    • F
      netfilter: nf_tables: extend tracing infrastructure · 33d5a7b1
      Florian Westphal 提交于
      nft monitor mode can then decode and display this trace data.
      
      Parts of LL/Network/Transport headers are provided as separate
      attributes.
      
      Otherwise, printing IP address data becomes virtually impossible
      for userspace since in the case of the netdev family we really don't
      want userspace to have to know all the possible link layer types
      and/or sizes just to display/print an ip address.
      
      We also don't want userspace to have to follow ipv6 header chains
      to get the s/dport info, the kernel already did this work for us.
      
      To avoid bloating nft_do_chain all data required for tracing is
      encapsulated in nft_traceinfo.
      
      The structure is initialized unconditionally(!) for each nft_do_chain
      invocation.
      
      This unconditionall call will be moved under a static key in a
      followup patch.
      
      With lots of help from Patrick McHardy and Pablo Neira.
      Signed-off-by: NFlorian Westphal <fw@strlen.de>
      Acked-by: NPatrick McHardy <kaber@trash.net>
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      33d5a7b1
  23. 28 10月, 2015 1 次提交
  24. 09 10月, 2015 1 次提交
  25. 29 8月, 2015 1 次提交
    • P
      netfilter: nfnetlink: work around wrong endianess in res_id field · a9de9777
      Pablo Neira Ayuso 提交于
      The convention in nfnetlink is to use network byte order in every header field
      as well as in the attribute payload. The initial version of the batching
      infrastructure assumes that res_id comes in host byte order though.
      
      The only client of the batching infrastructure is nf_tables, so let's add a
      workaround to address this inconsistency. We currently have 11 nfnetlink
      subsystems according to NFNL_SUBSYS_COUNT, so we can assume that the subsystem
      2560, ie. htons(10), will not be allocated anytime soon, so it can be an alias
      of nf_tables from the nfnetlink batching path when interpreting the res_id
      field.
      
      Based on original patch from Florian Westphal.
      Reported-by: NFlorian Westphal <fw@strlen.de>
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      a9de9777
  26. 02 7月, 2015 1 次提交
  27. 07 1月, 2015 2 次提交
  28. 05 1月, 2015 1 次提交
  29. 27 12月, 2014 1 次提交
    • J
      netlink/genetlink: pass network namespace to bind/unbind · 023e2cfa
      Johannes Berg 提交于
      Netlink families can exist in multiple namespaces, and for the most
      part multicast subscriptions are per network namespace. Thus it only
      makes sense to have bind/unbind notifications per network namespace.
      
      To achieve this, pass the network namespace of a given client socket
      to the bind/unbind functions.
      
      Also do this in generic netlink, and there also make sure that any
      bind for multicast groups that only exist in init_net is rejected.
      This isn't really a problem if it is accepted since a client in a
      different namespace will never receive any notifications from such
      a group, but it can confuse the family if not rejected (it's also
      possible to silently (without telling the family) accept it, but it
      would also have to be ignored on unbind so families that take any
      kind of action on bind/unbind won't do unnecessary work for invalid
      clients like that.
      Signed-off-by: NJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      023e2cfa
  30. 17 11月, 2014 1 次提交
    • P
      netfilter: nfnetlink: fix insufficient validation in nfnetlink_bind · 97840cb6
      Pablo Neira Ayuso 提交于
      Make sure the netlink group exists, otherwise you can trigger an out
      of bound array memory access from the netlink_bind() path. This splat
      can only be triggered only by superuser.
      
      [  180.203600] UBSan: Undefined behaviour in ../net/netfilter/nfnetlink.c:467:28
      [  180.204249] index 9 is out of range for type 'int [9]'
      [  180.204697] CPU: 0 PID: 1771 Comm: trinity-main Not tainted 3.18.0-rc4-mm1+ #122
      [  180.205365] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.7.5-0-ge51488c-20140602_164612-nilsson.home.kraxel.org
      +04/01/2014
      [  180.206498]  0000000000000018 0000000000000000 0000000000000009 ffff88007bdf7da8
      [  180.207220]  ffffffff82b0ef5f 0000000000000092 ffffffff845ae2e0 ffff88007bdf7db8
      [  180.207887]  ffffffff8199e489 ffff88007bdf7e18 ffffffff8199ea22 0000003900000000
      [  180.208639] Call Trace:
      [  180.208857] dump_stack (lib/dump_stack.c:52)
      [  180.209370] ubsan_epilogue (lib/ubsan.c:174)
      [  180.209849] __ubsan_handle_out_of_bounds (lib/ubsan.c:400)
      [  180.210512] nfnetlink_bind (net/netfilter/nfnetlink.c:467)
      [  180.210986] netlink_bind (net/netlink/af_netlink.c:1483)
      [  180.211495] SYSC_bind (net/socket.c:1541)
      
      Moreover, define the missing nf_tables and nf_acct multicast groups too.
      Reported-by: NAndrey Ryabinin <a.ryabinin@samsung.com>
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      97840cb6
  31. 19 9月, 2014 1 次提交
  32. 03 9月, 2014 1 次提交
    • P
      netfilter: nfnetlink: deliver netlink errors on batch completion · cbb8125e
      Pablo Neira Ayuso 提交于
      We have to wait until the full batch has been processed to deliver the
      netlink error messages to userspace. Otherwise, we may deliver
      duplicated errors to userspace in case that we need to abort and replay
      the transaction if any of the required modules needs to be autoloaded.
      
      A simple way to reproduce this (assumming nft_meta is not loaded) with
      the following test file:
      
       add table filter
       add chain filter test
       add chain bad test                 # intentional wrong unexistent table
       add rule filter test meta mark 0
      
      Then, when trying to load the batch:
      
       # nft -f test
       test:4:1-19: Error: Could not process rule: No such file or directory
       add chain bad test
       ^^^^^^^^^^^^^^^^^^^
       test:4:1-19: Error: Could not process rule: No such file or directory
       add chain bad test
       ^^^^^^^^^^^^^^^^^^^
      
      The error is reported twice, once when the batch is aborted due to
      missing nft_meta and another when it is fully processed.
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      cbb8125e