lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <174289354654.14745.7813168122836962597.tip-bot2@tip-bot2>
Date: Tue, 25 Mar 2025 09:05:46 -0000
From: "tip-bot2 for Ahmed S. Darwish" <tip-bot2@...utronix.de>
To: linux-tip-commits@...r.kernel.org
Cc: "Ahmed S. Darwish" <darwi@...utronix.de>, Ingo Molnar <mingo@...nel.org>,
 "H. Peter Anvin" <hpa@...or.com>,
 Linus Torvalds <torvalds@...ux-foundation.org>,
 Josh Poimboeuf <jpoimboe@...hat.com>, x86@...nel.org,
 linux-kernel@...r.kernel.org
Subject:
 [tip: x86/cpu] tools/x86/kcpuid: Exit the program on invalid parameters

The following commit has been merged into the x86/cpu branch of tip:

Commit-ID:     a866a6775793a2554585073704b83c4691d80740
Gitweb:        https://git.kernel.org/tip/a866a6775793a2554585073704b83c4691d80740
Author:        Ahmed S. Darwish <darwi@...utronix.de>
AuthorDate:    Mon, 24 Mar 2025 15:20:23 +01:00
Committer:     Ingo Molnar <mingo@...nel.org>
CommitterDate: Tue, 25 Mar 2025 09:53:44 +01:00

tools/x86/kcpuid: Exit the program on invalid parameters

If the user passed an invalid CPUID index value through --leaf=index,
kcpuid prints a warning, does nothing, then exits successfully.
Transform the warning to an error, and exit the program with a proper
error code.

Similarly, if the user passed an invalid subleaf, kcpuid prints a
warning, dumps the whole leaf, then exits successfully.  Print a clear
error message regarding the invalid subleaf and exit the program with the
proper error code.

Note, moving the "Invalid input index" message from index_to_func() to
show_info() localizes error message handling to the latter, where it
should be.  It also allows index_to_func() to be refactored at further
commits.

Note, since after this commit and its parent kcpuid does not just "move
on" on failures, remove the NULL parameter check plus silent exit at
show_func() and show_leaf().

Signed-off-by: Ahmed S. Darwish <darwi@...utronix.de>
Signed-off-by: Ingo Molnar <mingo@...nel.org>
Cc: H. Peter Anvin <hpa@...or.com>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Josh Poimboeuf <jpoimboe@...hat.com>
Link: https://lore.kernel.org/r/20250324142042.29010-3-darwi@linutronix.de
---
 tools/arch/x86/kcpuid/kcpuid.c | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/tools/arch/x86/kcpuid/kcpuid.c b/tools/arch/x86/kcpuid/kcpuid.c
index 40a9e59..25b10fe 100644
--- a/tools/arch/x86/kcpuid/kcpuid.c
+++ b/tools/arch/x86/kcpuid/kcpuid.c
@@ -481,9 +481,6 @@ static void decode_bits(u32 value, struct reg_desc *rdesc, enum cpuid_reg reg)
 
 static void show_leaf(struct subleaf *leaf)
 {
-	if (!leaf)
-		return;
-
 	if (show_raw) {
 		leaf_print_raw(leaf);
 	} else {
@@ -505,9 +502,6 @@ static void show_func(struct cpuid_func *func)
 {
 	int i;
 
-	if (!func)
-		return;
-
 	for (i = 0; i < func->nr; i++)
 		show_leaf(&func->leafs[i]);
 }
@@ -528,10 +522,9 @@ static inline struct cpuid_func *index_to_func(u32 index)
 	range = (index & 0x80000000) ? leafs_ext : leafs_basic;
 	func_idx = index & 0xffff;
 
-	if ((func_idx + 1) > (u32)range->nr) {
-		warnx("Invalid input index (0x%x)", index);
+	if ((func_idx + 1) > (u32)range->nr)
 		return NULL;
-	}
+
 	return &range->funcs[func_idx];
 }
 
@@ -550,18 +543,19 @@ static void show_info(void)
 		/* Only show specific leaf/subleaf info */
 		func = index_to_func(user_index);
 		if (!func)
-			return;
+			errx(EXIT_FAILURE, "Invalid input leaf (0x%x)", user_index);
 
 		/* Dump the raw data also */
 		show_raw = true;
 
 		if (user_sub != 0xFFFFFFFF) {
-			if (user_sub + 1 <= (u32)func->nr) {
-				show_leaf(&func->leafs[user_sub]);
-				return;
+			if (user_sub + 1 > (u32)func->nr) {
+				errx(EXIT_FAILURE, "Leaf 0x%x has no valid subleaf = 0x%x",
+				     user_index, user_sub);
 			}
 
-			warnx("Invalid input subleaf (0x%x)", user_sub);
+			show_leaf(&func->leafs[user_sub]);
+			return;
 		}
 
 		show_func(func);

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