From nobody Sun Feb 8 04:34:30 2026 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 178FE2472A1; Sun, 4 May 2025 18:28:40 +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=1746383321; cv=none; b=r82Q6FNz8CeMFp+wZzz0jEMP1lopxp+0CFbXn5h211HyAbWDmzLJBRl4YJ3gaoDISTJZPaw0K8CGPopoI4R5CENZ/D6pjC6DjslTDOek0Yfz8yptehl6by/1QxrTH8qEvtQi0D4ORvsNEoOljo49c2cKIm8sWCW7yb0GsiQmcxU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746383321; c=relaxed/simple; bh=6v+xVhxOY0UkacAOKqSthuE1TtEV5XtaFiVQyBzCxUs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ex9olxJz4132GzpNodFh/m4qdCTLAMCLxYLEqXmxcZhNGRmg2wq2QQTBfWdqeQE1Cr/Ybt7ibAHAg5V3A1ZlreQLL1kz+cjQ21k6d47iqZbT3eyFhFrV3M/lI2vHDfazOqTWXRQTlHmmzE6NkU+zp2PDAXyWPrraG4xmh8GZ534= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ePGlyFt2; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ePGlyFt2" Received: by smtp.kernel.org (Postfix) with ESMTPS id 89EC6C4CEED; Sun, 4 May 2025 18:28:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1746383320; bh=6v+xVhxOY0UkacAOKqSthuE1TtEV5XtaFiVQyBzCxUs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=ePGlyFt2ir+j1Bisl0m/h88ufkTssFyaRRmekkhhv9J4LwY6xgQjsly0bb2h+H4pD JHXsqul3pYZEoLdwycAxCXEl+q0XCdpuEZYJiemx+ca6NtoZKLz7kjztvdr9oOFSB+ NX1vLW0bTRzuykTPfprk4rjumD/I9LjZwxSB5F+sq/NywRWauKGVksuK7rPRTyXzYB XCveWm4yMslL6pic6dIgkrJc5kiTCN+J0l/ITY/AtY4YmR5C6W/4a+AQVnmfeJS5AI 9NQ00Nbb0IT3lHdiycA0sP+U+xeGHpcVAiJ5gGozlRrknI8OPn4rShV5xtRL9nEh2v cg1mnShEANXig== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7771DC3ABB7; Sun, 4 May 2025 18:28:40 +0000 (UTC) From: Paul Cacheux via B4 Relay Date: Sun, 04 May 2025 20:27:52 +0200 Subject: [PATCH v3 1/2] tracing: add missing trace_probe_log_clear for eprobes Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250504-fix-trace-probe-log-race-v3-1-9e99fec7eddc@gmail.com> References: <20250504-fix-trace-probe-log-race-v3-0-9e99fec7eddc@gmail.com> In-Reply-To: <20250504-fix-trace-probe-log-race-v3-0-9e99fec7eddc@gmail.com> To: Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Namhyung Kim Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Paul Cacheux X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1746383319; l=788; i=paulcacheux@gmail.com; s=20250422; h=from:subject:message-id; bh=Nem7XKEmMcHI5glWY7jEUqZtjAQzjhIH+nS5TNvLewM=; b=uErPiOew5kdUhskb+0wBgOnfEYN78yNGP/MAUmbu0StBUMwKBsonBomXxZHuwKWM5lfKnafRO cAMKUWkwDX+ApWIVlSff2FCh54bhhWFcLZc8sZgwXyZO/w2uej+CsZQ X-Developer-Key: i=paulcacheux@gmail.com; a=ed25519; pk=8UguSecyECHKHp0YLS7hTEDob0ctFMr3ygBTeAmrFHs= X-Endpoint-Received: by B4 Relay for paulcacheux@gmail.com/20250422 with auth_id=386 X-Original-From: Paul Cacheux Reply-To: paulcacheux@gmail.com From: Paul Cacheux Make sure trace_probe_log_clear is called in the tracing eprobe code path, matching the trace_probe_log_init call. Signed-off-by: Paul Cacheux Acked-by: Steven Rostedt (Google) --- kernel/trace/trace_eprobe.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/trace/trace_eprobe.c b/kernel/trace/trace_eprobe.c index c08355c3ef32b4124ac944d7e3a03efb66492269..916555f0de811f03feed9d923c6= 3078b0e4c993b 100644 --- a/kernel/trace/trace_eprobe.c +++ b/kernel/trace/trace_eprobe.c @@ -969,10 +969,13 @@ static int __trace_eprobe_create(int argc, const char= *argv[]) goto error; } } + trace_probe_log_clear(); return ret; + parse_error: ret =3D -EINVAL; error: + trace_probe_log_clear(); trace_event_probe_cleanup(ep); return ret; } --=20 2.49.0 From nobody Sun Feb 8 04:34:30 2026 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 179612472B5; Sun, 4 May 2025 18:28:40 +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=1746383321; cv=none; b=rpXzaBaCFHZasK+zgpKD9qK4sVlsEvp7Tx2Ap2khfjn7rl0Ryz3H0ZuXeWqW2r7ycTHnfGHUIgoE7/9IlSsL0AIcLaAV5Vfb1JnRTLe7AMztHQES/jLf7zC9bBdU3k3UTHPx6UGzgk/7ZN3NdEGlOTe3T1TpZdGuQVldHUsbYrU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746383321; c=relaxed/simple; bh=biw/YOugtlpuJtFsezEFUKDGzFXeTNhhYYG6c17nWCc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Bbh8jS+y72JJjM5J5/w4z8wWCe8GvCSvRXc6EF4qP58Aw1oDKfcKS7lI1j5+7+gxBljrn63XRTRaN6nQe9m39YzSCESjDQct9lISj0b+zvVAN6ykD8L+SFD/6no8FbM27Zox3BPIvsdyKN14G2cl08qQ14iC2rR/TPHzQKST834= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FoYtdbTT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FoYtdbTT" Received: by smtp.kernel.org (Postfix) with ESMTPS id 94A4AC4CEF0; Sun, 4 May 2025 18:28:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1746383320; bh=biw/YOugtlpuJtFsezEFUKDGzFXeTNhhYYG6c17nWCc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=FoYtdbTTAynKusPgOKC6NGKkyv6RbiP4dUPH+IvYDHoxzgeLEZvdLZ2qJSdCAJ2Rn vHFvRmjEeSozWg14UtCoM/bgRFQgkzDDXKc/qsD36EBBwbp4gPi9cwQBzph5w6U2tB 3QqOjzg2ABXVKc7BruZ3CrXj+eXb0TMedSBn62ZocOC80ZXt2rCXLhYiDE9GLZa0L2 1LHDD6A7mzUlfTw3ooQdQsGEGdVGBFcJybY32AvT3GEEdlhQDevby4R/Ymg8rEND8m RNTtea/xM1eJZYPd0837YQp3IxrKVbCVv25Zz4n5DVIOqnHnoWtx7TgBKAjFhpQHxY cSLUqqk/WNwsQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 850A9C3ABAC; Sun, 4 May 2025 18:28:40 +0000 (UTC) From: Paul Cacheux via B4 Relay Date: Sun, 04 May 2025 20:27:53 +0200 Subject: [PATCH v3 2/2] tracing: protect trace_probe_log with mutex Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250504-fix-trace-probe-log-race-v3-2-9e99fec7eddc@gmail.com> References: <20250504-fix-trace-probe-log-race-v3-0-9e99fec7eddc@gmail.com> In-Reply-To: <20250504-fix-trace-probe-log-race-v3-0-9e99fec7eddc@gmail.com> To: Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Namhyung Kim Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Paul Cacheux X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1746383319; l=2188; i=paulcacheux@gmail.com; s=20250422; h=from:subject:message-id; bh=JLwkOJEumGD7YD+nexmmI4MTQQL+hh9/f9FKhif6SKY=; b=fVewTZB5G2vWsu+/Kz4Ut/he1vI/StVN88Rdda3rjXLMq6aLMqZRKzi5Julu87MoiHFUqbwGK KXnbai+dRHTD56OINMEWdcXKsCdj4mMvmKKgRuU/nETJv2mSlto3Dho X-Developer-Key: i=paulcacheux@gmail.com; a=ed25519; pk=8UguSecyECHKHp0YLS7hTEDob0ctFMr3ygBTeAmrFHs= X-Endpoint-Received: by B4 Relay for paulcacheux@gmail.com/20250422 with auth_id=386 X-Original-From: Paul Cacheux Reply-To: paulcacheux@gmail.com From: Paul Cacheux The shared trace_probe_log variable can be accessed and modified by multiple processes using tracefs at the same time, this new mutex will guarantee it's always in a coherent state. There is no guarantee that multiple errors happening at the same time will each have the correct error message, but at least this won't crash. Fixes: ab105a4fb894 ("tracing: Use tracing error_log with probe events") Signed-off-by: Paul Cacheux Acked-by: Steven Rostedt (Google) --- kernel/trace/trace_probe.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c index 2eeecb6c95eea55502b83af6775b7b6f0cc5ab94..d538964c87a52b06646ec1b8c34= 69be7399f04fa 100644 --- a/kernel/trace/trace_probe.c +++ b/kernel/trace/trace_probe.c @@ -153,10 +153,19 @@ static const struct fetch_type *find_fetch_type(const= char *type, unsigned long return NULL; } =20 +/* + * The trace_probe_log_lock only protects against the individual + * modification of the trace_probe_log. It does not protect against + * the log from producing garbage if two probes use it at the same + * time. That would only happen if two admins were trying to add + * probes simultaneously which they shouldn't be doing. + */ +static DEFINE_MUTEX(trace_probe_log_lock); static struct trace_probe_log trace_probe_log; =20 void trace_probe_log_init(const char *subsystem, int argc, const char **ar= gv) { + guard(mutex)(&trace_probe_log_lock); trace_probe_log.subsystem =3D subsystem; trace_probe_log.argc =3D argc; trace_probe_log.argv =3D argv; @@ -165,11 +174,13 @@ void trace_probe_log_init(const char *subsystem, int = argc, const char **argv) =20 void trace_probe_log_clear(void) { + guard(mutex)(&trace_probe_log_lock); memset(&trace_probe_log, 0, sizeof(trace_probe_log)); } =20 void trace_probe_log_set_index(int index) { + guard(mutex)(&trace_probe_log_lock); trace_probe_log.index =3D index; } =20 @@ -178,6 +189,8 @@ void __trace_probe_log_err(int offset, int err_type) char *command, *p; int i, len =3D 0, pos =3D 0; =20 + guard(mutex)(&trace_probe_log_lock); + if (!trace_probe_log.argv) return; =20 --=20 2.49.0