• Pablo Neira Ayuso's avatar
    netfilter: ctnetlink: force null nat binding on insert · 0eba801b
    Pablo Neira Ayuso authored
    Quoting Andrey Vagin:
      When a conntrack is created  by kernel, it is initialized (sets
      IPS_{DST,SRC}_NAT_DONE_BIT bits in nf_nat_setup_info) and only then it
      is added in hashes (__nf_conntrack_hash_insert), so one conntract
      can't be initialized from a few threads concurrently.
    
      ctnetlink can add an uninitialized conntrack (w/o
      IPS_{DST,SRC}_NAT_DONE_BIT) in hashes, then a few threads can look up
      this conntrack and start initialize it concurrently. It's dangerous,
      because BUG can be triggered from nf_nat_setup_info.
    
    Fix this race by always setting up nat, even if no CTA_NAT_ attribute
    was requested before inserting the ct into the hash table. In absence
    of CTA_NAT_ attribute, a null binding is created.
    
    This alters current behaviour: Before this patch, the first packet
    matching the newly injected conntrack would be run through the nat
    table since nf_nat_initialized() returns false.  IOW, this forces
    ctnetlink users to specify the desired nat transformation on ct
    creation time.
    
    Thanks for Florian Westphal, this patch is based on his original
    patch to address this problem, including this patch description.
    Reported-By: default avatarAndrey Vagin <avagin@gmail.com>
    Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
    Acked-by: default avatarFlorian Westphal <fw@strlen.de>
    0eba801b
nf_nat_core.c 23.3 KB