06 Apr, 2020

1 commit

  • 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 24791b9aa1ab ("netfilter: nft_set_bitmap: initialize set
    element extension in lookups") which is not required anymore.

    Fixes: 339706bc21c1 ("netfilter: nft_lookup: update element stateful expression")
    Signed-off-by: Pablo Neira Ayuso

    Pablo Neira Ayuso
     

15 Mar, 2020

1 commit


20 Sep, 2019

1 commit

  • This un-breaks lookups in sets that have the 'dynamic' flag set.
    Given this active example configuration:

    table filter {
    set set1 {
    type ipv4_addr
    size 64
    flags dynamic,timeout
    timeout 1m
    }

    chain input {
    type filter hook input priority 0; policy accept;
    }
    }

    ... this works:
    nft add rule ip filter input add @set1 { ip saddr }

    -> whenever rule is triggered, the source ip address is inserted
    into the set (if it did not exist).

    This won't work:
    nft add rule ip filter input ip saddr @set1 counter
    Error: Could not process rule: Operation not supported

    In other words, we can add entries to the set, but then can't make
    matching decision based on that set.

    That is just wrong -- all set backends support lookups (else they would
    not be very useful).
    The failure comes from an explicit rejection in nft_lookup.c.

    Looking at the history, it seems like NFT_SET_EVAL used to mean
    'set contains expressions' (aka. "is a meter"), for instance something like

    nft add rule ip filter input meter example { ip saddr limit rate 10/second }
    or
    nft add rule ip filter input meter example { ip saddr counter }

    The actual meaning of NFT_SET_EVAL however, is
    'set can be updated from the packet path'.

    'meters' and packet-path insertions into sets, such as
    'add @set { ip saddr }' use exactly the same kernel code (nft_dynset.c)
    and thus require a set backend that provides the ->update() function.

    The only set that provides this also is the only one that has the
    NFT_SET_EVAL feature flag.

    Removing the wrong check makes the above example work.
    While at it, also fix the flag check during set instantiation to
    allow supported combinations only.

    Fixes: 8aeff920dcc9b3f ("netfilter: nf_tables: add stateful object reference to set elements")
    Signed-off-by: Florian Westphal
    Signed-off-by: Pablo Neira Ayuso

    Florian Westphal
     

19 Jun, 2019

1 commit

  • Based on 2 normalized pattern(s):

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license version 2 as
    published by the free software foundation

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license version 2 as
    published by the free software foundation #

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-only

    has been chosen to replace the boilerplate/reference in 4122 file(s).

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Enrico Weigelt
    Reviewed-by: Kate Stewart
    Reviewed-by: Allison Randal
    Cc: linux-spdx@vger.kernel.org
    Link: https://lkml.kernel.org/r/20190604081206.933168790@linutronix.de
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

11 Mar, 2019

1 commit


05 Feb, 2019

1 commit

  • Anonymous sets that are bound to rules from the same transaction trigger
    a kernel splat from the abort path due to double set list removal and
    double free.

    This patch updates the logic to search for the transaction that is
    responsible for creating the set and disable the set list removal and
    release, given the rule is now responsible for this. Lookup is reverse
    since the transaction that adds the set is likely to be at the tail of
    the list.

    Moreover, this patch adds the unbind step to deliver the event from the
    commit path. This should not be done from the worker thread, since we
    have no guarantees of in-order delivery to the listener.

    This patch removes the assumption that both activate and deactivate
    callbacks need to be provided.

    Fixes: cd5125d8f518 ("netfilter: nf_tables: split set destruction in deactivate and destroy phase")
    Reported-by: Mikhail Morfikov
    Signed-off-by: Pablo Neira Ayuso

    Pablo Neira Ayuso
     

17 Sep, 2018

1 commit

  • Splits unbind_set into destroy_set and unbinding operation.

    Unbinding removes set from lists (so new transaction would not
    find it anymore) but keeps memory allocated (so packet path continues
    to work).

    Rebind function is added to allow unrolling in case transaction
    that wants to remove set is aborted.

    Destroy function is added to free the memory, but this could occur
    outside of transaction in the future.

    Signed-off-by: Florian Westphal
    Signed-off-by: Pablo Neira Ayuso

    Florian Westphal
     

30 Jul, 2018

1 commit


18 Jul, 2018

1 commit

  • The level of struct nft_ctx is updated by nf_tables_check_loops(). That
    is used to validate jumpstack depth. But jumpstack validation routine
    doesn't update and validate recursively. So, in some cases, chain depth
    can be bigger than the NFT_JUMP_STACK_SIZE.

    After this patch, The jumpstack validation routine is located in the
    nft_chain_validate(). When new rules or new set elements are added, the
    nft_table_validate() is called by the nf_tables_newrule and the
    nf_tables_newsetelem. The nft_table_validate() calls the
    nft_chain_validate() that visit all their children chains recursively.
    So it can update depth of chain certainly.

    Reproducer:
    %cat ./test.sh
    #!/bin/bash
    nft add table ip filter
    nft add chain ip filter input { type filter hook input priority 0\; }
    for ((i=0;i 0b 31 c0 e9 bc 02 00 00 44 8b ad 64 fd
    [ 253.933807] RSP: 0018:ffff88011b807570 EFLAGS: 00010212
    [ 253.933807] RAX: 00000000fffffffd RBX: ffff88011b807660 RCX: 0000000000000000
    [ 253.933807] RDX: 0000000000000010 RSI: ffff880112b39d78 RDI: ffff88011b807670
    [ 253.933807] RBP: ffff88011b807850 R08: ffffed0023700ece R09: ffffed0023700ecd
    [ 253.933807] R10: ffff88011b80766f R11: ffffed0023700ece R12: ffff88011b807898
    [ 253.933807] R13: ffff880112b39d80 R14: ffff880112b39d60 R15: dffffc0000000000
    [ 253.933807] FS: 0000000000000000(0000) GS:ffff88011b800000(0000) knlGS:0000000000000000
    [ 253.933807] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    [ 253.933807] CR2: 00000000014f1008 CR3: 000000006b216000 CR4: 00000000001006e0
    [ 253.933807] Call Trace:
    [ 253.933807]
    [ 253.933807] ? sched_clock_cpu+0x132/0x170
    [ 253.933807] ? __nft_trace_packet+0x180/0x180 [nf_tables]
    [ 253.933807] ? sched_clock_cpu+0x132/0x170
    [ 253.933807] ? debug_show_all_locks+0x290/0x290
    [ 253.933807] ? __lock_acquire+0x4835/0x4af0
    [ 253.933807] ? inet_ehash_locks_alloc+0x1a0/0x1a0
    [ 253.933807] ? unwind_next_frame+0x159e/0x1840
    [ 253.933807] ? __read_once_size_nocheck.constprop.4+0x5/0x10
    [ 253.933807] ? nft_do_chain_ipv4+0x197/0x1e0 [nf_tables]
    [ 253.933807] ? nft_do_chain+0x5/0xdf0 [nf_tables]
    [ 253.933807] nft_do_chain_ipv4+0x197/0x1e0 [nf_tables]
    [ 253.933807] ? nft_do_chain_arp+0xb0/0xb0 [nf_tables]
    [ 253.933807] ? __lock_is_held+0x9d/0x130
    [ 253.933807] nf_hook_slow+0xc4/0x150
    [ 253.933807] ip_local_deliver+0x28b/0x380
    [ 253.933807] ? ip_call_ra_chain+0x3e0/0x3e0
    [ 253.933807] ? ip_rcv_finish+0x1610/0x1610
    [ 253.933807] ip_rcv+0xbcc/0xcc0
    [ 253.933807] ? debug_show_all_locks+0x290/0x290
    [ 253.933807] ? ip_local_deliver+0x380/0x380
    [ 253.933807] ? __lock_is_held+0x9d/0x130
    [ 253.933807] ? ip_local_deliver+0x380/0x380
    [ 253.933807] __netif_receive_skb_core+0x1c9c/0x2240

    Signed-off-by: Taehee Yoo
    Signed-off-by: Pablo Neira Ayuso

    Taehee Yoo
     

01 Jun, 2018

1 commit

  • 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 003087911af2 ("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: Taehee Yoo
    Signed-off-by: Pablo Neira Ayuso

    Pablo Neira Ayuso
     

30 Mar, 2018

1 commit


07 Mar, 2017

1 commit


24 Jan, 2017

1 commit

  • Currently, if the user add a stateful object with the name size exceed
    NFT_OBJ_MAXNAMELEN - 1 (i.e. 31), we truncate it down to 31 silently.
    This is not friendly, furthermore, this will cause duplicated stateful
    objects when the first 31 characters of the name is same. So limit the
    stateful object's name size to NFT_OBJ_MAXNAMELEN - 1.

    After apply this patch, error message will be printed out like this:
    # name_32=$(printf "%0.sQ" {1..32})
    # nft add counter filter $name_32
    :1:1-52: Error: Could not process rule: Numerical result out
    of range
    add counter filter QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    Also this patch cleans up the codes which missing the name size limit
    validation in nftables.

    Fixes: e50092404c1b ("netfilter: nf_tables: add stateful objects")
    Signed-off-by: Liping Zhang
    Signed-off-by: Pablo Neira Ayuso

    Liping Zhang
     

10 Nov, 2016

1 commit

  • Some basic expressions are built into nf_tables.ko, such as nft_cmp,
    nft_lookup, nft_range and so on. But these basic expressions' init
    routine is a little ugly, too many goto errX labels, and we forget
    to call nft_range_module_exit in the exit routine, although it is
    harmless.

    Acctually, the init and exit routines of these basic expressions
    are same, i.e. do nft_register_expr in the init routine and do
    nft_unregister_expr in the exit routine.

    So it's better to arrange them into an array and deal with them
    together.

    Signed-off-by: Liping Zhang
    Signed-off-by: Pablo Neira Ayuso

    Liping Zhang
     

03 Nov, 2016

1 commit


23 Sep, 2016

1 commit


11 Jul, 2016

1 commit


24 Jun, 2016

2 commits

  • Introduce a new configuration option for this expression, which allows users
    to invert the logic of set lookups.

    In _init() we will now return EINVAL if NFT_LOOKUP_F_INV is in anyway
    related to a map lookup.

    The code in the _eval() function has been untangled and updated to sopport the
    XOR of options, as we should consider 4 cases:
    * lookup false, invert false -> NFT_BREAK
    * lookup false, invert true -> return w/o NFT_BREAK
    * lookup true, invert false -> return w/o NFT_BREAK
    * lookup true, invert true -> NFT_BREAK

    Signed-off-by: Arturo Borrero Gonzalez
    Signed-off-by: Pablo Neira Ayuso

    Arturo Borrero
     
  • Similar to ("netfilter: nf_tables: add generation mask to tables").

    Signed-off-by: Pablo Neira Ayuso

    Pablo Neira Ayuso
     

14 Apr, 2015

1 commit

  • Add a set flag to indicate that the set is used as a state table and
    contains expressions for evaluation. This operation is mutually
    exclusive with the mapping operation, so sets specifying both are
    rejected. The lookup expression also rejects binding to state tables
    since it only deals with loopup and map operations.

    Signed-off-by: Patrick McHardy
    Signed-off-by: Pablo Neira Ayuso

    Patrick McHardy
     

13 Apr, 2015

6 commits

  • Switch the nf_tables registers from 128 bit addressing to 32 bit
    addressing to support so called concatenations, where multiple values
    can be concatenated over multiple registers for O(1) exact matches of
    multiple dimensions using sets.

    The old register values are mapped to areas of 128 bits for compatibility.
    When dumping register numbers, values are expressed using the old values
    if they refer to the beginning of a 128 bit area for compatibility.

    To support concatenations, register loads of less than a full 32 bit
    value need to be padded. This mainly affects the payload and exthdr
    expressions, which both unconditionally zero the last word before
    copying the data.

    Userspace fully passes the testsuite using both old and new register
    addressing.

    Signed-off-by: Patrick McHardy
    Signed-off-by: Pablo Neira Ayuso

    Patrick McHardy
     
  • Add helper functions to parse and dump register values in netlink attributes.
    These helpers will later be changed to take care of translation between the
    old 128 bit and the new 32 bit register numbers.

    Signed-off-by: Patrick McHardy
    Signed-off-by: Pablo Neira Ayuso

    Patrick McHardy
     
  • Replace the array of registers passed to expressions by a struct nft_regs,
    containing the verdict as a seperate member, which aliases to the
    NFT_REG_VERDICT register.

    This is needed to seperate the verdict from the data registers completely,
    so their size can be changed.

    Signed-off-by: Patrick McHardy
    Signed-off-by: Pablo Neira Ayuso

    Patrick McHardy
     
  • Change nft_validate_input_register() to not only validate the input
    register number, but also the length of the load, and rename it to
    nft_validate_register_load() to reflect that change.

    Signed-off-by: Patrick McHardy
    Signed-off-by: Pablo Neira Ayuso

    Patrick McHardy
     
  • All users of nft_validate_register_store() first invoke
    nft_validate_output_register(). There is in fact no use for using it
    on its own, so simplify the code by folding the functionality into
    nft_validate_register_store() and kill it.

    Signed-off-by: Patrick McHardy
    Signed-off-by: Pablo Neira Ayuso

    Patrick McHardy
     
  • In preparation of validating the length of a register store, use
    nft_validate_register_store() in nft_lookup instead of open coding the
    validation.

    Signed-off-by: Patrick McHardy
    Signed-off-by: Pablo Neira Ayuso

    Patrick McHardy
     

08 Apr, 2015

1 commit

  • Currently a set binding is assumed to be related to a lookup and, in
    case of maps, a data load.

    In order to use bindings for set updates, the loop detection checks
    must be restricted to map operations only. Add a flags member to the
    binding struct to hold the set "action" flags such as NFT_SET_MAP,
    and perform loop detection based on these.

    Signed-off-by: Patrick McHardy
    Signed-off-by: Pablo Neira Ayuso

    Patrick McHardy
     

26 Mar, 2015

1 commit


31 Jan, 2015

1 commit


19 May, 2014

1 commit

  • This patch reworks the nf_tables API so set updates are included in
    the same batch that contains rule updates. This speeds up rule-set
    updates since we skip a dialog of four messages between kernel and
    user-space (two on each direction), from:

    1) create the set and send netlink message to the kernel
    2) process the response from the kernel that contains the allocated name.
    3) add the set elements and send netlink message to the kernel.
    4) process the response from the kernel (to check for errors).

    To:

    1) add the set to the batch.
    2) add the set elements to the batch.
    3) add the rule that points to the set.
    4) send batch to the kernel.

    This also introduces an internal set ID (NFTA_SET_ID) that is unique
    in the batch so set elements and rules can refer to new sets.

    Backward compatibility has been only retained in userspace, this
    means that new nft versions can talk to the kernel both in the new
    and the old fashion.

    Signed-off-by: Pablo Neira Ayuso

    Pablo Neira Ayuso
     

