From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2576C1B252F; Wed, 25 Sep 2024 11:41:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727264487; cv=none; b=APuJBl7LpbgWOgvfllxQhlglG0bsYx2KpGJsBfw/met6hAF8Me2dNBjNP0mwgr8Y6giuPilWQ1GA47dN7aBfnmIeSwR1pjgu5TmjttpKg6F5mNO+hfObZXgiTmKtiAPiumhSwZC0+ITfYFkIpVZS218npi+pbGzGxQnF+rtt9YE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727264487; c=relaxed/simple; bh=xUwHKg/aHeA4wtXK+NtOrCDg65Gr22zZMZETxZxnKfE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LGfp4bq9I4CTAXog0N5OE0Z/2N00+Ed6TpZulAVuQkkd5gxP/O/dmyFraQQtucJb47+cMLxjV4LhwYSTwOg08Er2qY2Lb2KMRuQW71dfssP4AEQqDUQ/D4TCmDPy2EeKj8ighPQl4cDQzSFN2leQvxNTnehDqam0ZhIXHkj32fg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=d2NTKKJ0; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="d2NTKKJ0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4A0DFC4CEC7; Wed, 25 Sep 2024 11:41:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727264487; bh=xUwHKg/aHeA4wtXK+NtOrCDg65Gr22zZMZETxZxnKfE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d2NTKKJ0e6Mt6hyl03crUXMQmOOJBpiVO257gmYIDdd66gM+pV+Y2uSsJ7jxZGmHd 0inuEvQd/t5aRDHki3RWysYnghtF6cSqmz1B+nWRWumF741R2CnUNev4B1dW9LA1ka mOONG9j71MNzywzKtNMO1yb4I957OPscjcJeVQT4M6xsKruEOD2cguz7fJ9maWqri+ jpEzPaC1PDyPOWlvlgSEVqCIMBjxRUKUhSRKM+RnBWHQdSHfHivodCYW+95J6gRdDk bwBQbHPHdcRHWn1NMcagixTJMEjzn+4Zzbonmx8rifNUxStqkB6Q6dplYlfQgShdqz gx4bOLkKSXosg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Ahmed S. Darwish" , Thomas Gleixner , Sasha Levin Subject: [PATCH AUTOSEL 6.11 100/244] tools/x86/kcpuid: Protect against faulty "max subleaf" values Date: Wed, 25 Sep 2024 07:25:21 -0400 Message-ID: <20240925113641.1297102-100-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240925113641.1297102-1-sashal@kernel.org> References: <20240925113641.1297102-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.11 Content-Transfer-Encoding: 8bit From: "Ahmed S. Darwish" [ Upstream commit cf96ab1a966b87b09fdd9e8cc8357d2d00776a3a ] Protect against the kcpuid code parsing faulty max subleaf numbers through a min() expression. Thus, ensuring that max_subleaf will always be ≤ MAX_SUBLEAF_NUM. Use "u32" for the subleaf numbers since kcpuid is compiled with -Wextra, which includes signed/unsigned comparisons warnings. Signed-off-by: Ahmed S. Darwish Signed-off-by: Thomas Gleixner Link: https://lore.kernel.org/all/20240718134755.378115-5-darwi@linutronix.de Signed-off-by: Sasha Levin --- tools/arch/x86/kcpuid/kcpuid.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tools/arch/x86/kcpuid/kcpuid.c b/tools/arch/x86/kcpuid/kcpuid.c index 24b7d017ec2c1..b7965dfff33a9 100644 --- a/tools/arch/x86/kcpuid/kcpuid.c +++ b/tools/arch/x86/kcpuid/kcpuid.c @@ -7,7 +7,8 @@ #include #include -#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#define min(a, b) (((a) < (b)) ? (a) : (b)) typedef unsigned int u32; typedef unsigned long long u64; @@ -207,12 +208,9 @@ static void raw_dump_range(struct cpuid_range *range) #define MAX_SUBLEAF_NUM 32 struct cpuid_range *setup_cpuid_range(u32 input_eax) { - u32 max_func, idx_func; - int subleaf; + u32 max_func, idx_func, subleaf, max_subleaf; + u32 eax, ebx, ecx, edx, f = input_eax; struct cpuid_range *range; - u32 eax, ebx, ecx, edx; - u32 f = input_eax; - int max_subleaf; bool allzero; eax = input_eax; @@ -258,7 +256,7 @@ struct cpuid_range *setup_cpuid_range(u32 input_eax) * others have to be tried (0xf) */ if (f == 0x7 || f == 0x14 || f == 0x17 || f == 0x18) - max_subleaf = (eax & 0xff) + 1; + max_subleaf = min((eax & 0xff) + 1, max_subleaf); if (f == 0xb) max_subleaf = 2; -- 2.43.0