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 E90332628C; Mon, 23 Jun 2025 21:23:05 +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=1750713786; cv=none; b=jet0cSGYA5FRo81FiCzqF1Z/1FVYGWaIphgkTQkvBZOIpFVHcT8XPtnF29UszxYybJeCSbSAGKL5h52HWn+r3t5k9if1W7T2GsMgjyN6PVJNhkMjYxJ60jvwWyugG8CSBCaAW66seUR2rme9qhpkC4Ab+Qs8YyovgRK2L+kEXDI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750713786; c=relaxed/simple; bh=3+LyTIazs+IAXHqa62FDDfOvyJiohsGNjPGnc7vwTEY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=r96hsdCJ39xZea3IeK7JW1bOCw57S/CJRzORMiAr2iJbAvXskZR5s3iYrOisbstAjf2uOUxNTavUCQKyOldZ72EkaJX9q32YRkZ9d6xhj964LX468HdTqyKCIV+WapcSWiTmbRyDUEaojyZeephgkm/zDBp2GBfopgl3cYy3jfo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=doGSkFkG; 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="doGSkFkG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82B64C4CEEA; Mon, 23 Jun 2025 21:23:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1750713785; bh=3+LyTIazs+IAXHqa62FDDfOvyJiohsGNjPGnc7vwTEY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=doGSkFkGPmCJnkyxj+T/m76ws87gT5I0A5+kIhTkvM4lrriYTbBX21jeAUEEQQwLH CCLKP/NK9RJtAD5yRVRLpKVeqfW8QHa9QdnKVU/nDNqvykGiIy6e7AMiSpvLVVWkAl M0ooufFTDjSsvNZ/bw3C1ZAQ2KZJ4dRfhX64yHU8= 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.15 167/411] posix-cpu-timers: fix race between handle_posix_cpu_timers() and posix_cpu_timer_del() Date: Mon, 23 Jun 2025 15:05:11 +0200 Message-ID: <20250623130637.897534446@linuxfoundation.org> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250623130632.993849527@linuxfoundation.org> References: <20250623130632.993849527@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 5.15-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 @@ -1432,6 +1432,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; + + /* * If the actual expiry is deferred to task work context and the * work is already scheduled there is no point to do anything here. */