Received: by 10.192.165.148 with SMTP id m20csp4169205imm; Mon, 30 Apr 2018 13:05:37 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo+e/WXRSCEXy4t+LNPaQgGWzFqlVFO3I4llUcD+e2a5hE9nuotkJaOalq8iZmyk5nZ7t53 X-Received: by 2002:a63:bd52:: with SMTP id d18-v6mr11186778pgp.311.1525118737659; Mon, 30 Apr 2018 13:05:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525118737; cv=none; d=google.com; s=arc-20160816; b=kuv8SFf7fyjxlN82tuE6IMVNl7CSWWCx/MIGklD5vl7IyWNjQ1SkRC3a1aMe9b2/JJ ANBQcVzZNZQ1AFxzclvUGI+x1o8MamOQ89LoL1Y/gmWymez/4k2BF4NsfGi+q8BCWwIJ al/HUhQkJmeXeoXa5ZkudNTCYlMjF5eYvDfUcO38GWiUJ35sxxoAauW8ZXH5/LOwRLDr AwnN6DlQiGWnbyIX7sdxBYNl3pmB8UAQcyWmx4JKEpzmdsG85rFQpylL8mAGbWFmB2Hg OilTtSYVbafnw0ps6yYLrt7iJ3bxV84NWdsfvLLGZUU3bekoXjt15jP7UWdrjSPrtuoC 7RSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dmarc-filter :arc-authentication-results; bh=giQk4he6JYDw2Xz3HIlcXIve1fG/+S2q09Qz07Lemx8=; b=u4e91197kIKxV5X5J0BciHnuKPw0/Dpu3fqVgzzP/FPL9ggwb+DjLF6U9OVSCDQ1yT WgiDw6qAZdtBZP5TYRx/jxW8xmsaxUnnbZMG8q3eJhe/QSYXXeEscecFJu7sOwFX/cMz S4/xvh7885ugz0jOFcFJQp/7zNyM5U1P4eBkJJIyPQGhBSn5jKhDn0Ylghz7tKXGwiP6 vCXJnbfgLiHD5m8XJpM0q730/hyaqGnhN4Rc+h+LQA2P1vuM11CWZPRYbNtOWcKkA/UL TJJ2UsUaIgLVM6PBsDvJCBSFLo/bisYAX+gVsLsL49caQbmO6sjSQZrUOP1zxfR3GO98 pvjQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l188si8513256pfc.266.2018.04.30.13.05.23; Mon, 30 Apr 2018 13:05:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756054AbeD3UFO (ORCPT + 99 others); Mon, 30 Apr 2018 16:05:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:34060 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755962AbeD3T1a (ORCPT ); Mon, 30 Apr 2018 15:27:30 -0400 Received: from localhost (unknown [104.132.1.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5573122DCB; Mon, 30 Apr 2018 19:27:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5573122DCB Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: mail.kernel.org; spf=fail smtp.mailfrom=gregkh@linuxfoundation.org From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tetsuo Handa , syzbot , Jiri Slaby Subject: [PATCH 4.14 29/91] tty: Dont call panic() at tty_ldisc_init() Date: Mon, 30 Apr 2018 12:24:11 -0700 Message-Id: <20180430184005.696407137@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430184004.216234025@linuxfoundation.org> References: <20180430184004.216234025@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tetsuo Handa commit 903f9db10f18f735e62ba447147b6c434b6af003 upstream. syzbot is reporting kernel panic [1] triggered by memory allocation failure at tty_ldisc_get() from tty_ldisc_init(). But since both tty_ldisc_get() and caller of tty_ldisc_init() can cleanly handle errors, tty_ldisc_init() does not need to call panic() when tty_ldisc_get() failed. [1] https://syzkaller.appspot.com/bug?id=883431818e036ae6a9981156a64b821110f39187 Signed-off-by: Tetsuo Handa Reported-by: syzbot Cc: Greg Kroah-Hartman Cc: Jiri Slaby Cc: stable Signed-off-by: Greg Kroah-Hartman --- drivers/tty/tty_io.c | 5 ++++- drivers/tty/tty_ldisc.c | 5 +++-- include/linux/tty.h | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -2815,7 +2815,10 @@ struct tty_struct *alloc_tty_struct(stru kref_init(&tty->kref); tty->magic = TTY_MAGIC; - tty_ldisc_init(tty); + if (tty_ldisc_init(tty)) { + kfree(tty); + return NULL; + } tty->session = NULL; tty->pgrp = NULL; mutex_init(&tty->legacy_mutex); --- a/drivers/tty/tty_ldisc.c +++ b/drivers/tty/tty_ldisc.c @@ -823,12 +823,13 @@ EXPORT_SYMBOL_GPL(tty_ldisc_release); * the tty structure is not completely set up when this call is made. */ -void tty_ldisc_init(struct tty_struct *tty) +int tty_ldisc_init(struct tty_struct *tty) { struct tty_ldisc *ld = tty_ldisc_get(tty, N_TTY); if (IS_ERR(ld)) - panic("n_tty: init_tty"); + return PTR_ERR(ld); tty->ldisc = ld; + return 0; } /** --- a/include/linux/tty.h +++ b/include/linux/tty.h @@ -701,7 +701,7 @@ extern int tty_unregister_ldisc(int disc extern int tty_set_ldisc(struct tty_struct *tty, int disc); extern int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty); extern void tty_ldisc_release(struct tty_struct *tty); -extern void tty_ldisc_init(struct tty_struct *tty); +extern int __must_check tty_ldisc_init(struct tty_struct *tty); extern void tty_ldisc_deinit(struct tty_struct *tty); extern int tty_ldisc_receive_buf(struct tty_ldisc *ld, const unsigned char *p, char *f, int count);