summaryrefslogtreecommitdiffstats
path: root/kernel/printk
diff options
context:
space:
mode:
authorTony Lindgren <tony@atomide.com>2023-10-12 09:42:56 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-10-17 10:18:59 +0200
commit545a4f89cad5bd349522d17558b3a4208648e20e (patch)
treed4b4055f77c23696ead18417a1671a6b8d932251 /kernel/printk
parenta07b50d80ab621f4f18d429068a43cffec26691f (diff)
downloadlinux-545a4f89cad5bd349522d17558b3a4208648e20e.tar.gz
linux-545a4f89cad5bd349522d17558b3a4208648e20e.tar.bz2
linux-545a4f89cad5bd349522d17558b3a4208648e20e.zip
printk: Check valid console index for preferred console
Let's check for valid console index values for preferred console to avoid bogus console index numbers from kernel command line. Let's also return an error for negative index numbers for the preferred console. Unlike for device drivers, a negative index is not valid for the preferred console. Let's also constify idx while at it. Signed-off-by: Tony Lindgren <tony@atomide.com> Link: https://lore.kernel.org/r/20231012064300.50221-1-tony@atomide.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'kernel/printk')
-rw-r--r--kernel/printk/printk.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 0b3af1529778..b16c0bab88c6 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2404,13 +2404,21 @@ static void set_user_specified(struct console_cmdline *c, bool user_specified)
console_set_on_cmdline = 1;
}
-static int __add_preferred_console(char *name, int idx, char *options,
+static int __add_preferred_console(char *name, const short idx, char *options,
char *brl_options, bool user_specified)
{
struct console_cmdline *c;
int i;
/*
+ * We use a signed short index for struct console for device drivers to
+ * indicate a not yet assigned index or port. However, a negative index
+ * value is not valid for preferred console.
+ */
+ if (idx < 0)
+ return -EINVAL;
+
+ /*
* See if this tty is not yet registered, and
* if we have a slot free.
*/
@@ -2513,7 +2521,7 @@ __setup("console=", console_setup);
* commonly to provide a default console (ie from PROM variables) when
* the user has not supplied one.
*/
-int add_preferred_console(char *name, int idx, char *options)
+int add_preferred_console(char *name, const short idx, char *options)
{
return __add_preferred_console(name, idx, options, NULL, false);
}