Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752346AbdGFKic (ORCPT ); Thu, 6 Jul 2017 06:38:32 -0400 Received: from mailapp01.imgtec.com ([195.59.15.196]:50639 "EHLO mailapp01.imgtec.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752219AbdGFKia (ORCPT ); Thu, 6 Jul 2017 06:38:30 -0400 From: Matt Redfearn To: Petr Mladek , Sergey Senozhatsky , Greg Kroah-Hartman , Jiri Slaby CC: , Matt Redfearn , Subject: [PATCH 2/2] serial: earlycon: Make early_con as __initdata Date: Thu, 6 Jul 2017 11:38:01 +0100 Message-ID: <1499337481-19397-2-git-send-email-matt.redfearn@imgtec.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1499337481-19397-1-git-send-email-matt.redfearn@imgtec.com> References: <1499337481-19397-1-git-send-email-matt.redfearn@imgtec.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.150.130.83] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1880 Lines: 49 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 --- 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 -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