From nobody Tue Dec 2 02:58:56 2025 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 A7BD9338F2F for ; Mon, 17 Nov 2025 18:56:59 +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=1763405822; cv=none; b=IJSZGz6IVJcV9bnHVrAmSUAvHr19pL4XVSIg2MsXmhpDh6qU+ZhJrsfZ3hCNTaVYJfG0GluU/4yd1hRobNQkib6fmJtqXUDjP1mhEiklUjRE0QxSq+7txKKu7IvHYtn0+rKZXq8BgFqBi6ecONAtArJUlsEm6fp3Fg7qUUsPQM8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763405822; c=relaxed/simple; bh=dKoUYxM8LL9t2vzI/PpW0eLOO45rOCFrE/qFP2Mf2do=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mXcp3AOoRyrZKWPj4MFRAtjyvtG5/+ih93uNDSwzF+lkC+qN1tmEKOuFaUwyUjjvtUJJovGALJKbNd2w+1a2eJnVfNVrAxwr1loPSMsdNZEw8LF8R4ttbX/+6ctdeThoaEjtxxdr4qS7IrtdykHNnZWjKcrA65matXt1NhAO1Po= 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=dic/6yfV; 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="dic/6yfV" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763405818; 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=W92+hDsPlnWwpf3RV+flsE4eFQLqmU6MxoptDwLVLG4=; b=dic/6yfVAf4nWZDPPLjDikWlnTj4tlnnzlEClFdYPtcYgSEBJMRPyuco9JRCMc9b7/KSRr 6XTJIN+KPvyhbqK39lu1uxQYZ98XTNypBugJsOXqx/MNVIJmf2NLuQkyEnr2JZ/Pg0VQs8 y01wJis4QUFB9jtQuMT7HEAYk/nivWw= Received: from mx-prod-mc-05.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-544-WJFHpT6FO62vQGJQD6W6Rw-1; Mon, 17 Nov 2025 13:56:55 -0500 X-MC-Unique: WJFHpT6FO62vQGJQD6W6Rw-1 X-Mimecast-MFC-AGG-ID: WJFHpT6FO62vQGJQD6W6Rw_1763405814 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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3962E1956094; Mon, 17 Nov 2025 18:56:54 +0000 (UTC) Received: from wcosta-thinkpadt14gen4.rmtbr.csb (unknown [10.22.81.153]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1FB8D180049F; Mon, 17 Nov 2025 18:56:49 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Wander Lairson Costa , Tomas Glozar , Ivan Pravdin , Crystal Wood , John Kacur , Costa Shulyupin , Tiezhu Yang , linux-trace-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), linux-kernel@vger.kernel.org (open list), bpf@vger.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_)) Subject: [rtla 11/13] rtla: Replace magic number with MAX_PATH Date: Mon, 17 Nov 2025 15:41:18 -0300 Message-ID: <20251117184409.42831-12-wander@redhat.com> In-Reply-To: <20251117184409.42831-1-wander@redhat.com> References: <20251117184409.42831-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 5075e0f485c77..d502cbbcea91b 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 01dbf9a6b5a51..52977e725c79c 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; @@ -87,7 +87,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 813f4368f104b..658a6e94edfba 100644 --- a/tools/tracing/rtla/src/trace.c +++ b/tools/tracing/rtla/src/trace.c @@ -330,7 +330,7 @@ int 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) @@ -342,7 +342,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); @@ -361,7 +361,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) @@ -376,7 +376,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 @@ -408,7 +408,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) @@ -422,7 +422,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); @@ -461,7 +461,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) @@ -473,7 +473,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); @@ -496,7 +496,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) @@ -508,7 +508,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.51.1