From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796381354; b=3kSxM9xfIGw26FsH5u088XISU9dHou8gCqMC5oElRQcaRGgia/U9N4wmNDtwf4R3fbFa ylCtALyvpe1rV/cIzlqHQozDNdmYML2kvWoduI1TCc0hYeC2lqooHBKDVZsmP00R3zu3G 6kLaPOLERALZkMQTSL1nck01XBAyv03soFU52TE2aQ+Zn9W4G/VFgUDJNMkEl0arVW0fu Inh6GkBqHJdwmZcPsfWZxjeh5lcH/HsQaLs2HpNxMaKTodiTem/rYm0mgARhz4greIywp gG6ya8aUOjUVlds9WX5gex8Hf5L2kdL24Fez4grGvkCeB2+f85U8pNyW3dd0Vbslpkw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381354; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=EV+FU1sYNjsqvV85ppwb8JDg9k4tQvManA0KfJAloEM=; b=wB2BQMEYEyjQPYp+IRgWiK77EsBMF+/ZqwHmfE7exGARIThCgyZPX0m38XsBnZOkZiDi p3kfPOwEiLK9DMHl8vepFihwbiodml/joHmqBmYcmvok5chdx7qnmAevfb/TXKPTILgxJ GJDS4UQBT+H7hPb3YeOoRzxpdMEsjm3jVqkbhK4Ahi4nXasuaV1nlk/hFXEt2OP+gyZKK dUN9PdvJ2EXfDBnMvd/x5uvK+ibmkUcc103vJPjBdDIZIyJT1HOFcqBTuCTUfpoP/melc BQ/7y3CevoOTEvBoRqL/i0SRPJe+VMuYfuwoqUJQwhYa5YyYnZq/8fZzlDIlbk33DwQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=2g8cb8MJ; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06912606A322; Fri, 4 Dec 2026 10:49:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=2g8cb8MJ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7447A1F000C2; Fri, 4 Dec 2026 10:49:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381353; bh=EV+FU1sYNjsqvV85ppwb8JDg9k4tQvManA0KfJAloEM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=2g8cb8MJKEMPU9eVk7hIrdyjmQv7ehAE2fU6Mg4Zq5GV5aGwhcXrYbizzJ6xFQCEt dw4ixU2/Tq7HMJEyfFjkxG8TIgypFs9/dSi+EvxqlYVjzcVwdKapOkL5ZmH4IcnwhP bJgiDmFC7ocqXNkpbNhkC0VyWJIgaIirvNRgrhis= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Chaosheng Qu , Steven Rostedt Subject: [PATCH 7.3 668/742] tracing/osnoise: Dont start a kthread in timerlat user-space mode Date: Fri, 4 Dec 2026 19:08:52 +0900 Message-ID: <20261204100652.813389827@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chaosheng Qu commit 5f855410554564ca05903979e6dab96e754d8773 upstream. In timerlat user-space mode (NO_OSNOISE_WORKLOAD) the workload is a user task reading timerlat_fd, so there is no per-CPU kernel thread to run. start_kthread() only checks for that in the osnoise branch: if (timerlat_enabled()) { snprintf(comm, 24, "timerlat/%d", cpu); main = timerlat_main; } else { /* if no workload, just return */ if (!test_bit(OSN_WORKLOAD, &osnoise_options)) { ... return 0; } ... } start_per_cpu_kthreads() guards against this mode itself, but osnoise_hotplug_workfn() calls start_kthread() directly. Bringing a CPU online in user-space mode therefore starts a timerlat/N thread and sets its bit in kthread_cpumask while OSN_WORKLOAD is clear. stop_kthread() uses that bit to decide what the recorded task is: if (cpumask_test_and_clear_cpu(cpu, &kthread_cpumask) && !WARN_ON(!test_bit(OSN_WORKLOAD, &osnoise_options))) { kthread_stop(kthread); } else if (!WARN_ON(test_bit(OSN_WORKLOAD, &osnoise_options))) { kill_pid(kthread->thread_pid, SIGKILL, 1); put_task_struct(kthread); } The bit is set but OSN_WORKLOAD is not, so the first WARN_ON() fires and the && short-circuits into the user-task branch. A running kernel thread is SIGKILLed and its task_struct is put without ever being stopped, so it keeps executing until it is freed underneath itself. Any write to osnoise/options reaches this: osnoise_options_write() stops the per-CPU threads before applying the new value, so stop_kthread() still sees OSN_WORKLOAD clear. Re-writing the value that is already set triggers it just as well as changing it. echo NO_OSNOISE_WORKLOAD > osnoise/options echo timerlat > current_tracer echo 0 > /sys/devices/system/cpu/cpu1/online echo 1 > /sys/devices/system/cpu/cpu1/online echo NO_OSNOISE_WORKLOAD > osnoise/options The offline/online pair is required, otherwise no kthread is recorded and no bit is set. Running this on 7.3-rc7 with KASAN gives a WARNING in stop_kthread() followed by a slab-use-after-free in update_se(); leaving out the hotplug step produces neither. Keep the check in start_kthread(), where the related hotplug bug was fixed in 0bb0a5c12ecf, instead of adding another copy to the callback. Cc: stable@vger.kernel.org Fixes: e88ed227f639 ("tracing/timerlat: Add user-space interface") Link: https://patch.msgid.link/20261014081034.12702-1-chaosheng.qu.linux@gmail.com Signed-off-by: Chaosheng Qu Signed-off-by: Steven Rostedt Signed-off-by: Greg Kroah-Hartman --- kernel/trace/trace_osnoise.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/kernel/trace/trace_osnoise.c +++ b/kernel/trace/trace_osnoise.c @@ -2038,6 +2038,14 @@ static int start_kthread(unsigned int cp return 0; if (timerlat_enabled()) { + /* + * In timerlat user-space mode the workload is the user task + * reading timerlat_fd, so there is no kernel thread to start. + * One started here would set its kthread_cpumask bit, which + * stop_kthread() reads as "osnoise workload kthread". + */ + if (!test_bit(OSN_WORKLOAD, &osnoise_options)) + return 0; snprintf(comm, 24, "timerlat/%d", cpu); main = timerlat_main; } else {