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 537EF3B42F9; Tue, 21 Jul 2026 20:42:07 +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=1784666529; cv=none; b=jeKY7/BQsWnFWEqAEqNP3LBK1mkk0waDlIwZbk9zEAXTRE5ps/tTS561XidCn9QrUQP2lj2AX13FFiuF0D7MdtySGi/7jOKbHReLStpzO7Iy/7JiYn/qEjdVx4C6jQ+ijNTwQPQe8cGV+ufIphmX6RDgGg36XKYe7eRzh6HjH+g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784666529; c=relaxed/simple; bh=+0ZUGMICtJ3fWvGvCZCCeykrZno3m22/NibFVciCRkc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GS3L0Z4cuf0r5BGiJfcrhl6PVk0N5X8QZHSm1utH8DdbOd5gme0SIaM1OheemSzki156XP/Q30lWxEhRkI2yTWpZbVO2NTOzk5jqqT1E7Mwp452oGah/rL0+eQ8Kr97Dtf24g5BXur6DYwNOEf54ERE+VqoJWxba6D1fYQVCyCc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=XcuFN5HJ; 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="XcuFN5HJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6001C1F00A3A; Tue, 21 Jul 2026 20:42:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784666527; bh=ysFXWLsoFJRuKlMSRQzx0TTauWkAm7o0apLl0NoQMCY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=XcuFN5HJfSTn08zFVsX2W1FCJpR0HbmN4z5vdwjzJFuMcxetD08W6mlF1c/w/Y6Gj z8Ea6uH2Cs+kAiMZNMlnL+T9kqlt8cIBa5mQekEU1sNwREWDyz5i8VKaweH03AfIFA A8HYXQV5fLVKEwnGxvp1lU8h5ersDIuofBfWZjuo= 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 6.6 0717/1266] perf machine: Use snprintf() for guestmount path construction Date: Tue, 21 Jul 2026 17:19:14 +0200 Message-ID: <20260721152457.912209757@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152441.786066624@linuxfoundation.org> References: <20260721152441.786066624@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 6.6-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 2f5a5245483ede..9e462ebdaca686 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -369,7 +369,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; @@ -1415,9 +1415,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