1. 21 Jun, 2019 4 commits
  2. 20 Jun, 2019 3 commits
    • Christian Brauner's avatar
      netfilter: bridge: prevent UAF in brnf_exit_net() · 7e6daf50
      Christian Brauner authored
      Prevent a UAF in brnf_exit_net().
      
      When unregister_net_sysctl_table() is called the ctl_hdr pointer will
      obviously be freed and so accessing it righter after is invalid. Fix
      this by stashing a pointer to the table we want to free before we
      unregister the sysctl header.
      
      Note that syzkaller falsely chased this down to the drm tree so the
      Fixes tag that syzkaller requested would be wrong. This commit uses a
      different but the correct Fixes tag.
      
      /* Splat */
      
      BUG: KASAN: use-after-free in br_netfilter_sysctl_exit_net
      net/bridge/br_netfilter_hooks.c:1121 [inline]
      BUG: KASAN: use-after-free in brnf_exit_net+0x38c/0x3a0
      net/bridge/br_netfilter_hooks.c:1141
      Read of size 8 at addr ffff8880a4078d60 by task kworker/u4:4/8749
      
      CPU: 0 PID: 8749 Comm: kworker/u4:4 Not tainted 5.2.0-rc5-next-20190618 #17
      Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google
      01/01/2011
      Workqueue: netns cleanup_net
      Call Trace:
       __dump_stack lib/dump_stack.c:77 [inline]
       dump_stack+0x172/0x1f0 lib/dump_stack.c:113
       print_address_description.cold+0xd4/0x306 mm/kasan/report.c:351
       __kasan_report.cold+0x1b/0x36 mm/kasan/report.c:482
       kasan_report+0x12/0x20 mm/kasan/common.c:614
       __asan_report_load8_noabort+0x14/0x20 mm/kasan/generic_report.c:132
       br_netfilter_sysctl_exit_net net/bridge/br_netfilter_hooks.c:1121 [inline]
       brnf_exit_net+0x38c/0x3a0 net/bridge/br_netfilter_hooks.c:1141
       ops_exit_list.isra.0+0xaa/0x150 net/core/net_namespace.c:154
       cleanup_net+0x3fb/0x960 net/core/net_namespace.c:553
       process_one_work+0x989/0x1790 kernel/workqueue.c:2269
       worker_thread+0x98/0xe40 kernel/workqueue.c:2415
       kthread+0x354/0x420 kernel/kthread.c:255
       ret_from_fork+0x24/0x30 arch/x86/entry/entry_64.S:352
      
      Allocated by task 11374:
       save_stack+0x23/0x90 mm/kasan/common.c:71
       set_track mm/kasan/common.c:79 [inline]
       __kasan_kmalloc mm/kasan/common.c:489 [inline]
       __kasan_kmalloc.constprop.0+0xcf/0xe0 mm/kasan/common.c:462
       kasan_kmalloc+0x9/0x10 mm/kasan/common.c:503
       __do_kmalloc mm/slab.c:3645 [inline]
       __kmalloc+0x15c/0x740 mm/slab.c:3654
       kmalloc include/linux/slab.h:552 [inline]
       kzalloc include/linux/slab.h:743 [inline]
       __register_sysctl_table+0xc7/0xef0 fs/proc/proc_sysctl.c:1327
       register_net_sysctl+0x29/0x30 net/sysctl_net.c:121
       br_netfilter_sysctl_init_net net/bridge/br_netfilter_hooks.c:1105 [inline]
       brnf_init_net+0x379/0x6a0 net/bridge/br_netfilter_hooks.c:1126
       ops_init+0xb3/0x410 net/core/net_namespace.c:130
       setup_net+0x2d3/0x740 net/core/net_namespace.c:316
       copy_net_ns+0x1df/0x340 net/core/net_namespace.c:439
       create_new_namespaces+0x400/0x7b0 kernel/nsproxy.c:103
       unshare_nsproxy_namespaces+0xc2/0x200 kernel/nsproxy.c:202
       ksys_unshare+0x444/0x980 kernel/fork.c:2822
       __do_sys_unshare kernel/fork.c:2890 [inline]
       __se_sys_unshare kernel/fork.c:2888 [inline]
       __x64_sys_unshare+0x31/0x40 kernel/fork.c:2888
       do_syscall_64+0xfd/0x680 arch/x86/entry/common.c:301
       entry_SYSCALL_64_after_hwframe+0x49/0xbe
      
      Freed by task 9:
       save_stack+0x23/0x90 mm/kasan/common.c:71
       set_track mm/kasan/common.c:79 [inline]
       __kasan_slab_free+0x102/0x150 mm/kasan/common.c:451
       kasan_slab_free+0xe/0x10 mm/kasan/common.c:459
       __cache_free mm/slab.c:3417 [inline]
       kfree+0x10a/0x2c0 mm/slab.c:3746
       __rcu_reclaim kernel/rcu/rcu.h:215 [inline]
       rcu_do_batch kernel/rcu/tree.c:2092 [inline]
       invoke_rcu_callbacks kernel/rcu/tree.c:2310 [inline]
       rcu_core+0xcc7/0x1500 kernel/rcu/tree.c:2291
       __do_softirq+0x25c/0x94c kernel/softirq.c:292
      
      The buggy address belongs to the object at ffff8880a4078d40
       which belongs to the cache kmalloc-512 of size 512
      The buggy address is located 32 bytes inside of
       512-byte region [ffff8880a4078d40, ffff8880a4078f40)
      The buggy address belongs to the page:
      page:ffffea0002901e00 refcount:1 mapcount:0 mapping:ffff8880aa400a80
      index:0xffff8880a40785c0
      flags: 0x1fffc0000000200(slab)
      raw: 01fffc0000000200 ffffea0001d636c8 ffffea0001b07308 ffff8880aa400a80
      raw: ffff8880a40785c0 ffff8880a40780c0 0000000100000004 0000000000000000
      page dumped because: kasan: bad access detected
      
      Memory state around the buggy address:
       ffff8880a4078c00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
       ffff8880a4078c80: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
      > ffff8880a4078d00: fc fc fc fc fc fc fc fc fb fb fb fb fb fb fb fb
                                                             ^
       ffff8880a4078d80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
       ffff8880a4078e00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
      
      Reported-by: syzbot+43a3fa52c0d9c5c94f41@syzkaller.appspotmail.com
      Fixes: 22567590 ("netfilter: bridge: namespace bridge netfilter sysctls")
      Signed-off-by: default avatarChristian Brauner <christian@brauner.io>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      7e6daf50
    • Pablo Neira Ayuso's avatar
      netfilter: synproxy: use nf_cookie_v6_check() from core · 22f2efd3
      Pablo Neira Ayuso authored
      This helper function is never used and it is intended to avoid a direct
      dependency with the ipv6 module.
      
      Fixes: d7f9b2f1 ("netfilter: synproxy: extract SYNPROXY infrastructure from {ipt, ip6t}_SYNPROXY")
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      22f2efd3
    • Arnd Bergmann's avatar
      netfilter: synproxy: fix building syncookie calls · 8527fa6c
      Arnd Bergmann authored
      When either CONFIG_IPV6 or CONFIG_SYN_COOKIES are disabled, the kernel
      fails to build:
      
      include/linux/netfilter_ipv6.h:180:9: error: implicit declaration of function '__cookie_v6_init_sequence'
            [-Werror,-Wimplicit-function-declaration]
              return __cookie_v6_init_sequence(iph, th, mssp);
      include/linux/netfilter_ipv6.h:194:9: error: implicit declaration of function '__cookie_v6_check'
            [-Werror,-Wimplicit-function-declaration]
              return __cookie_v6_check(iph, th, cookie);
      net/ipv6/netfilter.c:237:26: error: use of undeclared identifier '__cookie_v6_init_sequence'; did you mean 'cookie_init_sequence'?
      net/ipv6/netfilter.c:238:21: error: use of undeclared identifier '__cookie_v6_check'; did you mean '__cookie_v4_check'?
      
      Fix the IS_ENABLED() checks to match the function declaration
      and definitions for these.
      
      Fixes: 3006a522 ("netfilter: synproxy: remove module dependency on IPv6 SYNPROXY")
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      8527fa6c
  3. 19 Jun, 2019 3 commits
  4. 17 Jun, 2019 9 commits
    • Fernando Fernandez Mancera's avatar
      netfilter: synproxy: extract SYNPROXY infrastructure from {ipt, ip6t}_SYNPROXY · d7f9b2f1
      Fernando Fernandez Mancera authored
      Add common functions into nf_synproxy_core.c to prepare for nftables support.
      The prototypes of the functions used by {ipt, ip6t}_SYNPROXY are in the new
      file nf_synproxy.h
      Signed-off-by: default avatarFernando Fernandez Mancera <ffmancera@riseup.net>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      d7f9b2f1
    • Fernando Fernandez Mancera's avatar
      netfilter: synproxy: remove module dependency on IPv6 SYNPROXY · 3006a522
      Fernando Fernandez Mancera authored
      This is a prerequisite for the infrastructure module NETFILTER_SYNPROXY.
      The new module is needed to avoid duplicated code for the SYNPROXY
      nftables support.
      Signed-off-by: default avatarFernando Fernandez Mancera <ffmancera@riseup.net>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      3006a522
    • Fernando Fernandez Mancera's avatar
      netfilter: synproxy: add common uapi for SYNPROXY infrastructure · 5fcc88ec
      Fernando Fernandez Mancera authored
      This new UAPI file is going to be used by the xt and nft common SYNPROXY
      infrastructure. It is needed to avoid duplicated code.
      Signed-off-by: default avatarFernando Fernandez Mancera <ffmancera@riseup.net>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      5fcc88ec
    • Pablo Neira Ayuso's avatar
      Merge branch 'master' of git://blackhole.kfki.hu/nf-next · 667ec21e
      Pablo Neira Ayuso authored
      Jozsef Kadlecsik says:
      
      ====================
      ipset patches for nf-next
      
      - Remove useless memset() calls, nla_parse_nested/nla_parse
        erase the tb array properly, from Florent Fourcot.
      - Merge the uadd and udel functions, the code is nicer
        this way, also from Florent Fourcot.
      - Add a missing check for the return value of a
        nla_parse[_deprecated] call, from Aditya Pakki.
      - Add the last missing check for the return value
        of nla_parse[_deprecated] call.
      - Fix error path and release the references properly
        in set_target_v3_checkentry().
      - Fix memory accounting which is reported to userspace
        for hash types on resize, from Stefano Brivio.
      - Update my email address to kadlec@netfilter.org.
        The patch covers all places in the source tree where
        my kadlec@blackhole.kfki.hu address could be found.
      ====================
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      667ec21e
    • Christian Brauner's avatar
      netfilter: bridge: namespace bridge netfilter sysctls · 22567590
      Christian Brauner authored
      Currently, the /proc/sys/net/bridge folder is only created in the initial
      network namespace. This patch ensures that the /proc/sys/net/bridge folder
      is available in each network namespace if the module is loaded and
      disappears from all network namespaces when the module is unloaded.
      
      In doing so the patch makes the sysctls:
      
      bridge-nf-call-arptables
      bridge-nf-call-ip6tables
      bridge-nf-call-iptables
      bridge-nf-filter-pppoe-tagged
      bridge-nf-filter-vlan-tagged
      bridge-nf-pass-vlan-input-dev
      
      apply per network namespace. This unblocks some use-cases where users would
      like to e.g. not do bridge filtering for bridges in a specific network
      namespace while doing so for bridges located in another network namespace.
      
      The netfilter rules are afaict already per network namespace so it should
      be safe for users to specify whether bridge devices inside a network
      namespace are supposed to go through iptables et al. or not. Also, this can
      already be done per-bridge by setting an option for each individual bridge
      via Netlink. It should also be possible to do this for all bridges in a
      network namespace via sysctls.
      
      Cc: Tyler Hicks <tyhicks@canonical.com>
      Signed-off-by: default avatarChristian Brauner <christian.brauner@ubuntu.com>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      22567590
    • Christian Brauner's avatar
      netfilter: bridge: port sysctls to use brnf_net · ff6d090d
      Christian Brauner authored
      This ports the sysctls to use struct brnf_net.
      
      With this patch we make it possible to namespace the br_netfilter module in
      the following patch.
      Signed-off-by: default avatarChristian Brauner <christian.brauner@ubuntu.com>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      ff6d090d
    • Pablo Neira Ayuso's avatar
      netfilter: xt_owner: bail out with EINVAL in case of unsupported flags · 9911c113
      Pablo Neira Ayuso authored
      Reject flags that are not supported with EINVAL.
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      9911c113
    • Florian Westphal's avatar
      netfilter: conntrack: small conntrack lookup optimization · 87e389b4
      Florian Westphal authored
      ____nf_conntrack_find() performs checks on the conntrack objects in
      this order:
      
      1. if (nf_ct_is_expired(ct))
      
      This fetches ct->timeout, in third cache line.
      
      The hnnode that is used to store the list pointers resides in the first
      (origin) or second (reply tuple) cache lines.
      
      This test rarely passes, but its necessary to reap obsolete entries.
      
      2. if (nf_ct_is_dying(ct))
      
      This fetches ct->status, also in third cache line.
      
      The test is useless, and can be removed:
        Consider:
           cpu0                                           cpu1
          ct = ____nf_conntrack_find()
          atomic_inc_not_zero(ct) -> ok
          nf_ct_key_equal -> ok
          is_dying -> DYING bit not set, ok
                                                          set_bit(ct, DYING);
      						    ... unhash ... etc.
          return ct
          -> returning a ct with dying bit set, despite
          having a test for it.
      
      This (unlikely) case is fine - refcount prevents ct from getting free'd.
      
      3. if (nf_ct_key_equal(h, tuple, zone, net))
      
      nf_ct_key_equal checks in following order:
      
      1. Tuple equal (first or second cacheline)
      2. Zone equal (third cacheline)
      3. confirmed bit set (->status, third cacheline)
      4. net namespace match (third cacheline).
      
      Swapping "timeout" and "cpu" places timeout in the first cacheline.
      This has two advantages:
      
      1. For a conntrack that won't even match the original tuple,
         we will now only fetch the first and maybe the second cacheline
         instead of always accessing the 3rd one as well.
      
      2.  in case of TCP ct->timeout changes frequently because we
          reduce/increase it when there are packets outstanding in the network.
      
      The first cacheline contains both the reference count and the ct spinlock,
      i.e. moving timeout there avoids writes to 3rd cacheline.
      
      The restart sequence in __nf_conntrack_find() is removed, if we found a
      candidate, but then fail to increment the refcount or discover the tuple
      has changed (object recycling), just pretend we did not find an entry.
      
      A second lookup won't find anything until another CPU adds a new conntrack
      with identical tuple into the hash table, which is very unlikely.
      
      We have the confirmation-time checks (when we hold hash lock) that deal
      with identical entries and even perform clash resolution in some cases.
      Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      87e389b4
    • Stéphane Veyret's avatar
      netfilter: nft_ct: add ct expectations support · 857b4602
      Stéphane Veyret authored
      This patch allows to add, list and delete expectations via nft objref
      infrastructure and assigning these expectations via nft rule.
      
      This allows manual port triggering when no helper is defined to manage a
      specific protocol. For example, if I have an online game which protocol
      is based on initial connection to TCP port 9753 of the server, and where
      the server opens a connection to port 9876, I can set rules as follow:
      
      table ip filter {
          ct expectation mygame {
              protocol udp;
              dport 9876;
              timeout 2m;
              size 1;
          }
      
          chain input {
              type filter hook input priority 0; policy drop;
              tcp dport 9753 ct expectation set "mygame";
          }
      
          chain output {
              type filter hook output priority 0; policy drop;
              udp dport 9876 ct status expected accept;
          }
      }
      Signed-off-by: default avatarStéphane Veyret <sveyret@gmail.com>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      857b4602
  5. 10 Jun, 2019 7 commits
  6. 06 Jun, 2019 9 commits
  7. 05 Jun, 2019 5 commits