]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
proc: sysctl: prevent aliased sysctls from getting passed to init
authorKrister Johansen <kjlx@templeofstupid.com>
Fri, 27 Oct 2023 21:46:40 +0000 (14:46 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 3 Dec 2023 06:31:24 +0000 (07:31 +0100)
commit 8001f49394e353f035306a45bcf504f06fca6355 upstream.

The code that checks for unknown boot options is unaware of the sysctl
alias facility, which maps bootparams to sysctl values.  If a user sets
an old value that has a valid alias, a message about an invalid
parameter will be printed during boot, and the parameter will get passed
to init.  Fix by checking for the existence of aliased parameters in the
unknown boot parameter code.  If an alias exists, don't return an error
or pass the value to init.

Signed-off-by: Krister Johansen <kjlx@templeofstupid.com>
Cc: stable@vger.kernel.org
Fixes: 0a477e1ae21b ("kernel/sysctl: support handling command line aliases")
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
Signed-off-by: Krister Johansen <kjlx@templeofstupid.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/proc/proc_sysctl.c
include/linux/sysctl.h
init/main.c

index caa421ba078fe04f2b77128ef608f88d9d3e6e4b..4192fe6ec3da29025aa8c2a9619234b581cb103d 100644 (file)
@@ -1780,6 +1780,13 @@ static const char *sysctl_find_alias(char *param)
        return NULL;
 }
 
+bool sysctl_is_alias(char *param)
+{
+       const char *alias = sysctl_find_alias(param);
+
+       return alias != NULL;
+}
+
 /* Set sysctl value passed on kernel command line. */
 static int process_sysctl_arg(char *param, char *val,
                               const char *unused, void *arg)
index 47cf70c8eb93c8b3d22f21c37355e2e435faaae5..32d79ef906e511f7035be43839bb3c5bbebbe27e 100644 (file)
@@ -210,6 +210,7 @@ extern void __register_sysctl_init(const char *path, struct ctl_table *table,
                                 const char *table_name);
 #define register_sysctl_init(path, table) __register_sysctl_init(path, table, #table)
 void do_sysctl_args(void);
+bool sysctl_is_alias(char *param);
 
 extern int pwrsw_enabled;
 extern int unaligned_enabled;
@@ -251,6 +252,11 @@ static inline void setup_sysctl_set(struct ctl_table_set *p,
 static inline void do_sysctl_args(void)
 {
 }
+
+static inline bool sysctl_is_alias(char *param)
+{
+       return false;
+}
 #endif /* CONFIG_SYSCTL */
 
 int sysctl_max_threads(struct ctl_table *table, int write, void *buffer,
index 63737af8de51e4834c74f43db9213504f6cabc75..5c81d7fb2fe9c86aa679c878885406e33e377271 100644 (file)
@@ -540,6 +540,10 @@ static int __init unknown_bootoption(char *param, char *val,
 {
        size_t len = strlen(param);
 
+       /* Handle params aliased to sysctls */
+       if (sysctl_is_alias(param))
+               return 0;
+
        repair_env_string(param, val);
 
        /* Handle obsolete-style parameters */