Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rtla: Replace magic number with MAX_PATH

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 <wander@redhat.com>
Link: https://lore.kernel.org/r/20260309195040.1019085-6-wander@redhat.com
Signed-off-by: Tomas Glozar <tglozar@redhat.com>

authored by

Wander Lairson Costa and committed by
Tomas Glozar
a29430c2 a50c5388

+13 -13
+1 -1
tools/tracing/rtla/src/osnoise.c
··· 62 62 if (!context->curr_cpus) 63 63 return -1; 64 64 65 - snprintf(buffer, 1024, "%s\n", cpus); 65 + snprintf(buffer, ARRAY_SIZE(buffer), "%s\n", cpus); 66 66 67 67 debug_msg("setting cpus to %s from %s", cpus, context->orig_cpus); 68 68
+2 -2
tools/tracing/rtla/src/timerlat_u.c
··· 32 32 static int timerlat_u_main(int cpu, struct timerlat_u_params *params) 33 33 { 34 34 struct sched_param sp = { .sched_priority = 95 }; 35 - char buffer[1024]; 35 + char buffer[MAX_PATH]; 36 36 int timerlat_fd; 37 37 cpu_set_t set; 38 38 int retval; ··· 83 83 84 84 /* add should continue with a signal handler */ 85 85 while (true) { 86 - retval = read(timerlat_fd, buffer, 1024); 86 + retval = read(timerlat_fd, buffer, ARRAY_SIZE(buffer)); 87 87 if (retval < 0) 88 88 break; 89 89 }
+10 -10
tools/tracing/rtla/src/trace.c
··· 313 313 static void trace_event_disable_filter(struct trace_instance *instance, 314 314 struct trace_events *tevent) 315 315 { 316 - char filter[1024]; 316 + char filter[MAX_PATH]; 317 317 int retval; 318 318 319 319 if (!tevent->filter) ··· 325 325 debug_msg("Disabling %s:%s filter %s\n", tevent->system, 326 326 tevent->event ? : "*", tevent->filter); 327 327 328 - snprintf(filter, 1024, "!%s\n", tevent->filter); 328 + snprintf(filter, ARRAY_SIZE(filter), "!%s\n", tevent->filter); 329 329 330 330 retval = tracefs_event_file_write(instance->inst, tevent->system, 331 331 tevent->event, "filter", filter); ··· 344 344 { 345 345 int retval, index, out_fd; 346 346 mode_t mode = 0644; 347 - char path[1024]; 347 + char path[MAX_PATH]; 348 348 char *hist; 349 349 350 350 if (!tevent) ··· 359 359 if (retval) 360 360 return; 361 361 362 - snprintf(path, 1024, "%s_%s_hist.txt", tevent->system, tevent->event); 362 + snprintf(path, ARRAY_SIZE(path), "%s_%s_hist.txt", tevent->system, tevent->event); 363 363 364 364 printf(" Saving event %s:%s hist to %s\n", tevent->system, tevent->event, path); 365 365 ··· 391 391 static void trace_event_disable_trigger(struct trace_instance *instance, 392 392 struct trace_events *tevent) 393 393 { 394 - char trigger[1024]; 394 + char trigger[MAX_PATH]; 395 395 int retval; 396 396 397 397 if (!tevent->trigger) ··· 405 405 406 406 trace_event_save_hist(instance, tevent); 407 407 408 - snprintf(trigger, 1024, "!%s\n", tevent->trigger); 408 + snprintf(trigger, ARRAY_SIZE(trigger), "!%s\n", tevent->trigger); 409 409 410 410 retval = tracefs_event_file_write(instance->inst, tevent->system, 411 411 tevent->event, "trigger", trigger); ··· 444 444 static int trace_event_enable_filter(struct trace_instance *instance, 445 445 struct trace_events *tevent) 446 446 { 447 - char filter[1024]; 447 + char filter[MAX_PATH]; 448 448 int retval; 449 449 450 450 if (!tevent->filter) ··· 456 456 return 1; 457 457 } 458 458 459 - snprintf(filter, 1024, "%s\n", tevent->filter); 459 + snprintf(filter, ARRAY_SIZE(filter), "%s\n", tevent->filter); 460 460 461 461 debug_msg("Enabling %s:%s filter %s\n", tevent->system, 462 462 tevent->event ? : "*", tevent->filter); ··· 479 479 static int trace_event_enable_trigger(struct trace_instance *instance, 480 480 struct trace_events *tevent) 481 481 { 482 - char trigger[1024]; 482 + char trigger[MAX_PATH]; 483 483 int retval; 484 484 485 485 if (!tevent->trigger) ··· 491 491 return 1; 492 492 } 493 493 494 - snprintf(trigger, 1024, "%s\n", tevent->trigger); 494 + snprintf(trigger, ARRAY_SIZE(trigger), "%s\n", tevent->trigger); 495 495 496 496 debug_msg("Enabling %s:%s trigger %s\n", tevent->system, 497 497 tevent->event ? : "*", tevent->trigger);