From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A005437111; Tue, 21 Jul 2026 22:12:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784671953; cv=none; b=NPIddWL3ALGJgZi5HlfxWet0qxN9ctdw3EplVANf7xegKM32TSSuz0TpEfs/N/hzJJRTCWTuLxfz2yaUrdAIb6xL9mPoJgV8GO3WIx/5jpJdTLhdk+UPiTHIs6Y2M5Uvn0utWTaS0jJEZRhXiGy/llxAtC9td1vYU1UTn5rryGE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784671953; c=relaxed/simple; bh=gM+8T1K3Ajs1oQppqyGL0Q9132hAXIrOTZcm5egRGNk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cleervQliZ9lIuozNDoB4YC9uw02dw+C7NK+EK99t/sVw4IYW8xKx98up6P6L84jGyC2DYlcVj9ZJ8cCQSCmm4d2U63n8t5agtOLJcdzVNbCDA/lFLkANAnf9lKvvQ77HsoSULaNcg+S8JPdTQGd9lMUMx7Ol2/BA4tVi8eyhME= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=q5kczycX; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="q5kczycX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 921841F000E9; Tue, 21 Jul 2026 22:12:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784671952; bh=9ybsKbi54/Min/R7n2mY9gccs0MCmZic4GJqup4t8FE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=q5kczycXEzyXT3fzrNL0NrfZ5ENOQSu0kNAWp9P5zcRv360NKhpF2DVIuejHDWryA 6jhA7bOAY/Vzlem31hyyix95E1BAMtjMB2u1qvhCr7Cf8tHkhc2iuSvs6N9pydPiig euG9J1eJ+Vpn/29SV4QfxLM8ACqoF/+xfFkKkwAE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, sashiko-bot , "Zhang, Yanmin" , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 5.15 440/843] perf machine: Use snprintf() for guestmount path construction Date: Tue, 21 Jul 2026 17:21:15 +0200 Message-ID: <20260721152415.928025703@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152405.946368001@linuxfoundation.org> References: <20260721152405.946368001@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Arnaldo Carvalho de Melo [ Upstream commit fe63d3bca288c5bb983304efd5fc3a5ff3183403 ] machines__findnew() and machines__create_guest_kernel_maps() use sprintf() to build paths by prepending symbol_conf.guestmount. Both write into PATH_MAX stack buffers, but guestmount comes from user configuration and is not length-checked. A guestmount path at or near PATH_MAX causes a stack buffer overflow. Switch to snprintf() with sizeof() to prevent overflow. The subsequent access()/fopen() calls will fail on a truncated path. Fixes: a1645ce12adb6c9c ("perf: 'perf kvm' tool for monitoring guest performance from host") Reported-by: sashiko-bot Cc: Zhang, Yanmin Assisted-by: Claude:claude-opus-4.6 Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/machine.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 7e7c63fcd14068..9a78261cffec9b 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -348,7 +348,7 @@ struct machine *machines__findnew(struct machines *machines, pid_t pid) if ((pid != HOST_KERNEL_ID) && (pid != DEFAULT_GUEST_KERNEL_ID) && (symbol_conf.guestmount)) { - sprintf(path, "%s/%d", symbol_conf.guestmount, pid); + snprintf(path, sizeof(path), "%s/%d", symbol_conf.guestmount, pid); if (access(path, R_OK)) { static struct strlist *seen; @@ -1260,9 +1260,9 @@ int machines__create_guest_kernel_maps(struct machines *machines) namelist[i]->d_name); continue; } - sprintf(path, "%s/%s/proc/kallsyms", - symbol_conf.guestmount, - namelist[i]->d_name); + snprintf(path, sizeof(path), "%s/%s/proc/kallsyms", + symbol_conf.guestmount, + namelist[i]->d_name); ret = access(path, R_OK); if (ret) { pr_debug("Can't access file %s\n", path); -- 2.53.0