public inbox for netfilter-devel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v5 nf-next 0/3] netfilter: nf_tables: fix reset request deadlock
@ 2026-02-04 20:26 Brian Witte
  2026-02-04 20:26 ` [PATCH v5 nf-next 1/3] Revert nf_tables commit_mutex in reset path Brian Witte
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Brian Witte @ 2026-02-04 20:26 UTC (permalink / raw)
  To: netfilter-devel
  Cc: pablo, fw, kadlec, syzbot+ff16b505ec9152e5f448, Brian Witte

syzbot reported a possible circular locking dependency between
commit_mutex, nfnl_subsys_ipset and nlk_cb_mutex-NETFILTER:

  WARNING: possible circular locking dependency detected
  syz.3.970/9330 is trying to acquire lock:
  ffff888012d4ccd8 (&nft_net->commit_mutex){+.+.}-{4:4}, at: nf_tables_dumpreset_obj+0x6f/0xa0

  but task is already holding lock:
  ffff88802bce36f0 (nlk_cb_mutex-NETFILTER){+.+.}-{4:4}, at: __netlink_dump_start+0x150/0x990

  Chain exists of:
    &nft_net->commit_mutex --> nfnl_subsys_ipset --> nlk_cb_mutex-NETFILTER

   Possible unsafe locking scenario:

         CPU0                    CPU1
         ----                    ----
    lock(nlk_cb_mutex-NETFILTER);
                                 lock(nfnl_subsys_ipset);
                                 lock(nlk_cb_mutex-NETFILTER);
    lock(&nft_net->commit_mutex);

Link: https://syzkaller.appspot.com/bug?extid=ff16b505ec9152e5f448

The bug was introduced by commits that added commit_mutex locking to
serialize reset requests.

v5:
  - Split counter and quota changes into separate patches
  - counter: use global static spinlock wrapping fetch+reset
    atomically to prevent parallel reset underrun, instead of
    per-net spinlock taken too late (after fetch)
  - Drop struct net from counter priv (no longer needed with
    global spinlock)
  - quota: unchanged from v4, atomic64_xchg() for reset

v4:
  - Push spinlock down into nft_counter_reset() instead of holding it
    across entire dump iteration, per Florian's review
  - Store struct net in counter priv to access the per-net spinlock
    during reset, avoiding skb->sk dereference which is NULL in
    single-element GET paths such as nft_get_set_elem
  - Use atomic64_xchg() for quota reset instead of spinlock, which is
    simpler per Pablo's suggestion
  Link: https://lore.kernel.org/netfilter-devel/20260203050723.263515-1-brianwitte@mailfence.com/

v3:
  - Restructured as 2-patch series per Florian's suggestion:
    1. Revert the 3 commits that added commit_mutex locking
    2. Add spinlock-based serialization for reset requests
  Link: https://lore.kernel.org/netfilter-devel/20260201195255.532559-1-brianwitte@mailfence.com/

v2:
  - Switched to a spinlock in nft_pernet instead of mutex
  - Spinlock doesn't sleep, so we stay in RCU read-side critical section
  - Removes the try_module_get/module_put and rcu_read_unlock/lock dance
  Link: https://lore.kernel.org/netfilter-devel/20260201062517.263087-1-brianwitte@mailfence.com/

v1:
  - Proposed using a dedicated reset_mutex instead of commit_mutex
  Link: https://lore.kernel.org/netfilter-devel/20260127030604.39982-1-brianwitte@mailfence.com/

Brian Witte (3):
  Revert nf_tables commit_mutex in reset path
  netfilter: nft_counter: serialize reset with spinlock
  netfilter: nft_quota: use atomic64_xchg for reset

 net/netfilter/nf_tables_api.c | 248 ++++++----------------------------
 net/netfilter/nft_counter.c   |  20 ++-
 net/netfilter/nft_quota.c     |  12 +-
 3 files changed, 65 insertions(+), 215 deletions(-)

-- 
2.47.3


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-02-05 13:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-04 20:26 [PATCH v5 nf-next 0/3] netfilter: nf_tables: fix reset request deadlock Brian Witte
2026-02-04 20:26 ` [PATCH v5 nf-next 1/3] Revert nf_tables commit_mutex in reset path Brian Witte
2026-02-05 13:46   ` Florian Westphal
2026-02-04 20:26 ` [PATCH v5 nf-next 2/3] netfilter: nft_counter: serialize reset with spinlock Brian Witte
2026-02-04 20:26 ` [PATCH v5 nf-next 3/3] netfilter: nft_quota: use atomic64_xchg for reset Brian Witte

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox