Skip to contentSkip to conversation

lib/vsprintf: Require exact hash_pointers mode matches

PATCH In review Kaitao Cheng 2 participants 3 messages May 19 – May 26

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/vsprintf: Require exact hash_pointers mode matches

From: Kaitao Cheng <[email protected]>

hash_pointers= accepts a small set of mode strings, but the parser uses strncmp() with the length of each valid mode. That accepts values with trailing garbage, such as hash_pointers=autobots or hash_pointers=nevermind, as valid aliases for auto and never.

Use strcmp() so that only the documented mode strings are accepted. Invalid values will continue to fall back to auto through the existing unknown-mode path.

---
 lib/vsprintf.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/vsprintf.c +3 -3
index 9ca676feb8eb..03e87b933fd0 100644
@@ -2354,13 +2354,13 @@ static int __init hash_pointers_mode_parse(char *str)
 	if (!str) {
 		pr_warn("Hash pointers mode empty; falling back to auto.\n");
 		hash_pointers_mode = HASH_PTR_AUTO;
-	} else if (strncmp(str, "auto", 4) == 0)   {
+	} else if (strcmp(str, "auto") == 0) {
 		pr_info("Hash pointers mode set to auto.\n");
 		hash_pointers_mode = HASH_PTR_AUTO;
-	} else if (strncmp(str, "never", 5) == 0) {
+	} else if (strcmp(str, "never") == 0) {
 		pr_info("Hash pointers mode set to never.\n");
 		hash_pointers_mode = HASH_PTR_NEVER;
-	} else if (strncmp(str, "always", 6) == 0) {
+	} else if (strcmp(str, "always") == 0) {
 		pr_info("Hash pointers mode set to always.\n");
 		hash_pointers_mode = HASH_PTR_ALWAYS;
 	} else {
Signature · 1 line
2.50.1 (Apple Git-155)
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Kaitao Cheng

From: Kaitao Cheng <[email protected]>

hash_pointers= accepts a small set of mode strings, but the parser uses strncmp() with the length of each valid mode. That accepts values with trailing garbage, such as hash_pointers=autobots or hash_pointers=nevermind, as valid aliases for auto and never.

Quoted 5 lines

Use strcmp() so that only the documented mode strings are accepted. Invalid values will continue to fall back to auto through the existing unknown-mode path.

LGTM:

I am going to queue this patch via the printk tree early next week unless anyone complains in the meantime.

Best Regards,
Petr

maintainer
#2 lore raw
In reply to Kaitao Cheng
Quoted 7 lines · Kaitao Cheng

From: Kaitao Cheng <[email protected]>

hash_pointers= accepts a small set of mode strings, but the parser uses strncmp() with the length of each valid mode. That accepts values with trailing garbage, such as hash_pointers=autobots or hash_pointers=nevermind, as valid aliases for auto and never.

Quoted 5 lines

Use strcmp() so that only the documented mode strings are accepted. Invalid values will continue to fall back to auto through the existing unknown-mode path.

JFYI, the patch has been committed into printk/linux.git, branch for-7.2.

Best Regards,
Petr