05 Mar, 2020

4 commits

  • commit cf3e204a1ca5442190018a317d9ec181b4639bd6 upstream.

    info->key.tp_src and tp_dst are __be16, when using nla_put_be16()
    to dump them, htons() is not needed, so remove it in this patch.

    Fixes: af308b94a2a4 ("netfilter: nf_tables: add tunnel support")
    Signed-off-by: Xin Long
    Reviewed-by: Simon Horman
    Signed-off-by: Pablo Neira Ayuso
    Signed-off-by: Greg Kroah-Hartman

    Xin Long
     
  • commit c4a3922d2d20c710f827d3a115ee338e8d0467df upstream.

    It is unnecessary to hold hashlimit_mutex for htable_destroy()
    as it is already removed from the global hashtable and its
    refcount is already zero.

    Also, switch hinfo->use to refcount_t so that we don't have
    to hold the mutex until it reaches zero in htable_put().

    Reported-and-tested-by: syzbot+adf6c6c2be1c3a718121@syzkaller.appspotmail.com
    Acked-by: Florian Westphal
    Signed-off-by: Cong Wang
    Signed-off-by: Pablo Neira Ayuso
    Signed-off-by: Greg Kroah-Hartman

    Cong Wang
     
  • commit 8af1c6fbd9239877998c7f5a591cb2c88d41fb66 upstream.

    When the forceadd option is enabled, the hash:* types should find and replace
    the first entry in the bucket with the new one if there are no reuseable
    (deleted or timed out) entries. However, the position index was just not set
    to zero and remained the invalid -1 if there were no reuseable entries.

    Reported-by: syzbot+6a86565c74ebe30aea18@syzkaller.appspotmail.com
    Fixes: 23c42a403a9c ("netfilter: ipset: Introduction of new commands and protocol version 7")
    Signed-off-by: Jozsef Kadlecsik
    Signed-off-by: Greg Kroah-Hartman

    Jozsef Kadlecsik
     
  • commit f66ee0410b1c3481ee75e5db9b34547b4d582465 upstream.

    In the case of huge hash:* types of sets, due to the single spinlock of
    a set the processing of the whole set under spinlock protection could take
    too long.

    There were four places where the whole hash table of the set was processed
    from bucket to bucket under holding the spinlock:

    - During resizing a set, the original set was locked to exclude kernel side
    add/del element operations (userspace add/del is excluded by the
    nfnetlink mutex). The original set is actually just read during the
    resize, so the spinlocking is replaced with rcu locking of regions.
    However, thus there can be parallel kernel side add/del of entries.
    In order not to loose those operations a backlog is added and replayed
    after the successful resize.
    - Garbage collection of timed out entries was also protected by the spinlock.
    In order not to lock too long, region locking is introduced and a single
    region is processed in one gc go. Also, the simple timer based gc running
    is replaced with a workqueue based solution. The internal book-keeping
    (number of elements, size of extensions) is moved to region level due to
    the region locking.
    - Adding elements: when the max number of the elements is reached, the gc
    was called to evict the timed out entries. The new approach is that the gc
    is called just for the matching region, assuming that if the region
    (proportionally) seems to be full, then the whole set does. We could scan
    the other regions to check every entry under rcu locking, but for huge
    sets it'd mean a slowdown at adding elements.
    - Listing the set header data: when the set was defined with timeout
    support, the garbage collector was called to clean up timed out entries
    to get the correct element numbers and set size values. Now the set is
    scanned to check non-timed out entries, without actually calling the gc
    for the whole set.

    Thanks to Florian Westphal for helping me to solve the SOFTIRQ-safe ->
    SOFTIRQ-unsafe lock order issues during working on the patch.

    Reported-by: syzbot+4b0e9d4ff3cf117837e5@syzkaller.appspotmail.com
    Reported-by: syzbot+c27b8d5010f45c666ed1@syzkaller.appspotmail.com
    Reported-by: syzbot+68a806795ac89df3aa1c@syzkaller.appspotmail.com
    Fixes: 23c42a403a9c ("netfilter: ipset: Introduction of new commands and protocol version 7")
    Signed-off-by: Jozsef Kadlecsik
    Signed-off-by: Greg Kroah-Hartman

    Jozsef Kadlecsik
     

29 Feb, 2020

