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 5555D2E7163; Tue, 17 Jun 2025 16:17:38 +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=1750177058; cv=none; b=jbr8N39SnT3avPzAi1BHgTP8P/toalPUka2HJiwvhK2tenN/ds5lHE62qjsCU2bFY2MJDkHL4lykqqMAR8bB7EQLwoEJd3I/zNYm445vadyfhWDFVvSXR97GT5YYBe668lNcwcBcxGzTPtUwmLJTuSDPENARVfwM6ry/VitVTOQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750177058; c=relaxed/simple; bh=cAzXAqlWV0Gn8ueh66IyB6o2oU8BhdFPikGrHUQJjM8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VKTlFokXF8L718wXqQ5nhSPdNrwLMmxMpc61ZmMsTEkM5NcxfgS0aLz3v5AIe3rZIPInjqbOFCQFQPTmCzIrdPu+wehjM1UGAywBWKKLK0NbSe5ypzRsGIReqh2bD5hzuEdJNX7gOwymWb2e799+rijdIHOZJouBLgP5vl+ka2g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=BpusspH2; 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="BpusspH2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7C95C4CEE3; Tue, 17 Jun 2025 16:17:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1750177058; bh=cAzXAqlWV0Gn8ueh66IyB6o2oU8BhdFPikGrHUQJjM8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BpusspH2S91Le30z3KJqK8KpRNfk0fIlEislb423wy7d17AhSUguvVbF74+NpnG2E zpj5bOAEzWXM8mRekyj9jgPRQ/Layfp9eGQzqBVGISXD4AoViOv5vEs4rEkK9aOy8r qoNZbxslivXfAYnJaOKzKKkFnIi5ujw+hB0mYubg= 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 6.6 343/356] posix-cpu-timers: fix race between handle_posix_cpu_timers() and posix_cpu_timer_del() Date: Tue, 17 Jun 2025 17:27:38 +0200 Message-ID: <20250617152351.942295762@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250617152338.212798615@linuxfoundation.org> References: <20250617152338.212798615@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 6.6-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 @@ -1438,6 +1438,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. */