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=1796387609; b=OrhOOdt+OHrvrWvvK/ZGg+DyLc3sH1vsi3xNNZuGUpbYYR4VdaaBL97VVNT7Xr/MCIzD C4iMU5BEzmL5w6BgQN1SOMVuCqOm2EFXSM8OtV5nPKArhngHeUG57r7D2CCDS6RFrATMP nVB0gcc4PbHW2pcnaEysHNCw7Er5+LNiAulz4oretA49W1FFBWv7tkdQvDBK0Ub8KtUQ2 vlUuCAckmukOGuzXmnwZyjyPNYHPZ4MClmoD2HBXOeF2PFwk7lPu+SbYG3EXjl3LNhRmg 4mq9Si549qrhcN5tu4sNI2XN4eUa8hhYr53OyEGZelAafSsgojwFBLVAJ5N2g4IrXrQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387609; 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=nPxfJynSLNru8A/gL1ILCeurZbyJHS233I9PiZjOQg0=; b=4gEA8yV8vLP+JvFAGUQIxd5Z7X65J6w8E/Cy2r0qnToVysKAXDRXj/9g8FmsgqBlrlSD NgIQw+vsJYaTq1H0ZZJshNzlThbOaBykDdRocMITTjInky80TWQNbvOaZ8Alo8OJOo1KM wB5U5uB80a3pSO1maS59uRRSGmdHDFPeNObvquAGaH2Ee+u65AuXOZiA0Dih4QAaR4CTU 5o62dvwqMJPn2tKCGWmnuarda1GIZwILKY1rYLelrJ1SImdk4kyYt9x3/SjuiybPkLp+4 f+rd15+X0STQ4Yg0rOxepFBuof2ilfMV1/yEczEXiWda6MNMikudC75KEXtNcMv4bOA== 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=KQ8l7tUo; 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 2B918606A322; Fri, 4 Dec 2026 12:33:29 +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=KQ8l7tUo Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C5691F000C2; Fri, 4 Dec 2026 12:33:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387609; bh=nPxfJynSLNru8A/gL1ILCeurZbyJHS233I9PiZjOQg0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=KQ8l7tUoDKqfOZtcE/zN1FZCNuWKKmpyLCChjR8IKGTk0x6eTR9BUkb253FYURkrM hrFdtg7Yrx/2w6RhpW0yr8ucIJS185RXG8aCdQIam84M3kPhuu9bwUE63hb6WgOmzU HN4n/nOqphBn11y9FBb6P1pXlsarYkxXb0JQZpAU= 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 6.1 0314/1059] perf test code-reading: Fix duplicate kernel maps and machine leak Date: Fri, 4 Dec 2026 18:57:25 +0900 Message-ID: <20261204100652.406052657@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ian Rogers [ Upstream commit 58bf7b7af359d4c6f1af29fd8d2067bbcff1d8c7 ] In do_test_code_reading(), machine__new_host(&host_env) already calls machine__create_kernel_maps(machine). Calling machine__create_kernel_maps(machine) a second time immediately afterwards duplicates all kernel module maps in machine->kmaps, causing dso__load_kcore()'s module validation (do_validate_kcore_modules()) to fail and fall back to /proc/kallsyms. Furthermore, when try_kcore is true and !have_kcore, returning TEST_CODE_READING_NO_KCORE directly bypasses out_err, leaking the entire struct machine, its kernel/module maps and DSOs, all kallsyms symbols, and host_env. Remove the redundant machine__create_kernel_maps() call, check for !machine after machine__new_host(), and jump to out_err when returning TEST_CODE_READING_NO_KCORE. Fixes: 0fd4008ed755c52d ("perf test: Use machine__new_host in mmap thread code reading test") Assisted-by: Antigravity:gemini-3.1-pro Signed-off-by: Ian Rogers Signed-off-by: Arnaldo Carvalho de Melo [ sashal: Dropped the host_env/perf_env__init parts that don't exist here, and on machine__new_host() failure used "return err" instead of "goto out_err" to avoid a NULL dereference in cleanup. ] Signed-off-by: Sasha Levin --- tools/perf/tests/code-reading.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c index 95feb6ef34a0a..b357abe6d7237 100644 --- a/tools/perf/tests/code-reading.c +++ b/tools/perf/tests/code-reading.c @@ -569,13 +569,11 @@ static int do_test_code_reading(bool try_kcore) pid = getpid(); machine = machine__new_host(); - machine->env = &perf_env; - - ret = machine__create_kernel_maps(machine); - if (ret < 0) { - pr_debug("machine__create_kernel_maps failed\n"); - goto out_err; + if (!machine) { + pr_debug("machine__new_host failed\n"); + return err; } + machine->env = &perf_env; /* Force the use of kallsyms instead of vmlinux to try kcore */ if (try_kcore) @@ -592,8 +590,10 @@ static int do_test_code_reading(bool try_kcore) have_kcore = dso__is_kcore(map->dso); /* 2nd time through we just try kcore */ - if (try_kcore && !have_kcore) - return TEST_CODE_READING_NO_KCORE; + if (try_kcore && !have_kcore) { + err = TEST_CODE_READING_NO_KCORE; + goto out_err; + } /* No point getting kernel events if there is no kernel object */ if (!have_vmlinux && !have_kcore) -- 2.53.0