From: "James O. D. Hunt" <james.o.hunt@intel.com>
To: linux-perf-users@vger.kernel.org, Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
"Liang, Kan" <kan.liang@linux.intel.com>
Cc: linux-kernel@vger.kernel.org,
"James O . D . Hunt" <james.o.hunt@intel.com>
Subject: [PATCH] perf: header: Check read return
Date: Mon, 7 Apr 2025 17:35:38 +0100 [thread overview]
Message-ID: <20250407163538.176140-1-james.o.hunt@intel.com> (raw)
Check the `readn()` return value in `read_attr()` if there are remaining
header bytes to read (previously, the return value was being ignored).
Fixes: 69996df486fc3 ("perf tools: Enable reading of perf.data files from different ABI rev")
Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
---
| 5 +++++
1 file changed, 5 insertions(+)
--git a/tools/perf/util/header.c b/tools/perf/util/header.c
index e3cdc3b7b4ab..09dfd95e350c 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -4161,6 +4161,11 @@ static int read_attr(int fd, struct perf_header *ph,
ptr += PERF_ATTR_SIZE_VER0;
ret = readn(fd, ptr, left);
+ if (ret <= 0) {
+ pr_debug("cannot read %zu remaining bytes of header attr\n",
+ left);
+ return -1;
+ }
}
/* read perf_file_section, ids are read in caller */
ret = readn(fd, &f_attr->ids, sizeof(f_attr->ids));
--
2.49.0
reply other threads:[~2025-04-07 16:36 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250407163538.176140-1-james.o.hunt@intel.com \
--to=james.o.hunt@intel.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®