]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
perf hwmon: Guard label read against empty or failed reads
authorArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 8 Jun 2026 10:03:04 +0000 (07:03 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 10 Jun 2026 21:56:01 +0000 (18:56 -0300)
commit34d3d93fac6d92237cb9d730ca04c37ed361c7a6
treeb53dcc88bbf7044b6201c51adea97bb072a3bee4
parent51cdb188edeaf389e4377859b9c483c19ce5a259
perf hwmon: Guard label read against empty or failed reads

hwmon_pmu__read_events() reads label files with read() into a stack
buffer, strips trailing newlines, then checks buf[0] == '\0'.  When
read() returns 0 (empty file) or -1 (error), the buffer is never
written, so buf[0] reads uninitialized stack memory.  If the garbage
byte is non-zero, the code falls through to strdup(buf) which copies
arbitrary stack data as the label string.

Fix by checking read_len <= 0 before accessing buf contents, closing
the fd and skipping the entry.

Reported-by: sashiko-bot <sashiko-bot@kernel.org>
Fixes: 53cc0b351ec99278 ("perf hwmon_pmu: Add a tool PMU exposing events from hwmon in sysfs")
Cc: Ian Rogers <irogers@google.com>
Assisted-by: Claude:claude-opus-4.6
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/hwmon_pmu.c