1 commit

  • commit 8d0015a7ab76b8b1e89a3e5f5710a6e5103f2dd5 upstream.

    The user-specified hashtable size is unbound, this could
    easily lead to an OOM or a hung task as we hold the global
    mutex while allocating and initializing the new hashtable.

    Add a max value to cap both cfg->size and cfg->max, as
    suggested by Florian.

    Reported-and-tested-by: syzbot+adf6c6c2be1c3a718121@syzkaller.appspotmail.com
    Signed-off-by: Cong Wang
    Reviewed-by: Florian Westphal
    Signed-off-by: Pablo Neira Ayuso
    Signed-off-by: Greg Kroah-Hartman

    Cong Wang
     

24 Feb, 2020

1 commit

  • [ Upstream commit 0705f95c332081036d85f26691e9d3cd7d901c31 ]

    ERSPAN_VERSION is an attribute parsed in kernel side, nla_policy
    type should be added for it, like other attributes.

    Fixes: af308b94a2a4 ("netfilter: nf_tables: add tunnel support")
    Signed-off-by: Xin Long
    Reviewed-by: Simon Horman
    Signed-off-by: Pablo Neira Ayuso
    Signed-off-by: Sasha Levin

    Xin Long
     

11 Feb, 2020

1 commit

  • commit 5038517119d50ed0240059b1d7fc2faa92371c08 upstream.

    find_set_and_id() is called when the NFNL_SUBSYS_IPSET mutex is held.
    However, in the error path there can be a follow-up recvmsg() without
    the mutex held. Use the start() function of struct netlink_dump_control
    instead of dump() to verify and report if the specified set does not
    exist.

    Thanks to Pablo Neira Ayuso for helping me to understand the subleties
    of the netlink protocol.

    Reported-by: syzbot+fc69d7cb21258ab4ae4d@syzkaller.appspotmail.com
    Signed-off-by: Jozsef Kadlecsik
    Signed-off-by: Pablo Neira Ayuso
    Signed-off-by: Greg Kroah-Hartman

    Kadlecsik József
     

06 Feb, 2020

2 commits

  • [ Upstream commit c83de17dd6308fb74696923e5245de0e3c427206 ]

    In the nft_indr_block_cb the chain should check the flag with
    NFT_CHAIN_HW_OFFLOAD.

    Fixes: 9a32669fecfb ("netfilter: nf_tables_offload: support indr block call")
    Signed-off-by: wenxu
    Signed-off-by: Pablo Neira Ayuso
    Signed-off-by: Sasha Levin

    wenxu
     
  • [ Upstream commit ab658b9fa7a2c467f79eac8b53ea308b8f98113d ]

    The netlink notifications triggered by the INIT and INIT_ACK chunks
    for a tracked SCTP association do not include protocol information
    for the corresponding connection - SCTP state and verification tags
    for the original and reply direction are missing. Since the connection
    tracking implementation allows user space programs to receive
    notifications about a connection and then create a new connection
    based on the values received in a notification, it makes sense that
    INIT and INIT_ACK notifications should contain the SCTP state
    and verification tags available at the time when a notification
    is sent. The missing verification tags cause a newly created
    netfilter connection to fail to verify the tags of SCTP packets
    when this connection has been created from the values previously
    received in an INIT or INIT_ACK notification.

    A PROTOINFO event is cached in sctp_packet() when the state
    of a connection changes. The CLOSED and COOKIE_WAIT state will
    be used for connections that have seen an INIT and INIT_ACK chunk,
    respectively. The distinct states will cause a connection state
    change in sctp_packet().

    Signed-off-by: Jiri Wiesner
    Signed-off-by: Pablo Neira Ayuso
    Signed-off-by: Sasha Levin

    Jiri Wiesner
     

29 Jan, 2020

