From: "Ahmed S. Darwish" <darwi@linutronix.de>
To: Borislav Petkov <bp@alien8.de>, Ingo Molnar <mingo@redhat.com>,
Dave Hansen <dave.hansen@linux.intel.com>,
"H. Peter Anvin" <hpa@zytor.com>,
x86@kernel.org, x86-cpuid@lists.linux.dev
Cc: Thomas Gleixner <tglx@linutronix.de>,
linux-kernel@vger.kernel.org,
"Ahmed S. Darwish" <darwi@linutronix.de>
Subject: [PATCH v1 4/9] tools/x86/kcpuid: Protect against faulty "max subleaf" values
Date: Thu, 18 Jul 2024 15:47:44 +0200 [thread overview]
Message-ID: <20240718134755.378115-5-darwi@linutronix.de> (raw)
In-Reply-To: <20240718134755.378115-1-darwi@linutronix.de>
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 <darwi@linutronix.de>
---
tools/arch/x86/kcpuid/kcpuid.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/tools/arch/x86/kcpuid/kcpuid.c b/tools/arch/x86/kcpuid/kcpuid.c
index a87cddc19554..c93015ee02e0 100644
--- a/tools/arch/x86/kcpuid/kcpuid.c
+++ b/tools/arch/x86/kcpuid/kcpuid.c
@@ -7,7 +7,8 @@
#include <string.h>
#include <getopt.h>
-#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,11 +208,10 @@ static void raw_dump_range(struct cpuid_range *range)
struct cpuid_range *setup_cpuid_range(u32 input_eax)
{
u32 max_func, idx_func;
- int subleaf;
struct cpuid_range *range;
+ u32 subleaf, max_subleaf;
u32 eax, ebx, ecx, edx;
u32 f = input_eax;
- int max_subleaf;
bool allzero;
eax = input_eax;
@@ -256,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.45.2
next prev parent reply other threads:[~2024-07-18 13:48 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-18 13:45 [ANNOUNCE] x86-cpuid.org: A machine-readable CPUID repository Ahmed S. Darwish
2024-07-18 13:47 ` [PATCH v1 0/9] tools/x86/kcpuid: Complete the CPUID database Ahmed S. Darwish
2024-07-18 13:47 ` [PATCH v1 1/9] tools/x86/kcpuid: Remove unused variable Ahmed S. Darwish
2024-08-02 7:28 ` [tip: x86/misc] " tip-bot2 for Ahmed S. Darwish
2024-07-18 13:47 ` [PATCH v1 2/9] tools/x86/kcpuid: Properly align long-description columns Ahmed S. Darwish
2024-08-02 7:28 ` [tip: x86/misc] " tip-bot2 for Ahmed S. Darwish
2024-07-18 13:47 ` [PATCH v1 3/9] tools/x86/kcpuid: Set max possible subleaves count to 64 Ahmed S. Darwish
2024-08-02 7:28 ` [tip: x86/misc] " tip-bot2 for Ahmed S. Darwish
2024-07-18 13:47 ` Ahmed S. Darwish [this message]
2024-08-02 7:28 ` [tip: x86/misc] tools/x86/kcpuid: Protect against faulty "max subleaf" values tip-bot2 for Ahmed S. Darwish
2024-07-18 13:47 ` [PATCH v1 5/9] tools/x86/kcpuid: Strip bitfield names leading/trailing whitespace Ahmed S. Darwish
2024-08-02 7:28 ` [tip: x86/misc] " tip-bot2 for Ahmed S. Darwish
2024-07-18 13:47 ` [PATCH v1 6/9] tools/x86/kcpuid: Recognize all leaves with subleaves Ahmed S. Darwish
2024-08-02 7:28 ` [tip: x86/misc] " tip-bot2 for Ahmed S. Darwish
2024-07-18 13:47 ` [PATCH v1 7/9] tools/x86/kcpuid: Parse subleaf ranges if provided Ahmed S. Darwish
2024-08-02 7:28 ` [tip: x86/misc] " tip-bot2 for Ahmed S. Darwish
2024-07-18 13:47 ` [PATCH v1 8/9] tools/x86/kcpuid: Introduce a complete cpuid bitfields CSV file Ahmed S. Darwish
2024-08-02 7:28 ` [tip: x86/misc] " tip-bot2 for Ahmed S. Darwish
2024-07-18 13:47 ` [PATCH v1 9/9] MAINTAINERS: Add x86 cpuid database entry Ahmed S. Darwish
2024-08-02 7:28 ` [tip: x86/misc] " tip-bot2 for Ahmed S. Darwish
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240718134755.378115-5-darwi@linutronix.de \
--to=darwi@linutronix.de \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86-cpuid@lists.linux.dev \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®