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 D743647125E; Tue, 21 Jul 2026 18:08:42 +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=1784657323; cv=none; b=Pl8Euun3nMcv2OMBW81ZoRICw1PBdniFmZSJER88SkBucZJVx3v6VHeKB03kPqz2MyUBIZ9q1/etS7N6y/WxcA1Npz/mmKsNWgQLKTUZvU85IwFVlAreoav+1z6oUW8YbKtq2FabzkQl4vTqtegY1W9p+BL+d9mowaS71/NMiP4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784657323; c=relaxed/simple; bh=54wuZu/8BNh65Ilu+Z01IdcKUa0DRBPKdiHA3KYu5YM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KSWxYXaGevwrtsZEhkjUjlVwdTjT+1MoS/S0sULwFfkGlbF/mThClL1NnSnHFIW8brcvvord3NyF6m9e4pyGSqLzVVp8up5A3XSwq+Qiv4z1UZkIhXOP4eP27jkhJrMihKS141Z3RFxTdEcvXcAn5SGq4MCSFoxrSoUJO73DYAg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Cxi+tc8k; 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="Cxi+tc8k" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF53C1F000E9; Tue, 21 Jul 2026 18:08:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784657322; bh=A9cvA3rI1LxXPklDecg6NGA6E442oYBEmMoDwZyy6sY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Cxi+tc8knl5jcTs9qTszYijnKYjmvKyq06cVYDzAdtFBg2dNPwwEzDvgDivanyTIb E6GfBtAtx9CcBA+/Y+QEb2w3v3x5EN+H5xlV20ian4VJj73tOv99QHDSru5pfjM2Cd dc+SiZlRUfHZsg6QhtjyBKWIvmsK38GXM0ryDHvI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, sashiko-bot , Jiri Olsa , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 6.18 0721/1611] tools lib api: Fix mount_overload() snprintf truncation and toupper range Date: Tue, 21 Jul 2026 17:13:57 +0200 Message-ID: <20260721152531.596776087@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152514.750365251@linuxfoundation.org> References: <20260721152514.750365251@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.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Arnaldo Carvalho de Melo [ Upstream commit fd1f70776add263f8ef38a87ae593c75303f1dcd ] mount_overload() builds an environment variable name like "PERF_SYSFS_ENVIRONMENT" from fs->name. Two bugs: 1) snprintf() uses name_len as the buffer size instead of sizeof(upper_name). For fs->name = "sysfs" (len=5), the output is truncated to "PERF" (4 chars + null), so getenv() never finds the intended variable. 2) mem_toupper() only uppercases name_len bytes, converting just the "PERF" prefix rather than the full string including the filesystem name portion. Fix by using sizeof(upper_name) for snprintf and strlen(upper_name) for mem_toupper, so the full "PERF_SYSFS_ENVIRONMENT" string is correctly formatted and uppercased. Reported-by: sashiko-bot Fixes: 73ca85ad364769ff ("tools lib api fs: Add FSTYPE__mount() method") Cc: Jiri Olsa Assisted-by: Claude:claude-opus-4.6 Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/lib/api/fs/fs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/lib/api/fs/fs.c b/tools/lib/api/fs/fs.c index d16911818d4d35..cbd8eab0d1df0c 100644 --- a/tools/lib/api/fs/fs.c +++ b/tools/lib/api/fs/fs.c @@ -261,8 +261,8 @@ static const char *mount_overload(struct fs *fs) /* "PERF_" + name + "_ENVIRONMENT" + '\0' */ char upper_name[5 + name_len + 12 + 1]; - snprintf(upper_name, name_len, "PERF_%s_ENVIRONMENT", fs->name); - mem_toupper(upper_name, name_len); + snprintf(upper_name, sizeof(upper_name), "PERF_%s_ENVIRONMENT", fs->name); + mem_toupper(upper_name, strlen(upper_name)); return getenv(upper_name) ?: *fs->mounts; } -- 2.53.0