From nobody Mon Feb 9 12:23:22 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 8F50F3A0E98 for ; Thu, 15 Jan 2026 17:26:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768497972; cv=none; b=DaVRrATkmlHHNNBvZZLRXhd9Ko18N0/xUn1SlPVN+Mg7GNKyx9LHymGnMsjdAUO1OirpDnDViHqXMXXnKyo6RW5goXdXl09YGn1r1GE7uP4I6wf430JuIBg7lh9zH07suJAKIuz9jl7/t6cpU15KUJ81+K0vs6XOd7Mn+wuFqy8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768497972; c=relaxed/simple; bh=GZcEHYQTtmZ0VfDcQ20iq3OLyxEpGboaa5o647sLiJE=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rc+i/jL4nvWQreuoctxx80n5D1nDg5ZMiaD4666xeo4NaUZAmuIyl8lONTGoU67+KKpv0BHWXfhYuEpF9yIWqmVvOzGLpfwfw5d0+YvG9aLjtK3Fy6PEfDXqO4KuAej67hGzRJ+vJJ+bXUjHZrCIwhwuQCYmeAr9D/IPPTUWYvs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Hayi5hzB; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Hayi5hzB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768497969; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=60sKp2ZfEgwvQCWM+SD55B2y7ixOltC+YNnJohYOh4k=; b=Hayi5hzB2Jx3OAax9J8AQ+DnaTff+pCKI1Rht5y8sSldghrO0zNZx5nQl3ySySfdcsBfha 6AijN3D6gN5spdCxkr4w0SdPp+5aZlU6OC453hFdQ2DpuhK7vPetUmUshqkAfOIEKDd/K1 hD33WATmCtxx0Y6+NBn5rt49pYx3pFw= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-674-5_Q0xnrFM8CY7zLUftDHaQ-1; Thu, 15 Jan 2026 12:26:04 -0500 X-MC-Unique: 5_Q0xnrFM8CY7zLUftDHaQ-1 X-Mimecast-MFC-AGG-ID: 5_Q0xnrFM8CY7zLUftDHaQ_1768497963 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4EABE195606E; Thu, 15 Jan 2026 17:26:03 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.64.87]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8278A1800285; Thu, 15 Jan 2026 17:25:58 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Ivan Pravdin , Crystal Wood , Costa Shulyupin , John Kacur , Tiezhu Yang , Daniel Wagner , Daniel Bristot de Oliveira , linux-trace-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), linux-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), bpf@vger.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_)) Subject: [PATCH v3 05/18] rtla: Replace magic number with MAX_PATH Date: Thu, 15 Jan 2026 13:31:48 -0300 Message-ID: <20260115163650.118910-6-wander@redhat.com> In-Reply-To: <20260115163650.118910-1-wander@redhat.com> References: <20260115163650.118910-1-wander@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" The trace functions use a buffer to manipulate strings that will be written to tracefs files. These buffers are defined with a magic number of 1024, which is a common source of vulnerabilities. Replace the magic number 1024 with the MAX_PATH macro to make the code safer and more readable. While at it, replace other instances of the magic number with ARRAY_SIZE() when the buffer is locally defined. Signed-off-by: Wander Lairson Costa --- tools/tracing/rtla/src/osnoise.c | 4 ++-- tools/tracing/rtla/src/timerlat_u.c | 4 ++-- tools/tracing/rtla/src/trace.c | 20 ++++++++++---------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tools/tracing/rtla/src/osnoise.c b/tools/tracing/rtla/src/osno= ise.c index ec074cd53dd84..4890a9a9d6466 100644 --- a/tools/tracing/rtla/src/osnoise.c +++ b/tools/tracing/rtla/src/osnoise.c @@ -52,7 +52,7 @@ char *osnoise_get_cpus(struct osnoise_context *context) int osnoise_set_cpus(struct osnoise_context *context, char *cpus) { char *orig_cpus =3D osnoise_get_cpus(context); - char buffer[1024]; + char buffer[MAX_PATH]; int retval; =20 if (!orig_cpus) @@ -62,7 +62,7 @@ int osnoise_set_cpus(struct osnoise_context *context, cha= r *cpus) if (!context->curr_cpus) return -1; =20 - snprintf(buffer, 1024, "%s\n", cpus); + snprintf(buffer, ARRAY_SIZE(buffer), "%s\n", cpus); =20 debug_msg("setting cpus to %s from %s", cpus, context->orig_cpus); =20 diff --git a/tools/tracing/rtla/src/timerlat_u.c b/tools/tracing/rtla/src/t= imerlat_u.c index ce68e39d25fde..efe2f72686486 100644 --- a/tools/tracing/rtla/src/timerlat_u.c +++ b/tools/tracing/rtla/src/timerlat_u.c @@ -32,7 +32,7 @@ static int timerlat_u_main(int cpu, struct timerlat_u_params *params) { struct sched_param sp =3D { .sched_priority =3D 95 }; - char buffer[1024]; + char buffer[MAX_PATH]; int timerlat_fd; cpu_set_t set; int retval; @@ -83,7 +83,7 @@ static int timerlat_u_main(int cpu, struct timerlat_u_par= ams *params) =20 /* add should continue with a signal handler */ while (true) { - retval =3D read(timerlat_fd, buffer, 1024); + retval =3D read(timerlat_fd, buffer, ARRAY_SIZE(buffer)); if (retval < 0) break; } diff --git a/tools/tracing/rtla/src/trace.c b/tools/tracing/rtla/src/trace.c index 211ca54b15b0e..e1af54f9531b8 100644 --- a/tools/tracing/rtla/src/trace.c +++ b/tools/tracing/rtla/src/trace.c @@ -313,7 +313,7 @@ void trace_event_add_trigger(struct trace_events *event= , char *trigger) static void trace_event_disable_filter(struct trace_instance *instance, struct trace_events *tevent) { - char filter[1024]; + char filter[MAX_PATH]; int retval; =20 if (!tevent->filter) @@ -325,7 +325,7 @@ static void trace_event_disable_filter(struct trace_ins= tance *instance, debug_msg("Disabling %s:%s filter %s\n", tevent->system, tevent->event ? : "*", tevent->filter); =20 - snprintf(filter, 1024, "!%s\n", tevent->filter); + snprintf(filter, ARRAY_SIZE(filter), "!%s\n", tevent->filter); =20 retval =3D tracefs_event_file_write(instance->inst, tevent->system, tevent->event, "filter", filter); @@ -344,7 +344,7 @@ static void trace_event_save_hist(struct trace_instance= *instance, { int retval, index, out_fd; mode_t mode =3D 0644; - char path[1024]; + char path[MAX_PATH]; char *hist; =20 if (!tevent) @@ -359,7 +359,7 @@ static void trace_event_save_hist(struct trace_instance= *instance, if (retval) return; =20 - snprintf(path, 1024, "%s_%s_hist.txt", tevent->system, tevent->event); + snprintf(path, ARRAY_SIZE(path), "%s_%s_hist.txt", tevent->system, tevent= ->event); =20 printf(" Saving event %s:%s hist to %s\n", tevent->system, tevent->event= , path); =20 @@ -391,7 +391,7 @@ static void trace_event_save_hist(struct trace_instance= *instance, static void trace_event_disable_trigger(struct trace_instance *instance, struct trace_events *tevent) { - char trigger[1024]; + char trigger[MAX_PATH]; int retval; =20 if (!tevent->trigger) @@ -405,7 +405,7 @@ static void trace_event_disable_trigger(struct trace_in= stance *instance, =20 trace_event_save_hist(instance, tevent); =20 - snprintf(trigger, 1024, "!%s\n", tevent->trigger); + snprintf(trigger, ARRAY_SIZE(trigger), "!%s\n", tevent->trigger); =20 retval =3D tracefs_event_file_write(instance->inst, tevent->system, tevent->event, "trigger", trigger); @@ -444,7 +444,7 @@ void trace_events_disable(struct trace_instance *instan= ce, static int trace_event_enable_filter(struct trace_instance *instance, struct trace_events *tevent) { - char filter[1024]; + char filter[MAX_PATH]; int retval; =20 if (!tevent->filter) @@ -456,7 +456,7 @@ static int trace_event_enable_filter(struct trace_insta= nce *instance, return 1; } =20 - snprintf(filter, 1024, "%s\n", tevent->filter); + snprintf(filter, ARRAY_SIZE(filter), "%s\n", tevent->filter); =20 debug_msg("Enabling %s:%s filter %s\n", tevent->system, tevent->event ? : "*", tevent->filter); @@ -479,7 +479,7 @@ static int trace_event_enable_filter(struct trace_insta= nce *instance, static int trace_event_enable_trigger(struct trace_instance *instance, struct trace_events *tevent) { - char trigger[1024]; + char trigger[MAX_PATH]; int retval; =20 if (!tevent->trigger) @@ -491,7 +491,7 @@ static int trace_event_enable_trigger(struct trace_inst= ance *instance, return 1; } =20 - snprintf(trigger, 1024, "%s\n", tevent->trigger); + snprintf(trigger, ARRAY_SIZE(trigger), "%s\n", tevent->trigger); =20 debug_msg("Enabling %s:%s trigger %s\n", tevent->system, tevent->event ? : "*", tevent->trigger); --=20 2.52.0