From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6374E2628C; Mon, 23 Jun 2025 21:23:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750713788; cv=none; b=ABHiibss7sN0UjeHr9sLNsxalfIzlnROwcYDJNJ+YkT2x9uSeZKuZtc9jP5LgZU8X1y6e4wte0zAQAptyCtvy00QkQdD6ZJzZOHKL8JMlgnp3fpEN2Z6BXQt4sK1LzSDv3PnFXsQ5R4ebIq5RTesMWuPxD8AHyYeSwc6VvMTVJk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750713788; c=relaxed/simple; bh=k52gCpLRBufST6ha7VgjAFovtCOD2kkszE9wMQX9GoE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=u70MEeEs1mQTuSL6KM2veVnsZed+tCowMq3potjU7IiIbR8MN0F/fmqMYWYHSuK+YX6bF6g73fvVD5KEu3ht8uYwHh+pSFlTMDXJjesqPiVYmSIYcDmBDek1dDTVrA9vkuSzUQsOlgWjKi2acBrc6vbFDTMhIcjIsQUXvPAOT5Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=pDNHFQvC; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="pDNHFQvC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E73C1C4CEEA; Mon, 23 Jun 2025 21:23:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1750713788; bh=k52gCpLRBufST6ha7VgjAFovtCOD2kkszE9wMQX9GoE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pDNHFQvCoDfrMy05LfpjGraU2lSYyCiWOWFp1YRGwkvFkkisALsWmMoBg93OzDsjI loyMNUXxARz68ePecIWBatdn83qe6WRcdew6serY2PxCqzwqdGH0SEQa0GqXKNTw79 m6FXBJ0gMMZRmOg4G0nPFu1e8ACA16ZDenuT65Uo= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, =?UTF-8?q?Beno=C3=AEt=20Sevens?= , Oleg Nesterov , Linus Torvalds Subject: [PATCH 5.4 213/222] posix-cpu-timers: fix race between handle_posix_cpu_timers() and posix_cpu_timer_del() Date: Mon, 23 Jun 2025 15:09:08 +0200 Message-ID: <20250623130618.704753063@linuxfoundation.org> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250623130611.896514667@linuxfoundation.org> References: <20250623130611.896514667@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 5.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Oleg Nesterov commit f90fff1e152dedf52b932240ebbd670d83330eca upstream. If an exiting non-autoreaping task has already passed exit_notify() and calls handle_posix_cpu_timers() from IRQ, it can be reaped by its parent or debugger right after unlock_task_sighand(). If a concurrent posix_cpu_timer_del() runs at that moment, it won't be able to detect timer->it.cpu.firing != 0: cpu_timer_task_rcu() and/or lock_task_sighand() will fail. Add the tsk->exit_state check into run_posix_cpu_timers() to fix this. This fix is not needed if CONFIG_POSIX_CPU_TIMERS_TASK_WORK=y, because exit_task_work() is called before exit_notify(). But the check still makes sense, task_work_add(&tsk->posix_cputimers_work.work) will fail anyway in this case. Cc: stable@vger.kernel.org Reported-by: BenoƮt Sevens Fixes: 0bdd2ed4138e ("sched: run_posix_cpu_timers: Don't check ->exit_state, use lock_task_sighand()") Signed-off-by: Oleg Nesterov Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- kernel/time/posix-cpu-timers.c | 9 +++++++++ 1 file changed, 9 insertions(+) --- a/kernel/time/posix-cpu-timers.c +++ b/kernel/time/posix-cpu-timers.c @@ -1120,6 +1120,15 @@ void run_posix_cpu_timers(void) lockdep_assert_irqs_disabled(); /* + * Ensure that release_task(tsk) can't happen while + * handle_posix_cpu_timers() is running. Otherwise, a concurrent + * posix_cpu_timer_del() may fail to lock_task_sighand(tsk) and + * miss timer->it.cpu.firing != 0. + */ + if (tsk->exit_state) + return; + + /* * The fast path checks that there are no expired thread or thread * group timers. If that's so, just return. */