printk: Check valid console index for preferred console

Message ID 20231004085434.42570-1-tony@atomide.com
State New
Headers
Series printk: Check valid console index for preferred console |

Commit Message

Tony Lindgren Oct. 4, 2023, 8:54 a.m. UTC
  Let's check for valid console index values.

Signed-off-by: Tony Lindgren <tony@atomide.com>
---
 kernel/printk/printk.c | 4 ++++
 1 file changed, 4 insertions(+)
  

Comments

Tony Lindgren Oct. 11, 2023, 7:34 a.m. UTC | #1
* Tony Lindgren <tony@atomide.com> [700101 02:00]:
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -2410,6 +2410,10 @@ static int __add_preferred_console(char *name, int idx, char *options,
>  	struct console_cmdline *c;
>  	int i;
>  
> +	/* See struct console */
> +	if (idx > SHRT_MAX)
> +		return -EINVAL;
> +

We can just use const short idx for preferred console and return an error
for negative values for preferred console. I'll send out v2 patch.

Regards,

Tony
  

Patch

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2410,6 +2410,10 @@  static int __add_preferred_console(char *name, int idx, char *options,
 	struct console_cmdline *c;
 	int i;
 
+	/* See struct console */
+	if (idx > SHRT_MAX)
+		return -EINVAL;
+
 	/*
 	 *	See if this tty is not yet registered, and
 	 *	if we have a slot free.