2007-08-20 02:46:17

by Robin Getz

[permalink] [raw]
Subject: [PATCH 1/1] ensure we don't use bootconsoles after init has been released

From: Robin Getz <[email protected]>

This is a followup to the cleanups for earlyprintk patch from Gerd Hoffmann

http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=69331af79cf29e26d1231152a172a1a10c2df511

This ensures that a bootconsole is unregistered if it is not replaced.
The current implementation spews garbage out the bootconsole in this case,
since the bootconsole structure is normally in the init section, and is
freed, but still used.

Signed-off-by: Robin Getz <[email protected]>

---
linux-2.6.x/kernel/printk.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)


Index: linux-2.6.x/kernel/printk.c
===================================================================
--- linux-2.6.x/kernel/printk.c
+++ linux-2.6.x/kernel/printk.c
@@ -1104,6 +1104,20 @@
}
EXPORT_SYMBOL(unregister_console);

+static int __init disable_boot_consoles(void)
+{
+ struct console *con;
+
+ for (con = console_drivers; con; con = con->next) {
+ if (con->flags & CON_BOOT) {
+ printk(KERN_INFO "Turn off boot console %s%d\n",
+ con->name, con->index);
+ unregister_console(con);
+ }
+ }
+}
+late_initcall(disable_boot_consoles);
+
/**
* tty_write_message - write a message to a certain tty, not just the console.
* @tty: the destination tty_struct


2007-08-20 03:11:59

by Mike Frysinger

[permalink] [raw]
Subject: Re: [PATCH 1/1] ensure we don't use bootconsoles after init has been released

On 8/19/07, Robin Getz <[email protected]> wrote:
> +static int __init disable_boot_consoles(void)
> +{
> + struct console *con;
> +
> + for (con = console_drivers; con; con = con->next) {
> + if (con->flags & CON_BOOT) {
> + printk(KERN_INFO "Turn off boot console %s%d\n",
> + con->name, con->index);
> + unregister_console(con);
> + }
> + }
> +}

erp, no 'return 0;' ... that'll earn you a warning at build time and
maybe random failures depending on the arch ...
-mike

2007-08-20 03:33:09

by Paul Mundt

[permalink] [raw]
Subject: Re: [PATCH 1/1] ensure we don't use bootconsoles after init has been released

On Sun, Aug 19, 2007 at 11:11:47PM -0400, Mike Frysinger wrote:
> On 8/19/07, Robin Getz <[email protected]> wrote:
> > +static int __init disable_boot_consoles(void)
> > +{
> > + struct console *con;
> > +
> > + for (con = console_drivers; con; con = con->next) {
> > + if (con->flags & CON_BOOT) {
> > + printk(KERN_INFO "Turn off boot console %s%d\n",
> > + con->name, con->index);
> > + unregister_console(con);
> > + }
> > + }
> > +}
>
> erp, no 'return 0;' ... that'll earn you a warning at build time and
> maybe random failures depending on the arch ...

Or better yet, complain if unregister_console() fails, and pass the
failure down.

2007-08-20 04:08:54

by Robin Getz

[permalink] [raw]
Subject: Re: [PATCH 1/1] ensure we don't use bootconsoles after init has been released

From: Robin Getz <[email protected]>

This is a followup to the cleanups for earlyprintk patch from Gerd Hoffmann

http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=69331af79cf29e26d1231152a172a1a10c2df511

This ensures that a bootconsole is unregistered if it is not replaced.
The current implementation spews garbage out the bootconsole in this case,
since the bootconsole structure is normally in the init section, and is
freed, but still used.

Signed-off-by: Robin Getz <[email protected]>

---

linux-2.6.x-old/kernel/printk.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)

Index: linux-2.6.x-old/kernel/printk.c
===================================================================
--- linux-2.6.x-old/kernel/printk.c (revision 3583)
+++ linux-2.6.x-old/kernel/printk.c (working copy)
@@ -1104,6 +1104,21 @@
}
EXPORT_SYMBOL(unregister_console);

+static int __init disable_boot_consoles(void)
+{
+ struct console *con;
+
+ for (con = console_drivers; con; con = con->next) {
+ if (con->flags & CON_BOOT) {
+ printk(KERN_INFO "Turn off boot console %s%d\n",
+ con->name, con->index);
+ unregister_console(con);
+ }
+ }
+ return 0;
+}
+late_initcall(disable_boot_consoles);
+
/**
* tty_write_message - write a message to a certain tty, not just the console.
* @tty: the destination tty_struct

2007-08-20 17:15:12

by Robin Getz

[permalink] [raw]
Subject: Re: [PATCH 1/1] ensure we don't use bootconsoles after init has been released

Try #3...

From: Robin Getz <[email protected]>

This is a followup to the cleanups for earlyprintk patch from Gerd Hoffmann

http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=69331af79cf29e26d1231152a172a1a10c2df511

This ensures that a bootconsole is unregistered if it is not replaced.
The current implementation spews garbage out the bootconsole in this case,
since the bootconsole structure is normally in the init section, and is
freed, but still used.

Signed-off-by: Robin Getz <[email protected]>
CC: Gerd Hoffmann <[email protected]>
CC: Paul Mundt <[email protected]>
CC: Mike Frysinger <[email protected]>
---
printk.c | 13 +++++++++++++
1 file changed, 13 insertions(+)


Index: linux-2.6.x/kernel/printk.c
===================================================================
--- linux-2.6.x/kernel/printk.c
+++ linux-2.6.x/kernel/printk.c
@@ -1104,6 +1104,19 @@
}
EXPORT_SYMBOL(unregister_console);

+static int __init disable_boot_consoles(void)
+{
+ printk(KERN_INFO "here\n");
+
+ if (console_drivers->flags & CON_BOOT) {
+ printk(KERN_INFO "turn off boot console %s%d\n",
+ console_drivers->name, console_drivers->index);
+ return unregister_console(console_drivers);
+ }
+ return 0;
+}
+late_initcall(disable_boot_consoles);
+
/**
* tty_write_message - write a message to a certain tty, not just the console.
* @tty: the destination tty_struct

2007-08-20 19:07:35

by Gerd Hoffmann

[permalink] [raw]
Subject: Re: [PATCH 1/1] ensure we don't use bootconsoles after init has been released

Robin Getz wrote:
> Try #3...
>
> From: Robin Getz <[email protected]>
> +static int __init disable_boot_consoles(void)
> +{
> + printk(KERN_INFO "here\n");

leftover debug printk?

cheers,
Gerd


2007-08-20 19:22:59

by Robin Getz

[permalink] [raw]
Subject: Re: [PATCH 1/1] ensure we don't use bootconsoles after init has been released

Try #4... (sorry)

From: Robin Getz <[email protected]>

This is a followup to the cleanups for earlyprintk patch from Gerd Hoffmann

http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=69331af79cf29e26d1231152a172a1a10c2df511

This ensures that a bootconsole is unregistered if it is not replaced.
The current implementation spews garbage out the bootconsole in this case,
since the bootconsole structure is normally in the init section, and is
freed, but still used.

Signed-off-by: Robin Getz <[email protected]>
CC: Gerd Hoffmann <[email protected]>
CC: Paul Mundt <[email protected]>
CC: Mike Frysinger <[email protected]>
---

kernel/printk.c | 11 +++++++++++
1 file changed, 11 insertions(+)

Index: linux-2.6.x/kernel/printk.c
===================================================================
--- linux-2.6.x/kernel/printk.c (revision 3583)
+++ linux-2.6.x/kernel/printk.c (working copy)
@@ -1104,6 +1104,17 @@
}
EXPORT_SYMBOL(unregister_console);

+static int __init disable_boot_consoles(void)
+{
+ if (console_drivers->flags & CON_BOOT) {
+ printk(KERN_INFO "turn off boot console %s%d\n",
+ console_drivers->name, console_drivers->index);
+ return unregister_console(console_drivers);
+ }
+ return 0;
+}
+late_initcall(disable_boot_consoles);
+
/**
* tty_write_message - write a message to a certain tty, not just the console.
* @tty: the destination tty_struct

2007-08-20 19:27:26

by Gerd Hoffmann

[permalink] [raw]
Subject: Re: [PATCH 1/1] ensure we don't use bootconsoles after init has been released

Robin Getz wrote:
> This ensures that a bootconsole is unregistered if it is not replaced.
> The current implementation spews garbage out the bootconsole in this case,
> since the bootconsole structure is normally in the init section, and is
> freed, but still used.
>
> Signed-off-by: Robin Getz <[email protected]>
> CC: Gerd Hoffmann <[email protected]>

Acked-by: Gerd Hoffmann <[email protected]>

cheers,
Gerd

2007-08-20 22:49:26

by Paul Mundt

[permalink] [raw]
Subject: Re: [PATCH 1/1] ensure we don't use bootconsoles after init has been released

On Mon, Aug 20, 2007 at 03:22:47PM -0400, Robin Getz wrote:
> Try #4... (sorry)
>
> From: Robin Getz <[email protected]>
>
> This is a followup to the cleanups for earlyprintk patch from Gerd Hoffmann
>
> http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=69331af79cf29e26d1231152a172a1a10c2df511
>
> This ensures that a bootconsole is unregistered if it is not replaced.
> The current implementation spews garbage out the bootconsole in this case,
> since the bootconsole structure is normally in the init section, and is
> freed, but still used.
>
> Signed-off-by: Robin Getz <[email protected]>
> CC: Gerd Hoffmann <[email protected]>
> CC: Paul Mundt <[email protected]>
> CC: Mike Frysinger <[email protected]>

Looks better, thanks.

Acked-by: Paul Mundt <[email protected]>

2007-08-22 03:15:06

by Robin Getz

[permalink] [raw]
Subject: [PATCH 1/1] fix - ensure we don't use bootconsoles after init has been released

From: Robin Getz <[email protected]>

Gerd Hoffmann pointed out that my patch from yesterday can lead
to a null pointer dereference if the kernel is booted with no
console, and no earlyprintk defined. This fixes that issue.

printk.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)

Signed-off-by: Robin Getz <[email protected]>

---

Index: linux-2.6.x/kernel/printk.c
===================================================================
--- linux-2.6.x/kernel/printk.c
+++ linux-2.6.x/kernel/printk.c
@@ -1106,10 +1106,12 @@

static int __init disable_boot_consoles(void)
{
- if (console_drivers->flags & CON_BOOT) {
- printk(KERN_INFO "turn off boot console %s%d\n",
- console_drivers->name, console_drivers->index);
- return unregister_console(console_drivers);
+ if (console_drivers != NULL) {
+ if (console_drivers->flags & CON_BOOT) {
+ printk(KERN_INFO "turn off boot console %s%d\n",
+ console_drivers->name, console_drivers->index);
+ return unregister_console(console_drivers);
+ }
}
return 0;
}