linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matt Redfearn <matt.redfearn@imgtec.com>
To: Petr Mladek <pmladek@suse.com>,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiri Slaby <jslaby@suse.com>
Cc: linux-serial@vger.kernel.org,
	Matt Redfearn <matt.redfearn@imgtec.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] serial: earlycon: Make early_con as __initdata
Date: Thu, 6 Jul 2017 11:38:01 +0100	[thread overview]
Message-ID: <1499337481-19397-2-git-send-email-matt.redfearn@imgtec.com> (raw)
In-Reply-To: <1499337481-19397-1-git-send-email-matt.redfearn@imgtec.com>

All early console drivers that may be registered as the earlycon are
marked __init to be placed in the init section. The drivers' code and
data are freed during free_initmem_default() but the early console is
not unregistered in printk_late_init() as the init_section_intersects()
test fails. This leads to the earlycon still being active, potentially
with dangling pointers into the freed init section, which may have been
poisoned by the slab debugger. Attempting to use the boot console after
this will likely lead to weird behaviour and kernel crashes.

Fix this by marking the early_con struct __initdata so that the
init_section_intersects() test succeeds and the console is unregistered
in printk_late_init() before the init section is freed.

The 8250 earlycon, on which the generic earlycon was based, had these
attributes on it's console struct. The switch to the generic
implementation in commit d2fd6810a823 ("tty/serial: convert 8250 to
generic earlycon") appears to have broken unregistraton of the boot
console when its code and data are in __init.

Fixes: d2fd6810a823 ("tty/serial: convert 8250 to generic earlycon")
Signed-off-by: Matt Redfearn <matt.redfearn@imgtec.com>

---

 drivers/tty/serial/earlycon.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/earlycon.c b/drivers/tty/serial/earlycon.c
index c3651540e1ba..388aaafcca2b 100644
--- a/drivers/tty/serial/earlycon.c
+++ b/drivers/tty/serial/earlycon.c
@@ -29,13 +29,13 @@
 
 #include <asm/serial.h>
 
-static struct console early_con = {
+static struct console early_con __initdata = {
 	.name =		"uart",		/* fixed up at earlycon registration */
 	.flags =	CON_PRINTBUFFER | CON_BOOT,
 	.index =	0,
 };
 
-static struct earlycon_device early_console_dev = {
+static struct earlycon_device early_console_dev __initdata = {
 	.con = &early_con,
 };
 
-- 
2.7.4

  reply	other threads:[~2017-07-06 10:38 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-06 10:38 [PATCH 1/2] printk: Unconditionally unregister boot consoles if in init section Matt Redfearn
2017-07-06 10:38 ` Matt Redfearn [this message]
2017-07-07  4:47   ` [PATCH 2/2] serial: earlycon: Make early_con as __initdata Sergey Senozhatsky
2017-07-07  4:45 ` [PATCH 1/2] printk: Unconditionally unregister boot consoles if in init section Sergey Senozhatsky
2017-07-07  7:58   ` Matt Redfearn
2017-07-11 12:43     ` Petr Mladek
2017-07-11 14:41       ` Matt Redfearn
2017-07-12 11:11         ` Petr Mladek
2017-07-14 12:40           ` Petr Mladek
2017-07-14 13:58             ` Matt Redfearn
2017-07-14 21:54       ` Sergey Senozhatsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1499337481-19397-2-git-send-email-matt.redfearn@imgtec.com \
    --to=matt.redfearn@imgtec.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jslaby@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=pmladek@suse.com \
    --cc=sergey.senozhatsky@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).