]> exis.tech > repos - linux.git/commit
xfrm: policy: fix use-after-free on inexact bin in xfrm_policy_bysel_ctx()
authorSanghyun Park <sanghyun.park.cnu@gmail.com>
Tue, 2 Jun 2026 09:49:05 +0000 (18:49 +0900)
committerSteffen Klassert <steffen.klassert@secunet.com>
Thu, 4 Jun 2026 09:55:22 +0000 (11:55 +0200)
commit7f2d76c9c03257c0782afef9d95321fa04096f60
tree555b0a0dfaf8314c600dd70229d440b394cdd122
parenteb48730bb827d1550401a5d391903f9d90b493c8
xfrm: policy: fix use-after-free on inexact bin in xfrm_policy_bysel_ctx()

Fix the race by pruning the bin while still holding xfrm_policy_lock,
before dropping it. Use __xfrm_policy_inexact_prune_bin() directly since
the lock is already held. The wrapper xfrm_policy_inexact_prune_bin()
becomes unused and is removed.

Race:

  CPU0 (XFRM_MSG_DELPOLICY)           CPU1 (XFRM_MSG_NEWSPDINFO)
  ==========================          ==========================
  xfrm_policy_bysel_ctx():
    spin_lock_bh(xfrm_policy_lock)
    bin = xfrm_policy_inexact_lookup()
    __xfrm_policy_unlink(pol)
    spin_unlock_bh(xfrm_policy_lock)
    xfrm_policy_kill(ret)
    // wide window, lock not held
                                       xfrm_hash_rebuild():
                                         spin_lock_bh(xfrm_policy_lock)
                                         __xfrm_policy_inexact_flush():
                                           kfree_rcu(bin)  // bin freed
                                         spin_unlock_bh(xfrm_policy_lock)
    xfrm_policy_inexact_prune_bin(bin)
    // UAF: bin is freed

Fixes: 6be3b0db6db8 ("xfrm: policy: add inexact policy search tree infrastructure")
Signed-off-by: Sanghyun Park <sanghyun.park.cnu@gmail.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
net/xfrm/xfrm_policy.c