1. 25 4月, 2015 1 次提交
  2. 14 4月, 2015 3 次提交
  3. 13 4月, 2015 10 次提交
  4. 08 4月, 2015 5 次提交
  5. 01 4月, 2015 4 次提交
  6. 26 3月, 2015 5 次提交
    • P
      netfilter: nf_tables: implement set transaction support · cc02e457
      Patrick McHardy 提交于
      Set elements are the last object type not supporting transaction support.
      Implement similar to the existing rule transactions:
      
      The global transaction counter keeps track of two generations, current
      and next. Each element contains a bitmask specifying in which generations
      it is inactive.
      
      New elements start out as inactive in the current generation and active
      in the next. On commit, the previous next generation becomes the current
      generation and the element becomes active. The bitmask is then cleared
      to indicate that the element is active in all future generations. If the
      transaction is aborted, the element is removed from the set before it
      becomes active.
      
      When removing an element, it gets marked as inactive in the next generation.
      On commit the next generation becomes active and the therefor the element
      inactive. It is then taken out of then set and released. On abort, the
      element is marked as active for the next generation again.
      
      Lookups ignore elements not active in the current generation.
      
      The current set types (hash/rbtree) both use a field in the extension area
      to store the generation mask. This (currently) does not require any
      additional memory since we have some free space in there.
      Signed-off-by: NPatrick McHardy <kaber@trash.net>
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      cc02e457
    • P
      netfilter: nf_tables: add transaction helper functions · ea4bd995
      Patrick McHardy 提交于
      Add some helper functions for building the genmask as preparation for
      set transactions.
      
      Also add a little documentation how this stuff actually works.
      Signed-off-by: NPatrick McHardy <kaber@trash.net>
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      ea4bd995
    • P
      netfilter: nf_tables: consolide set element destruction · 61edafbb
      Patrick McHardy 提交于
      With the conversion to set extensions, it is now possible to consolidate
      the different set element destruction functions.
      
      The set implementations' ->remove() functions are changed to only take
      the element out of their internal data structures. Elements will be freed
      in a batched fashion after the global transaction's completion RCU grace
      period.
      
      This reduces the amount of grace periods required for nft_hash from N
      to zero additional ones, additionally this guarantees that the set
      elements' extensions of all implementations can be used under RCU
      protection.
      Signed-off-by: NPatrick McHardy <kaber@trash.net>
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      61edafbb
    • P
      netfilter: nf_tables: convert hash and rbtree to set extensions · fe2811eb
      Patrick McHardy 提交于
      The set implementations' private struct will only contain the elements
      needed to maintain the search structure, all other elements are moved
      to the set extensions.
      
      Element allocation and initialization is performed centrally by
      nf_tables_api instead of by the different set implementations'
      ->insert() functions. A new "elemsize" member in the set ops specifies
      the amount of memory to reserve for internal usage. Destruction
      will also be moved out of the set implementations by a following patch.
      
      Except for element allocation, the patch is a simple conversion to
      using data from the extension area.
      Signed-off-by: NPatrick McHardy <kaber@trash.net>
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      fe2811eb
    • P
      netfilter: nf_tables: add set extensions · 3ac4c07a
      Patrick McHardy 提交于
      Add simple set extension infrastructure for maintaining variable sized
      and optional per element data.
      Signed-off-by: NPatrick McHardy <kaber@trash.net>
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      3ac4c07a
  7. 25 3月, 2015 1 次提交
  8. 23 3月, 2015 1 次提交
  9. 18 3月, 2015 1 次提交
  10. 17 3月, 2015 1 次提交
  11. 06 3月, 2015 1 次提交
  12. 05 3月, 2015 4 次提交
    • P
      netfilter: nf_tables: fix error handling of rule replacement · 59900e0a
      Pablo Neira Ayuso 提交于
      In general, if a transaction object is added to the list successfully,
      we can rely on the abort path to undo what we've done. This allows us to
      simplify the error handling of the rule replacement path in
      nf_tables_newrule().
      
      This implicitly fixes an unnecessary removal of the old rule, which
      needs to be left in place if we fail to replace.
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      59900e0a
    • P
      netfilter: nf_tables: fix userdata length overflow · 86f1ec32
      Patrick McHardy 提交于
      The NFT_USERDATA_MAXLEN is defined to 256, however we only have a u8
      to store its size. Introduce a struct nft_userdata which contains a
      length field and indicate its presence using a single bit in the rule.
      
      The length field of struct nft_userdata is also a u8, however we don't
      store zero sized data, so the actual length is udata->len + 1.
      Signed-off-by: NPatrick McHardy <kaber@trash.net>
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      86f1ec32
    • P
      netfilter: nf_tables: check for overflow of rule dlen field · 9889840f
      Patrick McHardy 提交于
      Check that the space required for the expressions doesn't exceed the
      size of the dlen field, which would lead to the iterators crashing.
      Signed-off-by: NPatrick McHardy <kaber@trash.net>
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      9889840f
    • P
      netfilter: nf_tables: fix transaction race condition · 8670c3a5
      Patrick McHardy 提交于
      A race condition exists in the rule transaction code for rules that
      get added and removed within the same transaction.
      
      The new rule starts out as inactive in the current and active in the
      next generation and is inserted into the ruleset. When it is deleted,
      it is additionally set to inactive in the next generation as well.
      
      On commit the next generation is begun, then the actions are finalized.
      For the new rule this would mean clearing out the inactive bit for
      the previously current, now next generation.
      
      However nft_rule_clear() clears out the bits for *both* generations,
      activating the rule in the current generation, where it should be
      deactivated due to being deleted. The rule will thus be active until
      the deletion is finalized, removing the rule from the ruleset.
      
      Similarly, when aborting a transaction for the same case, the undo
      of insertion will remove it from the RCU protected rule list, the
      deletion will clear out all bits. However until the next RCU
      synchronization after all operations have been undone, the rule is
      active on CPUs which can still see the rule on the list.
      
      Generally, there may never be any modifications of the current
      generations' inactive bit since this defeats the entire purpose of
      atomicity. Change nft_rule_clear() to only touch the next generations
      bit to fix this.
      Signed-off-by: NPatrick McHardy <kaber@trash.net>
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      8670c3a5
  13. 23 2月, 2015 1 次提交
    • P
      netfilter: nf_tables: fix addition/deletion of elements from commit/abort · 02263db0
      Pablo Neira Ayuso 提交于
      We have several problems in this path:
      
      1) There is a use-after-free when removing individual elements from
         the commit path.
      
      2) We have to uninit() the data part of the element from the abort
         path to avoid a chain refcount leak.
      
      3) We have to check for set->flags to see if there's a mapping, instead
         of the element flags.
      
      4) We have to check for !(flags & NFT_SET_ELEM_INTERVAL_END) to skip
         elements that are part of the interval that have no data part, so
         they don't need to be uninit().
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      02263db0
  14. 31 1月, 2015 1 次提交
  15. 26 1月, 2015 1 次提交
    • P
      netfilter: nf_tables: disable preemption when restoring chain counters · e8781f70
      Pablo Neira Ayuso 提交于
      With CONFIG_DEBUG_PREEMPT=y
      
      [22144.496057] BUG: using smp_processor_id() in preemptible [00000000] code: iptables-compat/10406
      [22144.496061] caller is debug_smp_processor_id+0x17/0x1b
      [22144.496065] CPU: 2 PID: 10406 Comm: iptables-compat Not tainted 3.19.0-rc4+ #
      [...]
      [22144.496092] Call Trace:
      [22144.496098]  [<ffffffff8145b9fa>] dump_stack+0x4f/0x7b
      [22144.496104]  [<ffffffff81244f52>] check_preemption_disabled+0xd6/0xe8
      [22144.496110]  [<ffffffff81244f90>] debug_smp_processor_id+0x17/0x1b
      [22144.496120]  [<ffffffffa07c557e>] nft_stats_alloc+0x94/0xc7 [nf_tables]
      [22144.496130]  [<ffffffffa07c73d2>] nf_tables_newchain+0x471/0x6d8 [nf_tables]
      [22144.496140]  [<ffffffffa07c5ef6>] ? nft_trans_alloc+0x18/0x34 [nf_tables]
      [22144.496154]  [<ffffffffa063c8da>] nfnetlink_rcv_batch+0x2b4/0x457 [nfnetlink]
      Reported-by: NAndreas Schultz <aschultz@tpip.net>
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      e8781f70