4 commits

  • commit eb014de4fd418de1a277913cba244e47274fe392 upstream.

    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: ec7470b834fe ("netfilter: nf_tables: store transaction list locally while requesting module")
    Reported-by: syzbot+29125d208b3dae9a7019@syzkaller.appspotmail.com
    Signed-off-by: Pablo Neira Ayuso
    Signed-off-by: Greg Kroah-Hartman

    Pablo Neira Ayuso
     
  • commit 826035498ec14b77b62a44f0cb6b94d45530db6f upstream.

    This new helper function validates that unknown family and chain type
    coming from userspace do not trigger an out-of-bound array access. Bail
    out in case __nft_chain_type_get() returns NULL from
    nft_chain_parse_hook().

    Fixes: 9370761c56b6 ("netfilter: nf_tables: convert built-in tables/chains to chain types")
    Reported-by: syzbot+156a04714799b1d480bc@syzkaller.appspotmail.com
    Signed-off-by: Pablo Neira Ayuso
    Signed-off-by: Greg Kroah-Hartman

    Pablo Neira Ayuso
     
  • commit 32c72165dbd0e246e69d16a3ad348a4851afd415 upstream.

    The bitmap allocation did not use full unsigned long sizes
    when calculating the required size and that was triggered by KASAN
    as slab-out-of-bounds read in several places. The patch fixes all
    of them.

    Reported-by: syzbot+fabca5cbf5e54f3fe2de@syzkaller.appspotmail.com
    Reported-by: syzbot+827ced406c9a1d9570ed@syzkaller.appspotmail.com
    Reported-by: syzbot+190d63957b22ef673ea5@syzkaller.appspotmail.com
    Reported-by: syzbot+dfccdb2bdb4a12ad425e@syzkaller.appspotmail.com
    Reported-by: syzbot+df0d0f5895ef1f41a65b@syzkaller.appspotmail.com
    Reported-by: syzbot+b08bd19bb37513357fd4@syzkaller.appspotmail.com
    Reported-by: syzbot+53cdd0ec0bbabd53370a@syzkaller.appspotmail.com
    Signed-off-by: Jozsef Kadlecsik
    Signed-off-by: Pablo Neira Ayuso
    Signed-off-by: Greg Kroah-Hartman

    Kadlecsik József
     
  • commit 7eaecf7963c1c8f62d62c6a8e7c439b0e7f2d365 upstream.

    syzbot reports just another NULL deref crash because of missing test
    for presence of the attribute.

    Reported-by: syzbot+cf23983d697c26c34f60@syzkaller.appspotmail.com
    Fixes: b96af92d6eaf9fadd ("netfilter: nf_tables: implement Passive OS fingerprint module in nft_osf")
    Signed-off-by: Florian Westphal
    Signed-off-by: Pablo Neira Ayuso
    Signed-off-by: Greg Kroah-Hartman

    Florian Westphal
     

23 Jan, 2020

