Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756612Ab2HGUBk (ORCPT ); Tue, 7 Aug 2012 16:01:40 -0400 Received: from mail.pripojeni.net ([178.22.112.14]:36551 "EHLO smtp.pripojeni.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756499Ab2HGT7q (ORCPT ); Tue, 7 Aug 2012 15:59:46 -0400 From: Jiri Slaby To: gregkh@linuxfoundation.org Cc: alan@linux.intel.com, linux-kernel@vger.kernel.org, jirislaby@gmail.com, Samo Pogacnik Subject: [PATCH 13/41] TTY: ttyprintk, unregister tty driver on failure Date: Tue, 7 Aug 2012 21:47:38 +0200 Message-Id: <1344368886-24033-14-git-send-email-jslaby@suse.cz> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1344368886-24033-1-git-send-email-jslaby@suse.cz> References: <1344368886-24033-1-git-send-email-jslaby@suse.cz> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3272 Lines: 78 When the tty_printk driver fails to create a node in sysfs, the system crashes. It is because the driver registers a tty driver and frees it without deregistering it first. The fix is easy: add a call to tty_unregister_driver to the fail path. This is very unlikely to happen in usual environment => no need for stable. The crash occurs at some place where we iterate over tty drivers first. It may look like this: BUG: unable to handle kernel paging request at ffffffffffffff84 IP: [] tty_open+0xd6/0x650 PGD 1a0d067 PUD 1a0e067 PMD 0 Oops: 0000 [#1] PREEMPT SMP Modules linked in: CPU 0 Pid: 1183, comm: boot.localnet Tainted: G W 3.5.0-rc7-next-20120716+ #369 Bochs Bochs RIP: 0010:[] [] tty_open+0xd6/0x650 RSP: 0018:ffff8800162b3b98 EFLAGS: 00010207 RAX: 0000000000000000 RBX: ffff880016ba6200 RCX: 0000000000002208 RDX: 0000000000000000 RSI: 00000000000000d0 RDI: ffffffff81a35080 RBP: ffff8800162b3c08 R08: ffffffff81276f42 R09: 0000000000400040 R10: ffff8800161dc005 R11: ffff8800188ee048 R12: 0000000000000000 R13: ffffffffffffff58 R14: 0000000000400040 R15: 0000000000008000 FS: 00007f3684abd700(0000) GS:ffff880018e00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: ffffffffffffff84 CR3: 000000001503e000 CR4: 00000000000006f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 Process boot.localnet (pid: 1183, threadinfo ffff8800162b2000, task ffff8800188c5880) Stack: ffff8800162b3c08 ffffffff81363d63 ffffffff81a62940 ffff8800189b4e88 ffff8800188c5880 ffffffff81123180 0000000000000000 ffffffff18b20600 0000000000000000 ffff8800189b4e88 ffff880016ba6200 ffff880018b20600 Call Trace: [] ? kobj_lookup+0x103/0x160 [] ? mount_fs+0x110/0x110 [] chrdev_open+0x9c/0x1a0 [] ? cdev_put+0x30/0x30 [] do_dentry_open.isra.19+0x1e6/0x270 [] finish_open+0x65/0xa0 [] do_last.isra.52+0x26e/0xd80 [] ? inode_permission+0x13/0x50 [] ? link_path_walk+0x63/0x940 [] path_openat+0xab/0x3d0 [] do_filp_open+0x3d/0xa0 [] ? alloc_fd+0xd2/0x120 [] do_sys_open+0xf3/0x1d0 [] sys_open+0x1c/0x20 [] system_call_fastpath+0x16/0x1b Signed-off-by: Jiri Slaby Cc: Samo Pogacnik --- drivers/char/ttyprintk.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/char/ttyprintk.c b/drivers/char/ttyprintk.c index 46b77ed..9b1e5e0 100644 --- a/drivers/char/ttyprintk.c +++ b/drivers/char/ttyprintk.c @@ -217,6 +217,7 @@ static int __init ttyprintk_init(void) return 0; error: + tty_unregister_driver(ttyprintk_driver); put_tty_driver(ttyprintk_driver); ttyprintk_driver = NULL; return ret; -- 1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/