Received: by 10.192.165.148 with SMTP id m20csp4157765imm; Mon, 30 Apr 2018 12:52:50 -0700 (PDT) X-Google-Smtp-Source: AB8JxZp4bfGadw5Ty+5ndFxeThwPGGt6K38A9WmQ3viZPbU8Zjb5M+SYaQPMXFiChthd9eKAonIO X-Received: by 2002:a63:3701:: with SMTP id e1-v6mr10852333pga.237.1525117970898; Mon, 30 Apr 2018 12:52:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525117970; cv=none; d=google.com; s=arc-20160816; b=SiPB3+4yyFhBOj79WxOxq9gQLIGD/tF5ulFpxDlSGw2+HiJqgvNgxVD1cgyDiIybEi Z5O9eQEA+VECZvs5IzGXb7FoNAScV8b1aZSGWeN4oCkHs3pPECBg8Nk/w/Sbomt8g8rw r7zf0zifDUdqi1U1GcmFy0L8N8jXPWHPDonN4IpBh6L6CV3u9jzy+yW/Rf1oaj+QZlfn 0VF3G2UpmI/tp+4IU1eH/CGV5tuArkv2+r62GgsXNfoYakdsJTrGwf1PfQj+Uy2qGp3x fkzPVI+UYKwMc6sKcflUyl7abLQZBcisFrV19pirvSvo2hZijLiH+Vmh5BoAS912uQhf o3pw== 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=LAOXkOdbAVuQ3uoYzodTFfllowpOstsTPg6lKgubdaY=; b=v/hGgt+xiCIPikdUzNd46Fa8KW6cX6HItYgzKtCXfgFxqkpRKLa7TL5qdc7LJ6rETp BaPWSHE6qIYA/ggVt7rOOVJ5uXZU/x73sNGhFbtocn93jANsKj3flOK5E2ib18KoJnqh rtXYP1+4kUwaN3qFOB6S8pfWj7s00DhqM3bFZwkigMAAKa/IvgsyT63X98H27z8QhONX FLStjFXm6kS7eE1emkmk8Jhi/8FQoVkLrtwv0L93RkQzHR8TNQ889ng5rZIcPrcDRA2l ynf+ApIkgK9w3xLjdWg4R8NMbe9ww87NfwBHwCUohRtdpz9XLJEQlJASVY2UfKSPrN/X WLsw== 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 v2-v6si6543381pgf.75.2018.04.30.12.52.36; Mon, 30 Apr 2018 12:52:50 -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 S1756278AbeD3Tuj (ORCPT + 99 others); Mon, 30 Apr 2018 15:50:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:35424 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756192AbeD3T2H (ORCPT ); Mon, 30 Apr 2018 15:28:07 -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 4B3A322DCB; Mon, 30 Apr 2018 19:28:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4B3A322DCB 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.16 031/113] tty: Dont call panic() at tty_ldisc_init() Date: Mon, 30 Apr 2018 12:24:02 -0700 Message-Id: <20180430184016.382970214@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430184015.043892819@linuxfoundation.org> References: <20180430184015.043892819@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.16-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 @@ -2816,7 +2816,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 @@ -824,12 +824,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);