7 commits

  • commit 335178d5429c4cee61b58f4ac80688f556630818 upstream.

    syzbot reported following crash:

    list_del corruption, ffff88808c9bb000->prev is LIST_POISON2 (dead000000000122)
    [..]
    Call Trace:
    __list_del_entry include/linux/list.h:131 [inline]
    list_del_rcu include/linux/rculist.h:148 [inline]
    nf_tables_commit+0x1068/0x3b30 net/netfilter/nf_tables_api.c:7183
    [..]

    The commit transaction list has:

    NFT_MSG_NEWTABLE
    NFT_MSG_NEWFLOWTABLE
    NFT_MSG_DELFLOWTABLE
    NFT_MSG_DELTABLE

    A missing generation check during DELTABLE processing causes it to queue
    the DELFLOWTABLE operation a second time, so we corrupt the list here:

    case NFT_MSG_DELFLOWTABLE:
    list_del_rcu(&nft_trans_flowtable(trans)->list);
    nf_tables_flowtable_notify(&trans->ctx,

    because we have two different DELFLOWTABLE transactions for the same
    flowtable. We then call list_del_rcu() twice for the same flowtable->list.

    The object handling seems to suffer from the same bug so add a generation
    check too and only queue delete transactions for flowtables/objects that
    are still active in the next generation.

    Reported-by: syzbot+37a6804945a3a13b1572@syzkaller.appspotmail.com
    Fixes: 3b49e2e94e6eb ("netfilter: nf_tables: add flow table netlink frontend")
    Signed-off-by: Florian Westphal
    Signed-off-by: Pablo Neira Ayuso
    Signed-off-by: Greg Kroah-Hartman

    Florian Westphal
     
  • commit ec7470b834fe7b5d7eff11b6677f5d7fdf5e9a91 upstream.

    This patch fixes a WARN_ON in nft_set_destroy() due to missing
    set reference count drop from the preparation phase. This is triggered
    by the module autoload path. Do not exercise the abort path from
    nft_request_module() while preparation phase cleaning up is still
    pending.

    WARNING: CPU: 3 PID: 3456 at net/netfilter/nf_tables_api.c:3740 nft_set_destroy+0x45/0x50 [nf_tables]
    [...]
    CPU: 3 PID: 3456 Comm: nft Not tainted 5.4.6-arch3-1 #1
    RIP: 0010:nft_set_destroy+0x45/0x50 [nf_tables]
    Code: e8 30 eb 83 c6 48 8b 85 80 00 00 00 48 8b b8 90 00 00 00 e8 dd 6b d7 c5 48 8b 7d 30 e8 24 dd eb c5 48 89 ef 5d e9 6b c6 e5 c5 0b c3 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 8b 7f 10 e9 52
    RSP: 0018:ffffac4f43e53700 EFLAGS: 00010202
    RAX: 0000000000000001 RBX: ffff99d63a154d80 RCX: 0000000001f88e03
    RDX: 0000000001f88c03 RSI: ffff99d6560ef0c0 RDI: ffff99d63a101200
    RBP: ffff99d617721de0 R08: 0000000000000000 R09: 0000000000000318
    R10: 00000000f0000000 R11: 0000000000000001 R12: ffffffff880fabf0
    R13: dead000000000122 R14: dead000000000100 R15: ffff99d63a154d80
    FS: 00007ff3dbd5b740(0000) GS:ffff99d6560c0000(0000) knlGS:0000000000000000
    CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    CR2: 00001cb5de6a9000 CR3: 000000016eb6a004 CR4: 00000000001606e0
    Call Trace:
    __nf_tables_abort+0x3e3/0x6d0 [nf_tables]
    nft_request_module+0x6f/0x110 [nf_tables]
    nft_expr_type_request_module+0x28/0x50 [nf_tables]
    nf_tables_expr_parse+0x198/0x1f0 [nf_tables]
    nft_expr_init+0x3b/0xf0 [nf_tables]
    nft_dynset_init+0x1e2/0x410 [nf_tables]
    nf_tables_newrule+0x30a/0x930 [nf_tables]
    nfnetlink_rcv_batch+0x2a0/0x640 [nfnetlink]
    nfnetlink_rcv+0x125/0x171 [nfnetlink]
    netlink_unicast+0x179/0x210
    netlink_sendmsg+0x208/0x3d0
    sock_sendmsg+0x5e/0x60
    ____sys_sendmsg+0x21b/0x290

    Update comment on the code to describe the new behaviour.

    Reported-by: Marco Oliverio
    Fixes: 452238e8d5ff ("netfilter: nf_tables: add and use helper for module autoload")
    Signed-off-by: Pablo Neira Ayuso
    Signed-off-by: Greg Kroah-Hartman

    Pablo Neira Ayuso
     
  • commit 9332d27d7918182add34e8043f6a754530fdd022 upstream.

    This WARN can trigger because some of the names fed to the module
    autoload function can be of arbitrary length.

    Remove the WARN and add limits for all NLA_STRING attributes.

    Reported-by: syzbot+0e63ae76d117ae1c3a01@syzkaller.appspotmail.com
    Fixes: 452238e8d5ffd8 ("netfilter: nf_tables: add and use helper for module autoload")
    Signed-off-by: Florian Westphal
    Signed-off-by: Pablo Neira Ayuso
    Signed-off-by: Greg Kroah-Hartman

    Florian Westphal
     
  • commit 9ec22d7c6c69146180577f3ad5fdf504beeaee62 upstream.

    Fixes: af308b94a2a4a5 ("netfilter: nf_tables: add tunnel support")
    Signed-off-by: Florian Westphal
    Signed-off-by: Pablo Neira Ayuso
    Signed-off-by: Greg Kroah-Hartman

    Florian Westphal
     
  • commit 1c702bf902bd37349f6d91cd7f4b372b1e46d0ed upstream.

    else we get null deref when one of the attributes is missing, both
    must be non-null.

    Reported-by: syzbot+76d0b80493ac881ff77b@syzkaller.appspotmail.com
    Fixes: aaecfdb5c5dd8ba ("netfilter: nf_tables: match on tunnel metadata")
    Signed-off-by: Florian Westphal
    Signed-off-by: Pablo Neira Ayuso
    Signed-off-by: Greg Kroah-Hartman

    Florian Westphal
     
  • commit 61177e911dad660df86a4553eb01c95ece2f6a82 upstream.

    Commit 8303b7e8f018 ("netfilter: nat: fix spurious connection timeouts")
    made nf_nat_icmp_reply_translation() use icmp_manip_pkt() as the l4
    manipulation function for the outer packet on ICMP errors.

    However, icmp_manip_pkt() assumes the packet has an 'id' field which
    is not correct for all types of ICMP messages.

    This is not correct for ICMP error packets, and leads to bogus bytes
    being written the ICMP header, which can be wrongfully regarded as
    'length' bytes by RFC 4884 compliant receivers.

    Fix by assigning the 'id' field only for ICMP messages that have this
    semantic.

    Reported-by: Shmulik Ladkani
    Fixes: 8303b7e8f018 ("netfilter: nat: fix spurious connection timeouts")
    Signed-off-by: Eyal Birger
    Acked-by: Florian Westphal
    Signed-off-by: Pablo Neira Ayuso
    Signed-off-by: Greg Kroah-Hartman

    Eyal Birger
     
  • commit c120959387efa51479056fd01dc90adfba7a590c upstream.

    map->members is freed by ip_set_free() right before using it in
    mtype_ext_cleanup() again. So we just have to move it down.

    Reported-by: syzbot+4c3cc6dbe7259dbf9054@syzkaller.appspotmail.com
    Fixes: 40cd63bf33b2 ("netfilter: ipset: Support extensions which need a per data destroy function")
    Acked-by: Jozsef Kadlecsik
    Signed-off-by: Cong Wang
    Signed-off-by: Pablo Neira Ayuso
    Signed-off-by: Greg Kroah-Hartman

    Cong Wang
     

18 Jan, 2020

3 commits

  • commit 6408c40c39d8eee5caaf97f5219b7dd4e041cc59 upstream.

    On 32-bit architectures, get_seconds() returns an unsigned 32-bit
    time value, which also matches the type used in the nft_meta
    code. This will not overflow in year 2038 as a time_t would, but
    it still suffers from the overflow problem later on in year 2106.

    Change this instance to use the time64_t type consistently
    and avoid the deprecated get_seconds().

    The nft_meta_weekday() calculation potentially gets a little slower
    on 32-bit architectures, but now it has the same behavior as on
    64-bit architectures and does not overflow.

    Fixes: 63d10e12b00d ("netfilter: nft_meta: support for time matching")
    Signed-off-by: Arnd Bergmann
    Acked-by: Phil Sutter
    Signed-off-by: Pablo Neira Ayuso
    Signed-off-by: Greg Kroah-Hartman

    Arnd Bergmann
     
  • commit 23403cd8898dbc9808d3eb2f63bc1db8a340b751 upstream.

    If hardware offload commit path fails, release all flow_rule objects.

    Fixes: c9626a2cbdb2 ("netfilter: nf_tables: add hardware offload support")
    Signed-off-by: Pablo Neira Ayuso
    Signed-off-by: Greg Kroah-Hartman

    Pablo Neira Ayuso
     
  • commit 8ca79606cdfde2e37ee4f0707b9d1874a6f0eb38 upstream.

    The .deactivate and .activate interfaces already deal with the reference
    counter. Otherwise, this results in spurious "Device is busy" errors.

    Fixes: a3c90f7a2323 ("netfilter: nf_tables: flow offload expression")
    Signed-off-by: wenxu
    Signed-off-by: Pablo Neira Ayuso
    Signed-off-by: Greg Kroah-Hartman

    wenxu
     

15 Jan, 2020

2 commits

  • commit 22dad713b8a5ff488e07b821195270672f486eb2 upstream.

    The set uadt functions assume lineno is never NULL, but it is in
    case of ip_set_utest().

    syzkaller managed to generate a netlink message that calls this with
    LINENO attr present:

    general protection fault: 0000 [#1] PREEMPT SMP KASAN
    RIP: 0010:hash_mac4_uadt+0x1bc/0x470 net/netfilter/ipset/ip_set_hash_mac.c:104
    Call Trace:
    ip_set_utest+0x55b/0x890 net/netfilter/ipset/ip_set_core.c:1867
    nfnetlink_rcv_msg+0xcf2/0xfb0 net/netfilter/nfnetlink.c:229
    netlink_rcv_skb+0x177/0x450 net/netlink/af_netlink.c:2477
    nfnetlink_rcv+0x1ba/0x460 net/netfilter/nfnetlink.c:563

    pass a dummy lineno storage, its easier than patching all set
    implementations.

    This seems to be a day-0 bug.

    Cc: Jozsef Kadlecsik
    Reported-by: syzbot+34bd2369d38707f3f4a7@syzkaller.appspotmail.com
    Fixes: a7b4f989a6294 ("netfilter: ipset: IP set core support")
    Signed-off-by: Florian Westphal
    Acked-by: Jozsef Kadlecsik
    Signed-off-by: Pablo Neira Ayuso
    Signed-off-by: Greg Kroah-Hartman

    Florian Westphal
     
  • commit 1d9a7acd3d1e74c2d150d8934f7f55bed6d70858 upstream.

    The timeout pointer can be NULL which means we should modify the
    per-nets timeout instead.

    All do this, except sctp and dccp which instead give:

    general protection fault: 0000 [#1] PREEMPT SMP KASAN
    net/netfilter/nf_conntrack_proto_dccp.c:682
    ctnl_timeout_parse_policy+0x150/0x1d0 net/netfilter/nfnetlink_cttimeout.c:67
    cttimeout_default_set+0x150/0x1c0 net/netfilter/nfnetlink_cttimeout.c:368
    nfnetlink_rcv_msg+0xcf2/0xfb0 net/netfilter/nfnetlink.c:229
    netlink_rcv_skb+0x177/0x450 net/netlink/af_netlink.c:2477

    Reported-by: syzbot+46a4ad33f345d1dd346e@syzkaller.appspotmail.com
    Fixes: c779e849608a8 ("netfilter: conntrack: remove get_timeout() indirection")
    Signed-off-by: Florian Westphal
    Signed-off-by: Pablo Neira Ayuso
    Signed-off-by: Greg Kroah-Hartman

    Florian Westphal
     

12 Jan, 2020

7 commits

  • [ Upstream commit 81ec61074bcf68acfcb2820cda3ff9d9984419c7 ]

    If the rule only specifies the matching side, return EOPNOTSUPP.
    Otherwise, the front-end relies on the drivers to reject this rule.

    Fixes: c9626a2cbdb2 ("netfilter: nf_tables: add hardware offload support")
    Signed-off-by: Pablo Neira Ayuso
    Signed-off-by: Sasha Levin

    Pablo Neira Ayuso
     
  • [ Upstream commit fd57d0cbe187e93f63777d36e9f49293311d417f ]

    Use __nft_obj_type_get() instead, otherwise there is a module reference
    counter leak.

    Fixes: d62d0ba97b58 ("netfilter: nf_tables: Introduce stateful object update operation")
    Signed-off-by: Pablo Neira Ayuso
    Signed-off-by: Sasha Levin

    Pablo Neira Ayuso
     
  • [ Upstream commit 0d2c96af797ba149e559c5875c0151384ab6dd14 ]

    Userspace might bogusly sent NFT_DATA_VERDICT in several netlink
    attributes that assume NFT_DATA_VALUE. Moreover, make sure that error
    path invokes nft_data_release() to decrement the reference count on the
    chain object.

    Fixes: 96518518cc41 ("netfilter: add nftables")
    Fixes: 0f3cd9b36977 ("netfilter: nf_tables: add range expression")
    Signed-off-by: Pablo Neira Ayuso
    Signed-off-by: Sasha Levin

    Pablo Neira Ayuso
     
  • [ Upstream commit bffc124b6fe37d0ae9b428d104efb426403bb5c9 ]

    Only NFTA_SET_ELEM_KEY and NFTA_SET_ELEM_FLAGS make sense for elements
    whose NFT_SET_ELEM_INTERVAL_END flag is set on.

    Fixes: 96518518cc41 ("netfilter: add nftables")
    Signed-off-by: Pablo Neira Ayuso
    Signed-off-by: Sasha Levin

    Pablo Neira Ayuso
     
  • [ Upstream commit db3b665dd77b34e34df00e17d7b299c98fcfb2c5 ]

    The existing rbtree implementation might store consecutive elements
    where the closing element and the opening element might overlap, eg.

    [ a, a+1) [ a+1, a+2)

    This patch removes the optimization for non-anonymous sets in the exact
    matching case, where it is assumed to stop searching in case that the
    closing element is found. Instead, invalidate candidate interval and
    keep looking further in the tree.

    The lookup/get operation might return false, while there is an element
    in the rbtree. Moreover, the get operation returns true as if a+2 would
    be in the tree. This happens with named sets after several set updates.

    The existing lookup optimization (that only works for the anonymous
    sets) might not reach the opening [ a+1,... element if the closing
    ...,a+1) is found in first place when walking over the rbtree. Hence,
    walking the full tree in that case is needed.

    This patch fixes the lookup and get operations.

    Fixes: e701001e7cbe ("netfilter: nft_rbtree: allow adjacent intervals with dynamic updates")
    Fixes: ba0e4d9917b4 ("netfilter: nf_tables: get set elements via netlink")
    Signed-off-by: Pablo Neira Ayuso
    Signed-off-by: Sasha Levin

    Pablo Neira Ayuso
     
  • [ Upstream commit d1f4c966475c6dd2545c6625022cb24e878bee11 ]

    Check for the NETDEV_UNREGISTER event from the nft_offload_netdev_event
    function, which is the event that actually triggers the clean up.

    Fixes: 06d392cbe3db ("netfilter: nf_tables_offload: remove rules when the device unregisters")
    Signed-off-by: wenxu
    Signed-off-by: Pablo Neira Ayuso
    Signed-off-by: Sasha Levin

    wenxu
     
  • [ Upstream commit 18a110b022a5c02e7dc9f6109d0bd93e58ac6ebb ]

    Curtis Taylor and Jon Maxwell reported and debugged a crash on 3.10
    based kernel.

    Crash occurs in ctnetlink_conntrack_events because net->nfnl socket is
    NULL. The nfnl socket was set to NULL by netns destruction running on
    another cpu.

    The exiting network namespace calls the relevant destructors in the
    following order:

    1. ctnetlink_net_exit_batch

    This nulls out the event callback pointer in struct netns.

    2. nfnetlink_net_exit_batch

    This nulls net->nfnl socket and frees it.

    3. nf_conntrack_cleanup_net_list

    This removes all remaining conntrack entries.

    This is order is correct. The only explanation for the crash so ar is:

    cpu1: conntrack is dying, eviction occurs:
    -> nf_ct_delete()
    -> nf_conntrack_event_report \
    -> nf_conntrack_eventmask_report
    -> notify->fcn() (== ctnetlink_conntrack_events).

    cpu1: a. fetches rcu protected pointer to obtain ctnetlink event callback.
    b. gets interrupted.
    cpu2: runs netns exit handlers:
    a runs ctnetlink destructor, event cb pointer set to NULL.
    b runs nfnetlink destructor, nfnl socket is closed and set to NULL.
    cpu1: c. resumes and trips over NULL net->nfnl.

    Problem appears to be that ctnetlink_net_exit_batch only prevents future
    callers of nf_conntrack_eventmask_report() from obtaining the callback.
    It doesn't wait of other cpus that might have already obtained the
    callbacks address.

    I don't see anything in upstream kernels that would prevent similar
    crash: We need to wait for all cpus to have exited the event callback.

    Fixes: 9592a5c01e79dbc59eb56fa ("netfilter: ctnetlink: netns support")
    Signed-off-by: Florian Westphal
    Signed-off-by: Pablo Neira Ayuso
    Signed-off-by: Sasha Levin

    Florian Westphal
     

09 Jan, 2020

2 commits

  • commit 0b9173f4688dfa7c5d723426be1d979c24ce3d51 upstream.

    Bridge packets that are forwarded have skb->dst == NULL and get
    dropped by the check introduced by
    b60a77386b1d4868f72f6353d35dabe5fbe981f2 (net: make skb_dst_force
    return true when dst is refcounted).

    To fix this we check skb_dst() before skb_dst_force(), so we don't
    drop skb packet with dst == NULL. This holds also for skb at the
    PRE_ROUTING hook so we remove the second check.

    Fixes: b60a77386b1d ("net: make skb_dst_force return true when dst is refcounted")
    Signed-off-by: Marco Oliverio
    Signed-off-by: Rocco Folino
    Acked-by: Florian Westphal
    Signed-off-by: Pablo Neira Ayuso
    Signed-off-by: Greg Kroah-Hartman

    Marco Oliverio
     
  • [ Upstream commit 8cb4ec44de42b99b92399b4d1daf3dc430ed0186 ]

    On Big Endian architectures, u16 port value was extracted from the wrong
    parts of u32 sreg_port, just like commit 10596608c4d62 ("netfilter:
    nf_tables: fix mismatch in big-endian system") describes.

    Fixes: 4ed8eb6570a49 ("netfilter: nf_tables: Add native tproxy support")
    Signed-off-by: Phil Sutter
    Acked-by: Florian Westphal
    Acked-by: Máté Eckl
    Signed-off-by: Pablo Neira Ayuso
    Signed-off-by: Sasha Levin

    Phil Sutter
     

05 Jan, 2020

1 commit

  • [ Upstream commit bd085ef678b2cc8c38c105673dfe8ff8f5ec0c57 ]

    The MTU update code is supposed to be invoked in response to real
    networking events that update the PMTU. In IPv6 PMTU update function
    __ip6_rt_update_pmtu() we called dst_confirm_neigh() to update neighbor
    confirmed time.

    But for tunnel code, it will call pmtu before xmit, like:
    - tnl_update_pmtu()
    - skb_dst_update_pmtu()
    - ip6_rt_update_pmtu()
    - __ip6_rt_update_pmtu()
    - dst_confirm_neigh()

    If the tunnel remote dst mac address changed and we still do the neigh
    confirm, we will not be able to update neigh cache and ping6 remote
    will failed.

    So for this ip_tunnel_xmit() case, _EVEN_ if the MTU is changed, we
    should not be invoking dst_confirm_neigh() as we have no evidence
    of successful two-way communication at this point.

    On the other hand it is also important to keep the neigh reachability fresh
    for TCP flows, so we cannot remove this dst_confirm_neigh() call.

    To fix the issue, we have to add a new bool parameter for dst_ops.update_pmtu
    to choose whether we should do neigh update or not. I will add the parameter
    in this patch and set all the callers to true to comply with the previous
    way, and fix the tunnel code one by one on later patches.

    v5: No change.
    v4: No change.
    v3: Do not remove dst_confirm_neigh, but add a new bool parameter in
    dst_ops.update_pmtu to control whether we should do neighbor confirm.
    Also split the big patch to small ones for each area.
    v2: Remove dst_confirm_neigh in __ip6_rt_update_pmtu.

    Suggested-by: David Miller
    Reviewed-by: Guillaume Nault
    Acked-by: David Ahern
    Signed-off-by: Hangbin Liu
    Signed-off-by: David S. Miller
    Signed-off-by: Greg Kroah-Hartman

    Hangbin Liu
     

18 Dec, 2019

1 commit

  • [ Upstream commit dbad3408896c3c5722ec9cda065468b3df16c5bf ]

    With indirect blocks, a driver can register for callbacks from a device
    that is does not 'own', for example, a tunnel device. When registering to
    or unregistering from a new device, a callback is triggered to generate
    a bind/unbind event. This, in turn, allows the driver to receive any
    existing rules or to properly clean up installed rules.

    When first added, it was assumed that all indirect block registrations
    would be for ingress offloads. However, the NFP driver can, in some
    instances, support clsact qdisc binds for egress offload.

    Change the name of the indirect block callback command in flow_offload to
    remove the 'ingress' identifier from it. While this does not change
    functionality, a follow up patch will implement a more more generic
    callback than just those currently just supporting ingress offload.

    Fixes: 4d12ba42787b ("nfp: flower: allow offloading of matches on 'internal' ports")
    Signed-off-by: John Hurley
    Acked-by: Jakub Kicinski
    Signed-off-by: David S. Miller
    Signed-off-by: Greg Kroah-Hartman

    John Hurley
     

05 Nov, 2019

4 commits

  • Jozsef Kadlecsik says:

    ====================
    ipset patches for nf

    - Fix the error code in ip_set_sockfn_get() when copy_to_user() is used,
    from Dan Carpenter.
    - The IPv6 part was missed when fixing copying the right MAC address
    in the patch "netfilter: ipset: Copy the right MAC address in bitmap:ip,mac
    and hash:ip,mac sets", it is completed now by Stefano Brivio.
    - ipset nla_policies are fixed to fully support NL_VALIDATE_STRICT and
    the code is converted from deprecated parsings to verified ones.
    ====================

    Signed-off-by: Pablo Neira Ayuso

    Pablo Neira Ayuso
     
  • Do not try to bind a chain again if it exists, otherwise the driver
    returns EBUSY.

    Fixes: c9626a2cbdb2 ("netfilter: nf_tables: add hardware offload support")
    Signed-off-by: Pablo Neira Ayuso

    Pablo Neira Ayuso
     
  • Userspace never includes the NFT_BASE_CHAIN flag, this flag is inferred
    from the NFTA_CHAIN_HOOK atribute. The chain update path does not allow
    to update flags at this stage, the existing sanity check bogusly hits
    EOPNOTSUPP in the basechain case if the offload flag is set on.

    Signed-off-by: Pablo Neira Ayuso

    Pablo Neira Ayuso
     
  • If the object type doesn't implement an update operation and the user tries to
    update it will silently ignore the update operation.

    Fixes: aa4095a156b5 ("netfilter: nf_tables: fix possible null-pointer dereference in object update")
    Signed-off-by: Fernando Fernandez Mancera
    Signed-off-by: Pablo Neira Ayuso

    Fernando Fernandez Mancera