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=1796382817; b=h3myFHSncuspwQqSifhWJJZP0tCvYpZFwCd3wEkdyzTOoahkDBRwrdcqZm2232teKwVq U+hOIvF4IoxOC0ww0La2ZJMq3TBCdgRmOc8B6yoxQyLKJ++8DzHtWUFvbGYy1ccUO/pNt /rM1yXs60nQHPE+C9i4coS28ow8SEhxjlXv0v8H2mP4JVkswnW1r7T1zU/NSlxIVnz6Hr BTiFTXNYoxMI2yyn3kS0W3pZevOSFXJzYBCnXPh/aMLXku8iVJTZTeB4Pg0ScECf/mv1N v0514jQgmHIFaOGCfVDweUpFa2mR04LFBJK+r0bn6xR/4mOiKRkpGZHL1Mat8seNbWg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382817; 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=xPjpNrAGnQ6UJbMOuwxx/LAWadEkxY/YM0jDmq3M/MA=; b=UixT31mt33uETg7fxV4+KTLKQW8GzdizuajF58m7PbnrveIOxqRVj6ulSi8OuLfGgkVw x9J025BSUdZYXMOmtKQJQLCy2p6WpuyyFikMkVw678E0SqFApOB90fPUiZ4vYyK9nH7tu bIFjmfhWFeO87ngZBUpxeGNqwD3yOH86/33biHmkNi7Ox750QCMMk0W5BPRcEjMZ92O7c Y90d86sNUUAMmyO220RCt4e9QnQQVlg0YTsXJsjb8v35T5m2xBPhYGsAre4Y7Sl4PiYhr mBnzk4ij7lmynSkWXs7whUQvSOyJma//6FMN38tiQ48sA/1PqYjec0aPtTIlhT9FwnA== 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=I4aNe0fn; 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 A1BE0606A33F; Fri, 4 Dec 2026 11:13:37 +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=I4aNe0fn Received: by smtp.kernel.org (Postfix) with ESMTPSA id 96A601F0092C; Fri, 4 Dec 2026 11:13:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382817; bh=xPjpNrAGnQ6UJbMOuwxx/LAWadEkxY/YM0jDmq3M/MA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=I4aNe0fn10p/+FdQMWsvskEfDL7Qbtw+2DySpKIKlzSJ9m82U7zMX1o8PILQpqBLO aSto1nfNZxXY8qUuvpMGHtCMl+/2KaEtH4Bxvrb/xB0kdKt7kxh7YLPQMat04Witre BG/fAQKjPhO8JGcRn6K1lHDwVhIo1pcYQcE2D7A4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Chaosheng Qu , Steven Rostedt Subject: [PATCH 6.18 584/703] tracing/osnoise: Dont start a kthread in timerlat user-space mode Date: Fri, 4 Dec 2026 19:08:03 +0900 Message-ID: <20261204100643.291333032@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-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 @@ -1993,6 +1993,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 {