1. 09 2月, 2021 2 次提交
  2. 27 12月, 2019 1 次提交
  3. 28 9月, 2018 1 次提交
  4. 11 7月, 2018 1 次提交
    • T
      netfilter: Add nf_ct_get_tuple_skb global lookup function · b60a6040
      Toke Høiland-Jørgensen 提交于
      This adds a global netfilter function to extract a conntrack tuple from an
      skb. The function uses a new function added to nf_ct_hook, which will try
      to get the tuple from skb->_nfct, and do a full lookup if that fails. This
      makes it possible to use the lookup function before the skb has passed
      through the conntrack init hooks (e.g., in an ingress qdisc). The tuple is
      copied to the caller to avoid issues with reference counting.
      
      The function returns false if conntrack is not loaded, allowing it to be
      used without incurring a module dependency on conntrack. This is used by
      the NAT mode in sch_cake.
      
      Cc: netfilter-devel@vger.kernel.org
      Signed-off-by: NToke Høiland-Jørgensen <toke@toke.dk>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      b60a6040
  5. 10 7月, 2018 1 次提交
  6. 04 7月, 2018 1 次提交
    • E
      net: ipv4: listified version of ip_rcv · 17266ee9
      Edward Cree 提交于
      Also involved adding a way to run a netfilter hook over a list of packets.
       Rather than attempting to make netfilter know about lists (which would be
       a major project in itself) we just let it call the regular okfn (in this
       case ip_rcv_finish()) for any packets it steals, and have it give us back
       a list of packets it's synchronously accepted (which normally NF_HOOK
       would automatically call okfn() on, but we want to be able to potentially
       pass the list to a listified version of okfn().)
      The netfilter hooks themselves are indirect calls that still happen per-
       packet (see nf_hook_entry_hookfn()), but again, changing that can be left
       for future work.
      
      There is potential for out-of-order receives if the netfilter hook ends up
       synchronously stealing packets, as they will be processed before any
       accepts earlier in the list.  However, it was already possible for an
       asynchronous accept to cause out-of-order receives, so presumably this is
       considered OK.
      Signed-off-by: NEdward Cree <ecree@solarflare.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      17266ee9
  7. 13 6月, 2018 1 次提交
    • P
      netfilter: fix null-ptr-deref in nf_nat_decode_session · 155fb5c5
      Prashant Bhole 提交于
      Add null check for nat_hook in nf_nat_decode_session()
      
      [  195.648098] UBSAN: Undefined behaviour in ./include/linux/netfilter.h:348:14
      [  195.651366] BUG: KASAN: null-ptr-deref in __xfrm_policy_check+0x208/0x1d70
      [  195.653888] member access within null pointer of type 'struct nf_nat_hook'
      [  195.653896] CPU: 3 PID: 0 Comm: swapper/3 Not tainted 4.17.0-rc6+ #5
      [  195.656320] Read of size 8 at addr 0000000000000008 by task ping/2469
      [  195.658715] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1ubuntu1 04/01/2014
      [  195.658721] Call Trace:
      [  195.661087]
      [  195.669341]  <IRQ>
      [  195.670574]  dump_stack+0xc6/0x150
      [  195.672156]  ? dump_stack_print_info.cold.0+0x1b/0x1b
      [  195.674121]  ? ubsan_prologue+0x31/0x92
      [  195.676546]  ubsan_epilogue+0x9/0x49
      [  195.678159]  handle_null_ptr_deref+0x11a/0x130
      [  195.679800]  ? sprint_OID+0x1a0/0x1a0
      [  195.681322]  __ubsan_handle_type_mismatch_v1+0xd5/0x11d
      [  195.683146]  ? ubsan_prologue+0x92/0x92
      [  195.684642]  __xfrm_policy_check+0x18ef/0x1d70
      [  195.686294]  ? rt_cache_valid+0x118/0x180
      [  195.687804]  ? __xfrm_route_forward+0x410/0x410
      [  195.689463]  ? fib_multipath_hash+0x700/0x700
      [  195.691109]  ? kvm_sched_clock_read+0x23/0x40
      [  195.692805]  ? pvclock_clocksource_read+0xf6/0x280
      [  195.694409]  ? graph_lock+0xa0/0xa0
      [  195.695824]  ? pvclock_clocksource_read+0xf6/0x280
      [  195.697508]  ? pvclock_read_flags+0x80/0x80
      [  195.698981]  ? kvm_sched_clock_read+0x23/0x40
      [  195.700347]  ? sched_clock+0x5/0x10
      [  195.701525]  ? sched_clock_cpu+0x18/0x1a0
      [  195.702846]  tcp_v4_rcv+0x1d32/0x1de0
      [  195.704115]  ? lock_repin_lock+0x70/0x270
      [  195.707072]  ? pvclock_read_flags+0x80/0x80
      [  195.709302]  ? tcp_v4_early_demux+0x4b0/0x4b0
      [  195.711833]  ? lock_acquire+0x195/0x380
      [  195.714222]  ? ip_local_deliver_finish+0xfc/0x770
      [  195.716967]  ? raw_rcv+0x2b0/0x2b0
      [  195.718856]  ? lock_release+0xa00/0xa00
      [  195.720938]  ip_local_deliver_finish+0x1b9/0x770
      [...]
      
      Fixes: 2c205dd3 ("netfilter: add struct nf_nat_hook and use it")
      Signed-off-by: NPrashant Bhole <bhole_prashant_q7@lab.ntt.co.jp>
      Acked-by: NFlorian Westphal <fw@strlen.de>
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      155fb5c5
  8. 23 5月, 2018 4 次提交
  9. 09 1月, 2018 12 次提交
    • P
      netfilter: remove struct nf_afinfo and its helper functions · b3a61254
      Pablo Neira Ayuso 提交于
      This abstraction has no clients anymore, remove it.
      
      This is what remains from previous authors, so correct copyright
      statement after recent modifications and code removal.
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      b3a61254
    • P
      netfilter: remove route_key_size field in struct nf_afinfo · 46435623
      Pablo Neira Ayuso 提交于
      This is only needed by nf_queue, place this code where it belongs.
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      46435623
    • P
      netfilter: move reroute indirection to struct nf_ipv6_ops · ce388f45
      Pablo Neira Ayuso 提交于
      We cannot make a direct call to nf_ip6_reroute() because that would result
      in autoloading the 'ipv6' module because of symbol dependencies.
      Therefore, define reroute indirection in nf_ipv6_ops where this really
      belongs to.
      
      For IPv4, we can indeed make a direct function call, which is faster,
      given IPv4 is built-in in the networking code by default. Still,
      CONFIG_INET=n and CONFIG_NETFILTER=y is possible, so define empty inline
      stub for IPv4 in such case.
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      ce388f45
    • P
      netfilter: move route indirection to struct nf_ipv6_ops · 3f87c08c
      Pablo Neira Ayuso 提交于
      We cannot make a direct call to nf_ip6_route() because that would result
      in autoloading the 'ipv6' module because of symbol dependencies.
      Therefore, define route indirection in nf_ipv6_ops where this really
      belongs to.
      
      For IPv4, we can indeed make a direct function call, which is faster,
      given IPv4 is built-in in the networking code by default. Still,
      CONFIG_INET=n and CONFIG_NETFILTER=y is possible, so define empty inline
      stub for IPv4 in such case.
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      3f87c08c
    • P
      netfilter: remove saveroute indirection in struct nf_afinfo · 7db9a51e
      Pablo Neira Ayuso 提交于
      This is only used by nf_queue.c and this function comes with no symbol
      dependencies with IPv6, it just refers to structure layouts. Therefore,
      we can replace it by a direct function call from where it belongs.
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      7db9a51e
    • P
      netfilter: move checksum_partial indirection to struct nf_ipv6_ops · f7dcbe2f
      Pablo Neira Ayuso 提交于
      We cannot make a direct call to nf_ip6_checksum_partial() because that
      would result in autoloading the 'ipv6' module because of symbol
      dependencies.  Therefore, define checksum_partial indirection in
      nf_ipv6_ops where this really belongs to.
      
      For IPv4, we can indeed make a direct function call, which is faster,
      given IPv4 is built-in in the networking code by default. Still,
      CONFIG_INET=n and CONFIG_NETFILTER=y is possible, so define empty inline
      stub for IPv4 in such case.
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      f7dcbe2f
    • P
      netfilter: move checksum indirection to struct nf_ipv6_ops · ef71fe27
      Pablo Neira Ayuso 提交于
      We cannot make a direct call to nf_ip6_checksum() because that would
      result in autoloading the 'ipv6' module because of symbol dependencies.
      Therefore, define checksum indirection in nf_ipv6_ops where this really
      belongs to.
      
      For IPv4, we can indeed make a direct function call, which is faster,
      given IPv4 is built-in in the networking code by default. Still,
      CONFIG_INET=n and CONFIG_NETFILTER=y is possible, so define empty inline
      stub for IPv4 in such case.
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      ef71fe27
    • F
      netfilter: core: only allow one nat hook per hook point · f92b40a8
      Florian Westphal 提交于
      The netfilter NAT core cannot deal with more than one NAT hook per hook
      location (prerouting, input ...), because the NAT hooks install a NAT null
      binding in case the iptables nat table (iptable_nat hooks) or the
      corresponding nftables chain (nft nat hooks) doesn't specify a nat
      transformation.
      
      Null bindings are needed to detect port collsisions between NAT-ed and
      non-NAT-ed connections.
      
      This causes nftables NAT rules to not work when iptable_nat module is
      loaded, and vice versa because nat binding has already been attached
      when the second nat hook is consulted.
      
      The netfilter core is not really the correct location to handle this
      (hooks are just hooks, the core has no notion of what kinds of side
       effects a hook implements), but its the only place where we can check
      for conflicts between both iptables hooks and nftables hooks without
      adding dependencies.
      
      So add nat annotation to hook_ops to describe those hooks that will
      add NAT bindings and then make core reject if such a hook already exists.
      The annotation fills a padding hole, in case further restrictions appar
      we might change this to a 'u8 type' instead of bool.
      
      iptables error if nft nat hook active:
      iptables -t nat -A POSTROUTING -j MASQUERADE
      iptables v1.4.21: can't initialize iptables table `nat': File exists
      Perhaps iptables or your kernel needs to be upgraded.
      
      nftables error if iptables nat table present:
      nft -f /etc/nftables/ipv4-nat
      /usr/etc/nftables/ipv4-nat:3:1-2: Error: Could not process rule: File exists
      table nat {
      ^^
      Signed-off-by: NFlorian Westphal <fw@strlen.de>
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      f92b40a8
    • F
      netfilter: don't allocate space for arp/bridge hooks unless needed · 2a95183a
      Florian Westphal 提交于
      no need to define hook points if the family isn't supported.
      Because we need these hooks for either nftables, arp/ebtables
      or the 'call-iptables' hack we have in the bridge layer add two
      new dependencies, NETFILTER_FAMILY_{ARP,BRIDGE}, and have the
      users select them.
      Signed-off-by: NFlorian Westphal <fw@strlen.de>
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      2a95183a
    • F
      netfilter: don't allocate space for decnet hooks unless needed · bb4badf3
      Florian Westphal 提交于
      no need to define hook points if the family isn't supported.
      Signed-off-by: NFlorian Westphal <fw@strlen.de>
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      bb4badf3
    • F
      netfilter: reduce size of hook entry point locations · b0f38338
      Florian Westphal 提交于
      struct net contains:
      
      struct nf_hook_entries __rcu *hooks[NFPROTO_NUMPROTO][NF_MAX_HOOKS];
      
      which store the hook entry point locations for the various protocol
      families and the hooks.
      
      Using array results in compact c code when doing accesses, i.e.
        x = rcu_dereference(net->nf.hooks[pf][hook]);
      
      but its also wasting a lot of memory, as most families are
      not used.
      
      So split the array into those families that are used, which
      are only 5 (instead of 13).  In most cases, the 'pf' argument is
      constant, i.e. gcc removes switch statement.
      
      struct net before:
       /* size: 5184, cachelines: 81, members: 46 */
      after:
       /* size: 4672, cachelines: 73, members: 46 */
      Signed-off-by: NFlorian Westphal <fw@strlen.de>
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      b0f38338
    • F
      netfilter: core: free hooks with call_rcu · 8c873e21
      Florian Westphal 提交于
      Giuseppe Scrivano says:
        "SELinux, if enabled, registers for each new network namespace 6
          netfilter hooks."
      
      Cost for this is high.  With synchronize_net() removed:
         "The net benefit on an SMP machine with two cores is that creating a
         new network namespace takes -40% of the original time."
      
      This patch replaces synchronize_net+kvfree with call_rcu().
      We store rcu_head at the tail of a structure that has no fixed layout,
      i.e. we cannot use offsetof() to compute the start of the original
      allocation.  Thus store this information right after the rcu head.
      
      We could simplify this by just placing the rcu_head at the start
      of struct nf_hook_entries.  However, this structure is used in
      packet processing hotpath, so only place what is needed for that
      at the beginning of the struct.
      Reported-by: NGiuseppe Scrivano <gscrivan@redhat.com>
      Signed-off-by: NFlorian Westphal <fw@strlen.de>
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      8c873e21
  10. 02 11月, 2017 1 次提交
    • G
      License cleanup: add SPDX GPL-2.0 license identifier to files with no license · b2441318
      Greg Kroah-Hartman 提交于
      Many source files in the tree are missing licensing information, which
      makes it harder for compliance tools to determine the correct license.
      
      By default all files without license information are under the default
      license of the kernel, which is GPL version 2.
      
      Update the files which contain no license information with the 'GPL-2.0'
      SPDX license identifier.  The SPDX identifier is a legally binding
      shorthand, which can be used instead of the full boiler plate text.
      
      This patch is based on work done by Thomas Gleixner and Kate Stewart and
      Philippe Ombredanne.
      
      How this work was done:
      
      Patches were generated and checked against linux-4.14-rc6 for a subset of
      the use cases:
       - file had no licensing information it it.
       - file was a */uapi/* one with no licensing information in it,
       - file was a */uapi/* one with existing licensing information,
      
      Further patches will be generated in subsequent months to fix up cases
      where non-standard license headers were used, and references to license
      had to be inferred by heuristics based on keywords.
      
      The analysis to determine which SPDX License Identifier to be applied to
      a file was done in a spreadsheet of side by side results from of the
      output of two independent scanners (ScanCode & Windriver) producing SPDX
      tag:value files created by Philippe Ombredanne.  Philippe prepared the
      base worksheet, and did an initial spot review of a few 1000 files.
      
      The 4.13 kernel was the starting point of the analysis with 60,537 files
      assessed.  Kate Stewart did a file by file comparison of the scanner
      results in the spreadsheet to determine which SPDX license identifier(s)
      to be applied to the file. She confirmed any determination that was not
      immediately clear with lawyers working with the Linux Foundation.
      
      Criteria used to select files for SPDX license identifier tagging was:
       - Files considered eligible had to be source code files.
       - Make and config files were included as candidates if they contained >5
         lines of source
       - File already had some variant of a license header in it (even if <5
         lines).
      
      All documentation files were explicitly excluded.
      
      The following heuristics were used to determine which SPDX license
      identifiers to apply.
      
       - when both scanners couldn't find any license traces, file was
         considered to have no license information in it, and the top level
         COPYING file license applied.
      
         For non */uapi/* files that summary was:
      
         SPDX license identifier                            # files
         ---------------------------------------------------|-------
         GPL-2.0                                              11139
      
         and resulted in the first patch in this series.
      
         If that file was a */uapi/* path one, it was "GPL-2.0 WITH
         Linux-syscall-note" otherwise it was "GPL-2.0".  Results of that was:
      
         SPDX license identifier                            # files
         ---------------------------------------------------|-------
         GPL-2.0 WITH Linux-syscall-note                        930
      
         and resulted in the second patch in this series.
      
       - if a file had some form of licensing information in it, and was one
         of the */uapi/* ones, it was denoted with the Linux-syscall-note if
         any GPL family license was found in the file or had no licensing in
         it (per prior point).  Results summary:
      
         SPDX license identifier                            # files
         ---------------------------------------------------|------
         GPL-2.0 WITH Linux-syscall-note                       270
         GPL-2.0+ WITH Linux-syscall-note                      169
         ((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause)    21
         ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)    17
         LGPL-2.1+ WITH Linux-syscall-note                      15
         GPL-1.0+ WITH Linux-syscall-note                       14
         ((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause)    5
         LGPL-2.0+ WITH Linux-syscall-note                       4
         LGPL-2.1 WITH Linux-syscall-note                        3
         ((GPL-2.0 WITH Linux-syscall-note) OR MIT)              3
         ((GPL-2.0 WITH Linux-syscall-note) AND MIT)             1
      
         and that resulted in the third patch in this series.
      
       - when the two scanners agreed on the detected license(s), that became
         the concluded license(s).
      
       - when there was disagreement between the two scanners (one detected a
         license but the other didn't, or they both detected different
         licenses) a manual inspection of the file occurred.
      
       - In most cases a manual inspection of the information in the file
         resulted in a clear resolution of the license that should apply (and
         which scanner probably needed to revisit its heuristics).
      
       - When it was not immediately clear, the license identifier was
         confirmed with lawyers working with the Linux Foundation.
      
       - If there was any question as to the appropriate license identifier,
         the file was flagged for further research and to be revisited later
         in time.
      
      In total, over 70 hours of logged manual review was done on the
      spreadsheet to determine the SPDX license identifiers to apply to the
      source files by Kate, Philippe, Thomas and, in some cases, confirmation
      by lawyers working with the Linux Foundation.
      
      Kate also obtained a third independent scan of the 4.13 code base from
      FOSSology, and compared selected files where the other two scanners
      disagreed against that SPDX file, to see if there was new insights.  The
      Windriver scanner is based on an older version of FOSSology in part, so
      they are related.
      
      Thomas did random spot checks in about 500 files from the spreadsheets
      for the uapi headers and agreed with SPDX license identifier in the
      files he inspected. For the non-uapi files Thomas did random spot checks
      in about 15000 files.
      
      In initial set of patches against 4.14-rc6, 3 files were found to have
      copy/paste license identifier errors, and have been fixed to reflect the
      correct identifier.
      
      Additionally Philippe spent 10 hours this week doing a detailed manual
      inspection and review of the 12,461 patched files from the initial patch
      version early this week with:
       - a full scancode scan run, collecting the matched texts, detected
         license ids and scores
       - reviewing anything where there was a license detected (about 500+
         files) to ensure that the applied SPDX license was correct
       - reviewing anything where there was no detection but the patch license
         was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
         SPDX license was correct
      
      This produced a worksheet with 20 files needing minor correction.  This
      worksheet was then exported into 3 different .csv files for the
      different types of files to be modified.
      
      These .csv files were then reviewed by Greg.  Thomas wrote a script to
      parse the csv files and add the proper SPDX tag to the file, in the
      format that the file expected.  This script was further refined by Greg
      based on the output to detect more types of files automatically and to
      distinguish between header and source .c files (which need different
      comment types.)  Finally Greg ran the script using the .csv files to
      generate the patches.
      Reviewed-by: NKate Stewart <kstewart@linuxfoundation.org>
      Reviewed-by: NPhilippe Ombredanne <pombredanne@nexb.com>
      Reviewed-by: NThomas Gleixner <tglx@linutronix.de>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b2441318
  11. 28 8月, 2017 1 次提交
    • A
      netfilter: convert hook list to an array · 960632ec
      Aaron Conole 提交于
      This converts the storage and layout of netfilter hook entries from a
      linked list to an array.  After this commit, hook entries will be
      stored adjacent in memory.  The next pointer is no longer required.
      
      The ops pointers are stored at the end of the array as they are only
      used in the register/unregister path and in the legacy br_netfilter code.
      
      nf_unregister_net_hooks() is slower than needed as it just calls
      nf_unregister_net_hook in a loop (i.e. at least n synchronize_net()
      calls), this will be addressed in followup patch.
      
      Test setup:
       - ixgbe 10gbit
       - netperf UDP_STREAM, 64 byte packets
       - 5 hooks: (raw + mangle prerouting, mangle+filter input, inet filter):
      empty mangle and raw prerouting, mangle and filter input hooks:
      353.9
      this patch:
      364.2
      Signed-off-by: NAaron Conole <aconole@bytheb.org>
      Signed-off-by: NFlorian Westphal <fw@strlen.de>
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      960632ec
  12. 17 7月, 2017 1 次提交
  13. 07 12月, 2016 2 次提交
  14. 03 11月, 2016 2 次提交
  15. 25 9月, 2016 2 次提交
  16. 19 9月, 2016 1 次提交
  17. 03 3月, 2016 1 次提交
  18. 17 10月, 2015 2 次提交
    • A
      netfilter: turn NF_HOOK into an inline function · 008027c3
      Arnd Bergmann 提交于
      A recent change to the dst_output handling caused a new warning
      when the call to NF_HOOK() is the only used of a local variable
      passed as 'dev', and CONFIG_NETFILTER is disabled:
      
      net/ipv6/ip6_output.c: In function 'ip6_output':
      net/ipv6/ip6_output.c:135:21: warning: unused variable 'dev' [-Wunused-variable]
      
      The reason for this is that the NF_HOOK macro in this case does
      not reference the variable at all, and the call to dev_net(dev)
      got removed from the ip6_output function. To avoid that warning now
      and in the future, this changes the macro into an equivalent
      inline function, which tells the compiler that the variable is
      passed correctly but still unused.
      
      The dn_forward function apparently had the same problem in
      the past and added a local workaround that no longer works
      with the inline function. In order to avoid a regression, we
      have to also remove the #ifdef from decnet in the same patch.
      
      Fixes: ede2059d ("dst: Pass net into dst->output")
      Signed-off-by: NArnd Bergmann <arnd@arndb.de>
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      008027c3
    • F
      netfilter: remove hook owner refcounting · 2ffbceb2
      Florian Westphal 提交于
      since commit 8405a8ff ("netfilter: nf_qeueue: Drop queue entries on
      nf_unregister_hook") all pending queued entries are discarded.
      
      So we can simply remove all of the owner handling -- when module is
      removed it also needs to unregister all its hooks.
      Signed-off-by: NFlorian Westphal <fw@strlen.de>
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      2ffbceb2
  19. 05 10月, 2015 3 次提交