08 Mar, 2014

2 commits


10 Feb, 2014

1 commit

  • Include appropriate header file net/netfilter/nf_tables_core.h in
    net/netfilter/nft_lookup.c because it has prototype declaration of
    functions defined in net/netfilter/nft_lookup.c.

    This eliminates the following warning in net/netfilter/nft_lookup.c:
    net/netfilter/nft_lookup.c:133:12: warning: no previous prototype for ‘nft_lookup_module_init’ [-Wmissing-prototypes]
    net/netfilter/nft_lookup.c:138:6: warning: no previous prototype for ‘nft_lookup_module_exit’ [-Wmissing-prototypes]

    Signed-off-by: Rashika Kheria
    Reviewed-by: Josh Triplett
    Signed-off-by: David S. Miller

    Rashika Kheria
     

14 Oct, 2013

2 commits

  • Split the expression ops into two parts and support overloading of
    the runtime expression ops based on the requested function through
    a ->select_ops() callback.

    This can be used to provide optimized implementations, for instance
    for loading small aligned amounts of data from the packet or inlining
    frequently used operations into the main evaluation loop.

    Signed-off-by: Patrick McHardy
    Signed-off-by: Pablo Neira Ayuso

    Patrick McHardy
     
  • This patch adds the new netlink API for maintaining nf_tables sets
    independently of the ruleset. The API supports the following operations:

    - creation of sets
    - deletion of sets
    - querying of specific sets
    - dumping of all sets

    - addition of set elements
    - removal of set elements
    - dumping of all set elements

    Sets are identified by name, each table defines an individual namespace.
    The name of a set may be allocated automatically, this is mostly useful
    in combination with the NFT_SET_ANONYMOUS flag, which destroys a set
    automatically once the last reference has been released.

    Sets can be marked constant, meaning they're not allowed to change while
    linked to a rule. This allows to perform lockless operation for set
    types that would otherwise require locking.

    Additionally, if the implementation supports it, sets can (as before) be
    used as maps, associating a data value with each key (or range), by
    specifying the NFT_SET_MAP flag and can be used for interval queries by
    specifying the NFT_SET_INTERVAL flag.

    Set elements are added and removed incrementally. All element operations
    support batching, reducing netlink message and set lookup overhead.

    The old "set" and "hash" expressions are replaced by a generic "lookup"
    expression, which binds to the specified set. Userspace is not aware
    of the actual set implementation used by the kernel anymore, all
    configuration options are generic.

    Currently the implementation selection logic is largely missing and the
    kernel will simply use the first registered implementation supporting the
    requested operation. Eventually, the plan is to have userspace supply a
    description of the data characteristics and select the implementation
    based on expected performance and memory use.

    This patch includes the new 'lookup' expression to look up for element
    matching in the set.

    This patch includes kernel-doc descriptions for this set API and it
    also includes the following fixes.

    From Patrick McHardy:
    * netfilter: nf_tables: fix set element data type in dumps
    * netfilter: nf_tables: fix indentation of struct nft_set_elem comments
    * netfilter: nf_tables: fix oops in nft_validate_data_load()
    * netfilter: nf_tables: fix oops while listing sets of built-in tables
    * netfilter: nf_tables: destroy anonymous sets immediately if binding fails
    * netfilter: nf_tables: propagate context to set iter callback
    * netfilter: nf_tables: add loop detection

    From Pablo Neira Ayuso:
    * netfilter: nf_tables: allow to dump all existing sets
    * netfilter: nf_tables: fix wrong type for flags variable in newelem

    Signed-off-by: Patrick McHardy
    Signed-off-by: Pablo Neira Ayuso

    Patrick McHardy