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 4DD67367B65; Sat, 12 Sep 2026 19:56:53 +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=1789243014; cv=none; b=hWcQuU3J2S7XmmvGB8QMkcO/aMcUO5Bq3M5aVY/WMhw/vWi1U8y8cqrMhdQLAJC8ARh0GUftNXlrD1tiknrzMT2aTve12pcMmp4iT5kzFON9iON1CQiSMfimLBNDX8iOLs2GZrJXMjAjOaDU/6dy77z4PJUjMY2KssDfq6xIgw8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789243014; c=relaxed/simple; bh=galYppfGKS9pFwk9Y5HCd/+TX4R/wGSlM/OW5RyzX14=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PXRmgb6x8CvPCvqfZ9dko075LO2YZVIm7zc2RkqFUnZV8R3iqpVdeJJ0r+6UqRk/FttiUjaYW2BYt1gn5bnMjY5mPexrkHRQPOa9ax9a1droGWz2AjCINmtTFjdZiE8DIiAjIeQjPYaKkB165PGP1NX5McO5u54BiFcez2YS4RE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=MUrwCq+1; 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="MUrwCq+1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 604C21F000FF; Sat, 12 Sep 2026 19:56:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789243012; bh=iKcTwVfXkbM4Bg7iKkJXTJ1Sz8spQRSLnXZk3zRUZEY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=MUrwCq+1ZN4IJaik7/TUlJ46ORwfKrraMA1w8PH4fOZG5YXKpOGJLLnQB2BkIoagT 8onWa3vnblJjJUGAZ9wWzCqyaG6ghTA4h4TkN6vdzfrwQ7B8iisEX6/1OEUJvnzoVr H/ROKIHdTbIrEc35PNJD4oCprfEAayaBX3sb8e9I= 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.10 563/798] perf machine: Use snprintf() for guestmount path construction Date: Sat, 12 Sep 2026 09:03:11 +0200 Message-ID: <20260912065530.031588499@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065516.948645775@linuxfoundation.org> References: <20260912065516.948645775@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.10-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 Stable-dep-of: cc6abe0012bf ("perf machine: Check snprintf truncation in machines__findnew()") 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 51f618debbaf4..4907459639b6f 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -347,7 +347,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; @@ -1232,9 +1232,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