]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
task_work: Fix NMI race condition
authorPeter Zijlstra <peterz@infradead.org>
Mon, 22 Sep 2025 13:47:00 +0000 (15:47 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 18 Dec 2025 12:54:50 +0000 (13:54 +0100)
commitee96f47123495ed75e0b847d09db4630dfe27fe0
tree138e4c8cb530242da88eef17e19274b972aba28b
parent329f8323d3a55a6fa7cc83d995813d45011987ea
task_work: Fix NMI race condition

[ Upstream commit ef1ea98c8fffe227e5319215d84a53fa2a4bcebc ]

  __schedule()
  // disable irqs
      <NMI>
  task_work_add(current, work, TWA_NMI_CURRENT);
      </NMI>
  // current = next;
  // enable irqs
      <IRQ>
  task_work_set_notify_irq()
  test_and_set_tsk_thread_flag(current,
                                       TIF_NOTIFY_RESUME); // wrong task!
      </IRQ>
  // original task skips task work on its next return to user (or exit!)

Fixes: 466e4d801cd4 ("task_work: Add TWA_NMI_CURRENT as an additional notify mode.")
Reported-by: Josh Poimboeuf <jpoimboe@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Link: https://patch.msgid.link/20250924080118.425949403@infradead.org
Signed-off-by: Sasha Levin <sashal@kernel.org>
kernel/task_work.c