From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795017394; b=fyz7TweHZtosJ1bYAUfW5iS1OmNPub3lebEJnh0VKCjH3fCiGziim3M6/SO0r3RRfR22 UpErpyKy6fhGKqu8J+0hxLnPLxHoP5gf82uyedHRYuLTXuTbyFcGBViJKnE1C415RVDP2 xyiXaT3yqhU6OToG5GXSY6hlYOfjTu5Pf78FmVpJRStoU4EDhXC0uzjtEtAYtumWJu5b7 5b1nNsYNKs8X54j/au7aKQ4T8lJewubsH4+F7LK0IDYMRItmSGkU6HJ7U+ehYvTz/LqxO p+Jm5j1ir2aswcVdBtuMljlLrw5Fo1gIykhIgQGGfQFqBlAtGO8DAi4rTLnfr4hIYfQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795017394; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=xeVEwBEqL4wyD005ne/b6GbNqcMaMO+uGhS6r7Dbilk=; b=xsI09BQjljFznv5nVFOEKodzOh95bNCFwEUKZRDlkWJBLpsVyjlf7c/wJA1cPoBHPyg+ 5Rha3Qwyqe03FwZizpNDyewaj1mn28UsxkFz4hss8MU3OxYD950shqqLbiKd7Yewc+C73 +og7kal2UlffcuS2qyCstA+l/yhOm/ta992WwnNpY6+CuQ0nzMAASF5PmoOI2DiiVwZX5 HpRGrT0jUYhPSDzmzNNb28tIKIAKpn8LgrB5aKzK6b4n3k2A/m9fNWTJ8CVyLisNDJg7M qG4DUaMlWf1D0Hw73SYPnEQDRAvOA6Xr/de5q/F7DjxVLdJ8ElJH5kuku1135lw3ISA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=QBaZ11vq; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A002C606A31C; Wed, 18 Nov 2026 15:56:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=QBaZ11vq Received: by smtp.kernel.org (Postfix) with ESMTPSA id F02CD1F000C4; Wed, 18 Nov 2026 15:56:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795017394; bh=xeVEwBEqL4wyD005ne/b6GbNqcMaMO+uGhS6r7Dbilk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=QBaZ11vq++nxs7PUnQQxpPEwBQRX0onmZNEmo9hismQxRK81p6ZwN5isKEGn6+2Az 8NXwtnmskEjCoSjv+0KOBu2J9WlHe0SYFt/MsosxRp1ddAB0RnFt2AHxrTk7QHux6D GFWTknOZAvkySiMpyX0hxSSE9ocUMEUnJyqW8/8A= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ian Rogers , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 7.3 0829/2651] perf machine: Add session back pointer to fix out of bounds read Date: Wed, 18 Nov 2026 15:34:29 +0100 Message-ID: <20261118150317.731876963@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150247.972732815@linuxfoundation.org> References: <20261118150247.972732815@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ian Rogers [ Upstream commit d227b45fc162ce9134bb96f33f71e6952ec36ea5 ] thread__e_machine_endian() decides whether a thread is live, and so whether to read /proc/pid/exe rather than fall back to the perf.data environment, by recovering the session from the machine: session = container_of(machine->machines, struct perf_session, machines); is_live = !session->data; That only holds when the struct machines is the one embedded in a struct perf_session. It is not the only one. aslr_tool keeps its own in struct aslr_tool, and hists_cumulate, hists_filter, hists_link, hists_output and thread-maps-share each put one on the stack. For those the container_of subtracts offsetof(struct perf_session, machines) from an address that was never inside a session, and the following load of session->data reads outside the object, which is what ASan reports. Replace the derivation with an explicit link. machines__init() takes the owning session, or NULL when the machines is standalone, and thread__e_machine_endian() reads it back through machines__session(). A NULL session is treated as live. The tests use synthetic pids that have no /proc entry, so the read fails there and the e_machine falls back to EM_HOST as before, rather than being decided by whatever the out of bounds read happened to return. perf inject registers its session with the aslr tool once the session exists, before any event is processed, so that tool keeps reporting file based threads as not live. Fixes: 70351029b556 ("perf thread: Add support for reading the e_machine type for a thread") Assisted-by: Antigravity:gemini-3.1-pro Signed-off-by: Ian Rogers Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/builtin-inject.c | 3 +++ tools/perf/tests/hists_cumulate.c | 2 +- tools/perf/tests/hists_filter.c | 2 +- tools/perf/tests/hists_link.c | 2 +- tools/perf/tests/hists_output.c | 2 +- tools/perf/tests/thread-maps-share.c | 3 ++- tools/perf/util/aslr.c | 10 +++++++++- tools/perf/util/aslr.h | 2 ++ tools/perf/util/machine.c | 3 ++- tools/perf/util/machine.h | 10 +++++++++- tools/perf/util/session.c | 2 +- tools/perf/util/thread.c | 8 +++----- 12 files changed, 35 insertions(+), 14 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 70bbfad5653e1..1446e5c0f63e8 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -2880,6 +2880,9 @@ int cmd_inject(int argc, const char **argv) goto out_close_output; } + if (inject.aslr) + aslr_tool__register_session(tool, inject.session); + if (zstd_init(&(inject.session->zstd_data), 0) < 0) pr_warning("Decompression initialization failed.\n"); diff --git a/tools/perf/tests/hists_cumulate.c b/tools/perf/tests/hists_cumulate.c index 9356451a172ea..c4a11a3255bc9 100644 --- a/tools/perf/tests/hists_cumulate.c +++ b/tools/perf/tests/hists_cumulate.c @@ -723,7 +723,7 @@ static int test__hists_cumulate(struct test_suite *test __maybe_unused, int subt goto out; err = TEST_FAIL; - if (machines__init(&machines)) + if (machines__init(&machines, /*session=*/NULL)) goto out; /* setup threads/dso/map/symbols also */ diff --git a/tools/perf/tests/hists_filter.c b/tools/perf/tests/hists_filter.c index f9eaa511487b4..6c7e4cdc71a72 100644 --- a/tools/perf/tests/hists_filter.c +++ b/tools/perf/tests/hists_filter.c @@ -131,7 +131,7 @@ static int test__hists_filter(struct test_suite *test __maybe_unused, int subtes goto out; err = TEST_FAIL; - if (machines__init(&machines)) + if (machines__init(&machines, /*session=*/NULL)) goto out; /* setup threads/dso/map/symbols also */ diff --git a/tools/perf/tests/hists_link.c b/tools/perf/tests/hists_link.c index d88591bcbe508..cd32c82776275 100644 --- a/tools/perf/tests/hists_link.c +++ b/tools/perf/tests/hists_link.c @@ -303,7 +303,7 @@ static int test__hists_link(struct test_suite *test __maybe_unused, int subtest goto out; err = TEST_FAIL; - if (machines__init(&machines)) + if (machines__init(&machines, /*session=*/NULL)) goto out; /* setup threads/dso/map/symbols also */ diff --git a/tools/perf/tests/hists_output.c b/tools/perf/tests/hists_output.c index f58c8d18fe330..35d230a83e430 100644 --- a/tools/perf/tests/hists_output.c +++ b/tools/perf/tests/hists_output.c @@ -610,7 +610,7 @@ static int test__hists_output(struct test_suite *test __maybe_unused, int subtes goto out; err = TEST_FAIL; - if (machines__init(&machines)) + if (machines__init(&machines, /*session=*/NULL)) goto out; /* setup threads/dso/map/symbols also */ diff --git a/tools/perf/tests/thread-maps-share.c b/tools/perf/tests/thread-maps-share.c index 0431bff31b3a1..4a0bbf715acb4 100644 --- a/tools/perf/tests/thread-maps-share.c +++ b/tools/perf/tests/thread-maps-share.c @@ -27,7 +27,8 @@ static int test__thread_maps_share(struct test_suite *test __maybe_unused, int s * other group (pid: 4, tids: 4, 5) */ - TEST_ASSERT_VAL("failed to init machines", machines__init(&machines) == 0); + TEST_ASSERT_VAL("failed to init machines", + machines__init(&machines, /*session=*/NULL) == 0); machine = &machines.host; /* create process with 4 threads */ diff --git a/tools/perf/util/aslr.c b/tools/perf/util/aslr.c index 027695d967798..76eba1a23bc7f 100644 --- a/tools/perf/util/aslr.c +++ b/tools/perf/util/aslr.c @@ -1243,7 +1243,7 @@ static int aslr_tool__init(struct aslr_tool *aslr, struct perf_tool *delegate) delegate_tool__init(&aslr->tool, delegate); aslr->tool.tool.ordered_events = true; - if (machines__init(&aslr->machines)) + if (machines__init(&aslr->machines, /*session=*/NULL)) return -ENOMEM; hashmap__init(&aslr->remap_addresses, @@ -1343,6 +1343,14 @@ void aslr_tool__delete(struct perf_tool *tool) free(aslr); } +void aslr_tool__register_session(struct perf_tool *tool, struct perf_session *session) +{ + struct delegate_tool *del_tool = container_of(tool, struct delegate_tool, tool); + struct aslr_tool *aslr = container_of(del_tool, struct aslr_tool, tool); + + aslr->machines.session = session; +} + int aslr_tool__cache_orig_attrs(struct perf_tool *tool, struct evsel *evsel) { struct delegate_tool *del_tool = container_of(tool, struct delegate_tool, tool); diff --git a/tools/perf/util/aslr.h b/tools/perf/util/aslr.h index 522e31c8e2c04..9cc14f0263dbe 100644 --- a/tools/perf/util/aslr.h +++ b/tools/perf/util/aslr.h @@ -28,6 +28,7 @@ PERF_SAMPLE_CODE_PAGE_SIZE | \ PERF_SAMPLE_AUX) +struct perf_session; struct perf_tool; struct evsel; struct evlist; @@ -36,6 +37,7 @@ union perf_event; struct perf_tool *aslr_tool__new(struct perf_tool *delegate); void aslr_tool__delete(struct perf_tool *tool); +void aslr_tool__register_session(struct perf_tool *tool, struct perf_session *session); void aslr_tool__strip_attr_event(union perf_event *event, struct evlist *evlist); int aslr_tool__cache_orig_attrs(struct perf_tool *tool, struct evsel *evsel); void aslr_tool__strip_evlist(const struct perf_tool *tool, struct evlist *evlist); diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index ad29a30a7b891..076d167380f20 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -233,10 +233,11 @@ void machine__delete(struct machine *machine) } } -int machines__init(struct machines *machines) +int machines__init(struct machines *machines, struct perf_session *session) { int err = machine__init(&machines->host, "", HOST_KERNEL_ID); + machines->session = session; machines->host.machines = machines; machines->guests = RB_ROOT_CACHED; return err; diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h index 26f9827062f5e..973a59f7c26ab 100644 --- a/tools/perf/util/machine.h +++ b/tools/perf/util/machine.h @@ -15,6 +15,7 @@ struct dso; struct dso_id; struct evsel; struct perf_sample; +struct perf_session; struct symbol; struct target; struct thread; @@ -148,13 +149,20 @@ int machine__process_event(struct machine *machine, union perf_event *event, typedef void (*machine__process_t)(struct machine *machine, void *data); struct machines { + /** @session: back link to owning session if there is one. */ + struct perf_session *session; struct machine host; struct rb_root_cached guests; }; -int machines__init(struct machines *machines); +int machines__init(struct machines *machines, struct perf_session *session); void machines__exit(struct machines *machines); +static inline struct perf_session *machines__session(struct machines *machines) +{ + return machines->session; +} + void machines__process_guests(struct machines *machines, machine__process_t process, void *data); diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 3237870a1a34b..1505a6f125be0 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -161,7 +161,7 @@ struct perf_session *__perf_session__new(struct perf_data *data, session->active_decomp = &session->decomp_data; INIT_LIST_HEAD(&session->auxtrace_index); perf_env__init(&session->header.env); - if (machines__init(&session->machines)) + if (machines__init(&session->machines, session)) goto out_delete; ordered_events__init(&session->ordered_events, diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c index f0d3773d87db0..8b8ca94e89ea8 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c @@ -531,12 +531,10 @@ uint16_t thread__e_machine_endian(struct thread *thread, struct machine *machine bool is_live = machine->machines == NULL; if (!is_live) { - /* Check if the session has a data file. */ - struct perf_session *session = container_of(machine->machines, - struct perf_session, - machines); + /* Check if the session has a data file (assume no session is a test). */ + struct perf_session *session = machines__session(machine->machines); - is_live = !session->data; + is_live = !session || !session->data; } /* Read from /proc/pid/exe if live. */ if (is_live) { -- 2.53.0