提交 d92d7ef5 编写于 作者: I Ian Rogers 提交者: Zheng Zengkai

perf synthetic events: Avoid write of uninitialized memory when generating...

perf synthetic events: Avoid write of uninitialized memory when generating PERF_RECORD_MMAP* records

stable inclusion
from stable-5.10.27
commit efb334c4e5ffd98d1de9d0ede16703ced913ad71
bugzilla: 51493

--------------------------------

[ Upstream commit 2a76f6de ]

Account for alignment bytes in the zero-ing memset.

Fixes: 1a853e36 ("perf record: Allow specifying a pid to record")
Signed-off-by: NIan Rogers <irogers@google.com>
Acked-by: NJiri Olsa <jolsa@redhat.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20210309234945.419254-1-irogers@google.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Acked-by: N  Weilong Chen <chenweilong@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 975e3ebe
......@@ -384,7 +384,7 @@ int perf_event__synthesize_mmap_events(struct perf_tool *tool,
while (!io.eof) {
static const char anonstr[] = "//anon";
size_t size;
size_t size, aligned_size;
/* ensure null termination since stack will be reused. */
event->mmap2.filename[0] = '\0';
......@@ -444,11 +444,12 @@ int perf_event__synthesize_mmap_events(struct perf_tool *tool,
}
size = strlen(event->mmap2.filename) + 1;
size = PERF_ALIGN(size, sizeof(u64));
aligned_size = PERF_ALIGN(size, sizeof(u64));
event->mmap2.len -= event->mmap.start;
event->mmap2.header.size = (sizeof(event->mmap2) -
(sizeof(event->mmap2.filename) - size));
memset(event->mmap2.filename + size, 0, machine->id_hdr_size);
(sizeof(event->mmap2.filename) - aligned_size));
memset(event->mmap2.filename + size, 0, machine->id_hdr_size +
(aligned_size - size));
event->mmap2.header.size += machine->id_hdr_size;
event->mmap2.pid = tgid;
event->mmap2.tid = pid;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册