]> git.ipfire.org Git - thirdparty/linux.git/commit
rtla: Ensure null termination after read operations in utils.c
authorWander Lairson Costa <wander@redhat.com>
Tue, 6 Jan 2026 11:49:52 +0000 (08:49 -0300)
committerTomas Glozar <tglozar@redhat.com>
Wed, 7 Jan 2026 14:57:56 +0000 (15:57 +0100)
commit33e3c807ab22bd4002640c8fe47fa30fd4f44ca0
treebfb6d16e6500a4550e14ba4bd41447aa653d89e9
parentaf2962d68b970b15d8910be2b0386b4f147ed78b
rtla: Ensure null termination after read operations in utils.c

Add explicit null termination and buffer initialization for read()
operations in procfs_is_workload_pid() and get_self_cgroup() functions.
The read() system call does not null-terminate the data it reads, and
when the buffer is filled to capacity, subsequent string operations
will read past the buffer boundary searching for a null terminator.

In procfs_is_workload_pid(), explicitly set buffer[MAX_PATH-1] to '\0'
to ensure the buffer is always null-terminated before passing it to
strncmp(). In get_self_cgroup(), use memset() to zero the path buffer
before reading, which ensures null termination when retval is less than
MAX_PATH. Additionally, set path[MAX_PATH-1] to '\0' after the read to
handle the case where the buffer is filled completely.

These defensive buffer handling practices prevent potential buffer
overruns and align with the ongoing buffer safety improvements across
the rtla codebase.

Signed-off-by: Wander Lairson Costa <wander@redhat.com>
Link: https://lore.kernel.org/r/20260106133655.249887-17-wander@redhat.com
Signed-off-by: Tomas Glozar <tglozar@redhat.com>
tools/tracing/rtla/src/utils.c