• Nikolay Borisov's avatar
    netfilter: ipset: Fix sleeping memory allocation in atomic context · 00db674b
    Nikolay Borisov authored
    Commit 00590fdd introduced RCU locking in list type and in
    doing so introduced a memory allocation in list_set_add, which
    is done in an atomic context, due to the fact that ipset rcu
    list modifications are serialised with a spin lock. The reason
    why we can't use a mutex is that in addition to modifying the
    list with ipset commands, it's also being modified when a
    particular ipset rule timeout expires aka garbage collection.
    This gc is triggered from set_cleanup_entries, which in turn
    is invoked from a timer thus requiring the lock to be bh-safe.
    
    Concretely the following call chain can lead to "sleeping function
    called in atomic context" splat:
    call_ad -> list_set_uadt -> list_set_uadd -> kzalloc(, GFP_KERNEL).
    And since GFP_KERNEL allows initiating direct reclaim thus
    potentially sleeping in the allocation path.
    
    To fix the issue change the allocation type to GFP_ATOMIC, to
    correctly reflect that it is occuring in an atomic context.
    
    Fixes: 00590fdd ("netfilter: ipset: Introduce RCU locking in list type")
    Signed-off-by: default avatarNikolay Borisov <kernel@kyup.com>
    Acked-by: default avatarJozsef Kadlecsik <kadlec@blackhole.kfki.hu>
    Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
    00db674b
ip_set_list_set.c 16.3 KB