{"id":"CVE-2026-142916","summary":"powerpc: fix NMI exit ordering: restore soft masks after irqentry_nmi_exit()","details":"In the Linux kernel, the following vulnerability has been resolved:\n\npowerpc: fix NMI exit ordering: restore soft masks after irqentry_nmi_exit()\n\nWhen running with CONFIG_PPC_IRQ_SOFT_MASK_DEBUG=y and LOCKDEP=y, an\nOops is triggered during NMI exit:\n\n  [  202.258332] Oops: Exception in kernel mode, sig: 4 [#1]\n  NIP [000000000003e178] 0x3e178\n  LR  [c00000000003e174] arch_local_irq_restore+0x2a4/0x328\n  TRAP: 0700  MSR: 0000000000081000 \u003cME\u003e\n\nThe faulting instruction at NIP is a 'trap' (0fe00000) inside the\nrfi_flush_fallback trampoline at a userspace-looking low address, reached\nafter a bad rfid caused by an incorrect SRR0 value.\n\nRoot cause:\nDEFINE_INTERRUPT_HANDLER_NMI used to call arch_interrupt_nmi_exit_prepare()\n*before* irqentry_nmi_exit(), giving this sequence:\n\n  arch_interrupt_nmi_enter_prepare()   // saves irq_soft_mask, irq_happened\n  irqentry_nmi_enter()                 // __nmi_enter() -\u003e nmi_count++, in_nmi()=true\n  ____func(regs)                       // NMI handler body\n  arch_interrupt_nmi_exit_prepare()    // RESTORES irq_soft_mask=0 (IRQS_ENABLED)\n                                       // RESTORES irq_happened with pending bits\n  irqentry_nmi_exit()                  // instrumentation block runs here...\n    trace_hardirqs_on_prepare()        //   ...with in_nmi()==true still\n    lockdep_hardirqs_on_prepare()      //   ...and irq_soft_mask already restored to 0\n      -\u003e arch_local_irq_restore(0)     // mask=0 -\u003e enable path entered\n           WARN_ON_ONCE(in_nmi())      // FIRES: __nmi_exit() hasn't run yet\n    __nmi_exit()                       // nmi_count-- (too late)\n\narch_interrupt_nmi_exit_prepare() restores irq_soft_mask to whatever\nthe interrupted thread had (IRQS_ENABLED / 0) and restores irq_happened\nwith any pending deferred-interrupt bits that were present when the NMI\nfired.  This is correct and necessary before rfid back to the interrupted\ncontext, but it must not happen until irqentry_nmi_exit() has fully\ncompleted.\n\nWith irq_soft_mask=0 and pending bits in irq_happened, the\ntrace_hardirqs_on_prepare() call inside irqentry_nmi_exit()'s\ninstrumentation block reaches lockdep_hardirqs_on_prepare() which\ncalls __trace_hardirqs_on_caller(), which eventually calls\narch_local_irq_restore(0) (the IRQS_ENABLED / enable path).\n\narch_local_irq_restore() with mask=0 hits the CONFIG_PPC_IRQ_SOFT_MASK_DEBUG\nguards at irq_64.c:217:\n\n  WARN_ON_ONCE(in_nmi());   // TRUE: __nmi_exit() not yet called\n\nThe WARN_ON_ONCE fires a 'trap' instruction (tw 31,0,0 / 0fe00000) in\nkernel mode with MSR_PR=0, MSR_IR=0 (real-mode).  The program check\nhandler (TRAP 0700) takes the sig:4 (SIGILL) path via do_program_check()\nand calls die(), producing the Oops.\n\nThe RESTART_TABLE mechanism in arch_local_irq_restore then causes the\nbad rfid that lands at the userspace-looking address visible in the NIP.\n\nThe bug is invisible with LOCKDEP=n because trace_hardirqs_on_prepare()\nis a no-op when CONFIG_TRACE_IRQFLAGS is not set (TRACE_IRQFLAGS is\nselected by PROVE_LOCKING which selects LOCKDEP).\n\nFix:\nMove arch_interrupt_nmi_exit_prepare() to after the irqentry_nmi_exit()\nblock, so that:\n\n  irqentry_nmi_exit()                 // __nmi_exit() -\u003e nmi_count--, in_nmi()=false\n  arch_interrupt_nmi_exit_prepare()   // now safe to restore soft mask state\n\nThe instrumentation inside irqentry_nmi_exit() now executes while\nin_nmi() is still true (nmi_count not yet decremented), but\nirq_soft_mask is still IRQS_ALL_DISABLED (NMI-entry value), so\narch_local_irq_restore() is never called with mask=0 from that path.\nAfter __nmi_exit() returns, arch_interrupt_nmi_exit_prepare() restores\nthe pre-NMI soft mask and irq_happened, which is the correct state for\nthe rfid back to the interrupted context.","modified":"2026-12-03T05:01:14.734702030Z","published":"2026-12-03T03:25:57.218Z","database_specific":{"osv_generated_from":"https://github.com/CVEProject/cvelistV5/tree/main/cves/2026/142xxx/CVE-2026-142916.json","cna_assigner":"Linux"},"references":[{"type":"PACKAGE","url":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git"},{"type":"WEB","url":"https://git.kernel.org/stable/c/8fa763bc3ee9bd215476ab91ee480c649eaa4b29"},{"type":"WEB","url":"https://git.kernel.org/stable/c/94bf70c51f3766222d83b86f911f04dd49897e61"},{"type":"ADVISORY","url":"https://github.com/CVEProject/cvelistV5/tree/main/cves/2026/142xxx/CVE-2026-142916.json"},{"type":"ADVISORY","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-142916"}],"affected":[{"ranges":[{"type":"GIT","repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","events":[{"introduced":"bee25f97ad24641df55cb3887eb5bfcb2b9d8fbc"},{"fixed":"94bf70c51f3766222d83b86f911f04dd49897e61"},{"fixed":"8fa763bc3ee9bd215476ab91ee480c649eaa4b29"}]}],"database_specific":{"source":"https://storage.googleapis.com/cve-osv-conversion/osv-output/CVE-2026-142916.json"}},{"package":{"name":"Kernel","ecosystem":"Linux"},"ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"7.2.0"},{"fixed":"7.3.6"}]}],"database_specific":{"source":"https://storage.googleapis.com/cve-osv-conversion/osv-output/CVE-2026-142916.json"}}],"schema_version":"1.9.2"}