1. Apr 08, 2020
  2. Apr 06, 2020
    • Amol Grover's avatar
      netfilter: ipset: Pass lockdep expression to RCU lists · b135fc08
      Amol Grover authored
      
      
      ip_set_type_list is traversed using list_for_each_entry_rcu
      outside an RCU read-side critical section but under the protection
      of ip_set_type_mutex.
      
      Hence, add corresponding lockdep expression to silence false-positive
      warnings, and harden RCU lists.
      
      Signed-off-by: default avatarAmol Grover <frextrite@gmail.com>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      b135fc08
    • Eric Dumazet's avatar
      netfilter: nf_tables: do not leave dangling pointer in nf_tables_set_alloc_name · 7fb6f78d
      Eric Dumazet authored
      If nf_tables_set_alloc_name() frees set->name, we better
      clear set->name to avoid a future use-after-free or invalid-free.
      
      BUG: KASAN: double-free or invalid-free in nf_tables_newset+0x1ed6/0x2560 net/netfilter/nf_tables_api.c:4148
      
      CPU: 0 PID: 28233 Comm: syz-executor.0 Not tainted 5.6.0-syzkaller #0
      Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
      Call Trace:
       __dump_stack lib/dump_stack.c:77 [inline]
       dump_stack+0x188/0x20d lib/dump_stack.c:118
       print_address_description.constprop.0.cold+0xd3/0x315 mm/kasan/report.c:374
       kasan_report_invalid_free+0x61/0xa0 mm/kasan/report.c:468
       __kasan_slab_free+0x129/0x140 mm/kasan/common.c:455
       __cache_free mm/slab.c:3426 [inline]
       kfree+0x109/0x2b0 mm/slab.c:3757
       nf_tables_newset+0x1ed6/0x2560 net/netfilter/nf_tables_api.c:4148
       nfnetlink_rcv_batch+0x83a/0x1610 net/netfilter/nfnetlink.c:433
       nfnetlink_rcv_skb_batch net/netfilter/nfnetlink.c:543 [inline]
       nfnetlink_rcv+0x3af/0x420 net/netfilter/nfnetlink.c:561
       netlink_unicast_kernel net/netlink/af_netlink.c:1303 [inline]
       netlink_unicast+0x537/0x740 net/netlink/af_netlink.c:1329
       netlink_sendmsg+0x882/0xe10 net/netlink/af_netlink.c:1918
       sock_sendmsg_nosec net/socket.c:652 [inline]
       sock_sendmsg+0xcf/0x120 net/socket.c:672
       ____sys_sendmsg+0x6b9/0x7d0 net/socket.c:2345
       ___sys_sendmsg+0x100/0x170 net/socket.c:2399
       __sys_sendmsg+0xec/0x1b0 net/socket.c:2432
       do_syscall_64+0xf6/0x7d0 arch/x86/entry/common.c:294
       entry_SYSCALL_64_after_hwframe+0x49/0xbe
      RIP: 0033:0x45c849
      Code: ad b6 fb ff c3 66 2e 0f 1f 84 00 00 00 00 00 66 90 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 0f 83 7b b6 fb ff c3 66 2e 0f 1f 84 00 00 00 00
      RSP: 002b:00007fe5ca21dc78 EFLAGS: 00000246 ORIG_RAX: 000000000000002e
      RAX: ffffffffffffffda RBX: 00007fe5ca21e6d4 RCX: 000000000045c849
      RDX: 0000000000000000 RSI: 0000000020000c40 RDI: 0000000000000003
      RBP: 000000000076bf00 R08: 0000000000000000 R09: 0000000000000000
      R10: 0000000000000000 R11: 0000000000000246 R12: 00000000ffffffff
      R13: 000000000000095b R14: 00000000004cc0e9 R15: 000000000076bf0c
      
      Allocated by task 28233:
       save_stack+0x1b/0x80 mm/kasan/common.c:72
       set_track mm/kasan/common.c:80 [inline]
       __kasan_kmalloc mm/kasan/common.c:515 [inline]
       __kasan_kmalloc.constprop.0+0xbf/0xd0 mm/kasan/common.c:488
       __do_kmalloc mm/slab.c:3656 [inline]
       __kmalloc_track_caller+0x159/0x790 mm/slab.c:3671
       kvasprintf+0xb5/0x150 lib/kasprintf.c:25
       kasprintf+0xbb/0xf0 lib/kasprintf.c:59
       nf_tables_set_alloc_name net/netfilter/nf_tables_api.c:3536 [inline]
       nf_tables_newset+0x1543/0x2560 net/netfilter/nf_tables_api.c:4088
       nfnetlink_rcv_batch+0x83a/0x1610 net/netfilter/nfnetlink.c:433
       nfnetlink_rcv_skb_batch net/netfilter/nfnetlink.c:543 [inline]
       nfnetlink_rcv+0x3af/0x420 net/netfilter/nfnetlink.c:561
       netlink_unicast_kernel net/netlink/af_netlink.c:1303 [inline]
       netlink_unicast+0x537/0x740 net/netlink/af_netlink.c:1329
       netlink_sendmsg+0x882/0xe10 net/netlink/af_netlink.c:1918
       sock_sendmsg_nosec net/socket.c:652 [inline]
       sock_sendmsg+0xcf/0x120 net/socket.c:672
       ____sys_sendmsg+0x6b9/0x7d0 net/socket.c:2345
       ___sys_sendmsg+0x100/0x170 net/socket.c:2399
       __sys_sendmsg+0xec/0x1b0 net/socket.c:2432
       do_syscall_64+0xf6/0x7d0 arch/x86/entry/common.c:294
       entry_SYSCALL_64_after_hwframe+0x49/0xbe
      
      Freed by task 28233:
       save_stack+0x1b/0x80 mm/kasan/common.c:72
       set_track mm/kasan/common.c:80 [inline]
       kasan_set_free_info mm/kasan/common.c:337 [inline]
       __kasan_slab_free+0xf7/0x140 mm/kasan/common.c:476
       __cache_free mm/slab.c:3426 [inline]
       kfree+0x109/0x2b0 mm/slab.c:3757
       nf_tables_set_alloc_name net/netfilter/nf_tables_api.c:3544 [inline]
       nf_tables_newset+0x1f73/0x2560 net/netfilter/nf_tables_api.c:4088
       nfnetlink_rcv_batch+0x83a/0x1610 net/netfilter/nfnetlink.c:433
       nfnetlink_rcv_skb_batch net/netfilter/nfnetlink.c:543 [inline]
       nfnetlink_rcv+0x3af/0x420 net/netfilter/nfnetlink.c:561
       netlink_unicast_kernel net/netlink/af_netlink.c:1303 [inline]
       netlink_unicast+0x537/0x740 net/netlink/af_netlink.c:1329
       netlink_sendmsg+0x882/0xe10 net/netlink/af_netlink.c:1918
       sock_sendmsg_nosec net/socket.c:652 [inline]
       sock_sendmsg+0xcf/0x120 net/socket.c:672
       ____sys_sendmsg+0x6b9/0x7d0 net/socket.c:2345
       ___sys_sendmsg+0x100/0x170 net/socket.c:2399
       __sys_sendmsg+0xec/0x1b0 net/socket.c:2432
       do_syscall_64+0xf6/0x7d0 arch/x86/entry/common.c:294
       entry_SYSCALL_64_after_hwframe+0x49/0xbe
      
      The buggy address belongs to the object at ffff8880a6032d00
       which belongs to the cache kmalloc-32 of size 32
      The buggy address is located 0 bytes inside of
       32-byte region [ffff8880a6032d00, ffff8880a6032d20)
      The buggy address belongs to the page:
      page:ffffea0002980c80 refcount:1 mapcount:0 mapping:ffff8880aa0001c0 index:0xffff8880a6032fc1
      flags: 0xfffe0000000200(slab)
      raw: 00fffe0000000200 ffffea0002a3be88 ffffea00029b1908 ffff8880aa0001c0
      raw: ffff8880a6032fc1 ffff8880a6032000 000000010000003e 0000000000000000
      page dumped because: kasan: bad access detected
      
      Fixes: 65038428
      
       ("netfilter: nf_tables: allow to specify stateful expression in set definition")
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Reported-by: default avatarsyzbot <syzkaller@googlegroups.com>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      7fb6f78d
    • Maciej Żenczykowski's avatar
      netfilter: xt_IDLETIMER: target v1 - match Android layout · bc9fe614
      Maciej Żenczykowski authored
      Android has long had an extension to IDLETIMER to send netlink
      messages to userspace, see:
        https://android.googlesource.com/kernel/common/+/refs/heads/android-mainline/include/uapi/linux/netfilter/xt_IDLETIMER.h#42
      Note: this is idletimer target rev 1, there is no rev 0 in
      the Android common kernel sources, see registration at:
        https://android.googlesource.com/kernel/common/+/refs/heads/android-mainline/net/netfilter/xt_IDLETIMER.c#483
      
      When we compare that to upstream's new idletimer target rev 1:
        https://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git/tree/include/uapi/linux/netfilter/xt_IDLETIMER.h#n46
      
      
      
      We immediately notice that these two rev 1 structs are the
      same size and layout, and that while timer_type and send_nl_msg
      are differently named and serve a different purpose, they're
      at the same offset.
      
      This makes them impossible to tell apart - and thus one cannot
      know in a mixed Android/vanilla environment whether one means
      timer_type or send_nl_msg.
      
      Since this is iptables/netfilter uapi it introduces a problem
      between iptables (vanilla vs Android) userspace and kernel
      (vanilla vs Android) if the two don't match each other.
      
      Additionally when at some point in the future Android picks up
      5.7+ it's not at all clear how to resolve the resulting merge
      conflict.
      
      Furthermore, since upgrading the kernel on old Android phones
      is pretty much impossible there does not seem to be an easy way
      out of this predicament.
      
      The only thing I've been able to come up with is some super
      disgusting kernel version >= 5.7 check in the iptables binary
      to flip between different struct layouts.
      
      By adding a dummy field to the vanilla Linux kernel header file
      we can force the two structs to be compatible with each other.
      
      Long term I think I would like to deprecate send_nl_msg out of
      Android entirely, but I haven't quite been able to figure out
      exactly how we depend on it.  It seems to be very similar to
      sysfs notifications but with some extra info.
      
      Currently it's actually always enabled whenever Android uses
      the IDLETIMER target, so we could also probably entirely
      remove it from the uapi in favour of just always enabling it,
      but again we can't upgrade old kernels already in the field.
      
      (Also note that this doesn't change the structure's size,
      as it is simply fitting into the pre-existing padding, and
      that since 5.7 hasn't been released yet, there's still time
      to make this uapi visible change)
      
      Cc: Manoj Basapathi <manojbm@codeaurora.org>
      Cc: Subash Abhinov Kasiviswanathan <subashab@codeaurora.org>
      Signed-off-by: default avatarMaciej Żenczykowski <maze@google.com>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      bc9fe614
    • Pablo Neira Ayuso's avatar
      netfilter: nf_tables: do not update stateful expressions if lookup is inverted · a26c1e49
      Pablo Neira Ayuso authored
      Initialize set lookup matching element to NULL. Otherwise, the
      NFT_LOOKUP_F_INV flag reverses the matching logic and it leads to
      deference an uninitialized pointer to the matching element. Make sure
      element data area and stateful expression are accessed if there is a
      matching set element.
      
      This patch undoes 24791b9a ("netfilter: nft_set_bitmap: initialize set
      element extension in lookups") which is not required anymore.
      
      Fixes: 339706bc
      
       ("netfilter: nft_lookup: update element stateful expression")
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      a26c1e49
    • Stefano Brivio's avatar
      netfilter: nft_set_rbtree: Drop spurious condition for overlap detection on insertion · 72239f27
      Stefano Brivio authored
      
      
      Case a1. for overlap detection in __nft_rbtree_insert() is not a valid
      one: start-after-start is not needed to detect any type of interval
      overlap and it actually results in a false positive if, while
      descending the tree, this is the only step we hit after starting from
      the root.
      
      This introduced a regression, as reported by Pablo, in Python tests
      cases ip/ip.t and ip/numgen.t:
      
        ip/ip.t: ERROR: line 124: add rule ip test-ip4 input ip hdrlength vmap { 0-4 : drop, 5 : accept, 6 : continue } counter: This rule should not have failed.
        ip/numgen.t: ERROR: line 7: add rule ip test-ip4 pre dnat to numgen inc mod 10 map { 0-5 : 192.168.10.100, 6-9 : 192.168.20.200}: This rule should not have failed.
      
      Drop case a1. and renumber others, so that they are a bit clearer. In
      order for these diagrams to be readily understandable, a bigger rework
      is probably needed, such as an ASCII art of the actual rbtree (instead
      of a flattened version).
      
      Shell script test sets/0044interval_overlap_0 should cover all
      possible cases for false negatives, so I consider that test case still
      sufficient after this change.
      
      v2: Fix comments for cases a3. and b3.
      
      Reported-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      Fixes: 7c84d414
      
       ("netfilter: nft_set_rbtree: Detect partial overlaps on insertion")
      Signed-off-by: default avatarStefano Brivio <sbrivio@redhat.com>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      72239f27
  3. Apr 04, 2020
  4. Apr 03, 2020
  5. Apr 02, 2020
  6. Apr 01, 2020