]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
lib/vsprintf: Require exact hash_pointers mode matches
authorKaitao Cheng <chengkaitao@kylinos.cn>
Tue, 19 May 2026 13:01:17 +0000 (21:01 +0800)
committerPetr Mladek <pmladek@suse.com>
Tue, 26 May 2026 09:06:12 +0000 (11:06 +0200)
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.

Signed-off-by: Kaitao Cheng <chengkaitao@kylinos.cn>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Link: https://patch.msgid.link/20260519130117.48097-1-kaitao.cheng@linux.dev
Signed-off-by: Petr Mladek <pmladek@suse.com>
lib/vsprintf.c

index d700dd0a52610f6f827bfc7fd1d2203ed428113d..90b267b59254ae8e1f162f2f93521315dce647d0 100644 (file)
@@ -2362,13 +2362,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 {