CVE-2026-99922: mm/madvise: add cond_resched() in THP branch of madvise_cold_or_pageout_pte_range()
In the Linux kernel, the following vulnerability has been resolved:
mm/madvise: add condresched() in THP branch of madvisecoldorpageoutpterange()
During stress testing with stress-ng on a 256-CPU system, a softlockup was observed when madvise(MADVCOLD) was called on a 31GB memory region backed by transparent hugepages. The region contains 15935 THP PMD entries, and the softlockup was triggered after 14485 of them had been processed.
The THP branch of madvisecoldorpageoutpterange() has no scheduling point. walkpmdrange() invokes it once per 2MB PMD entry with no condresched() anywhere in the loop. Each iteration calls pmdpinvalidate() which issues a synchronous TLB shootdown (dsb ish) waiting for all CPUs to acknowledge. This operation can be time-consuming under heavy system load, causing the accumulated time across all PMD entries to exceed the softlockup threshold (20s) and panic when softlockuppanic=1. On a CONFIGPREEMPTNONE=y kernel, there is no other opportunity to reschedule during this entire traversal.
The regular PTE path already has an unconditional condresched() at the function tail (introduced by commit 9c276cc65a58 ("mm: introduce MADVCOLD") and commit 1a4e58cce84e ("mm: introduce MADVPAGEOUT") when MADVCOLD and MADVPAGEOUT were first introduced) and a conditional one inside the loop (commit b2f557a21bc8 ("mm/madvise: add condresched() in madvisecoldorpageoutpterange()")). The THP branch never received equivalent treatment.
Fix by adding condresched() at the hugeunlock exit path after spinunlock(ptl) and reclaimpages(), which is the single exit point for all goto paths in the THP branch.
Crash log: watchdog: BUG: soft lockup - CPU#63 stuck for 23s! [stress-ng-vm:1665914] ... Call trace: pmdpinvalidate+0x48/0x68 madvisecoldorpageoutpterange+0x84c/0xb00 walkpmdrange.isra.0+0x1ac/0x3b0 walkpudrange+0x120/0x190 walkpgdrange+0x170/0x1b8 walkpagerange+0x184/0x198 walkpagerangevma+0x94/0x128 madvisecold+0xd8/0x198 madvisevmabehavior+0x234/0x638 madvisewalkvmas.constprop.0+0xdc/0x210 madvisedobehavior+0xa8/0x328 domadvise+0xd8/0x140 arm64sysmadvise+0x2c/0xe0
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Compensating control
Add cond_resched() to the THP branch of madvise_cold_or_pageout_pte_range(), including all goto paths at the exit after spin_unlock(ptl) and reclaim_pages().