• Florian Westphal's avatar
    netfilter: nfnetlink: place subsys mutexes in distinct lockdep classes · ab6c41ee
    Florian Westphal authored
    From time to time there are lockdep reports similar to this one:
    
     WARNING: possible circular locking dependency detected
     ------------------------------------------------------
     000000004f61aa56 (&table[i].mutex){+.+.}, at: nfnl_lock [nfnetlink]
     but task is already holding lock:
     [..] (&net->nft.commit_mutex){+.+.}, at: nf_tables_valid_genid [nf_tables]
     which lock already depends on the new lock.
     the existing dependency chain (in reverse order) is:
     -> #1 (&net->nft.commit_mutex){+.+.}:
     [..]
            nf_tables_valid_genid+0x18/0x60 [nf_tables]
            nfnetlink_rcv_batch+0x24c/0x620 [nfnetlink]
            nfnetlink_rcv+0x110/0x140 [nfnetlink]
            netlink_unicast+0x12c/0x1e0
     [..]
            sys_sendmsg+0x18/0x40
            linux_sparc_syscall+0x34/0x44
     -> #0 (&table[i].mutex){+.+.}:
     [..]
            nfnl_lock+0x24/0x40 [nfnetlink]
            ip_set_nfnl_get_byindex+0x19c/0x280 [ip_set]
            set_match_v1_checkentry+0x14/0xc0 [xt_set]
            xt_check_match+0x238/0x260 [x_tables]
            __nft_match_init+0x160/0x180 [nft_compat]
     [..]
            sys_sendmsg+0x18/0x40
            linux_sparc_syscall+0x34/0x44
     other info that might help us debug this:
      Possible unsafe locking scenario:
            CPU0                    CPU1
            ----                    ----
       lock(&net->nft.commit_mutex);
                                    lock(&table[i].mutex);
                                    lock(&net->nft.commit_mutex);
       lock(&table[i].mutex);
    
    Lockdep considers this an ABBA deadlock because the different nfnl subsys
    mutexes reside in the same lockdep class, but this is a false positive.
    
    CPU1 table[i] refers to the nftables subsys mutex, whereas CPU1 locks
    the ipset subsys mutex.
    
    Yi Che reported a similar lockdep splat, this time between ipset and
    ctnetlink subsys mutexes.
    
    Time to place them in distinct classes to avoid these warnings.
    Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
    Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
    ab6c41ee
nfnetlink.c 16.1 KB