Received: by 10.192.165.148 with SMTP id m20csp4189455imm; Mon, 30 Apr 2018 13:30:34 -0700 (PDT) X-Google-Smtp-Source: AB8JxZocrYz+zvJMhVI9Q6tHuYKxS9mC3n1ESLEMcduU0FZ/YxSWe7fpjKvB6saEAtj5y8ENVUVP X-Received: by 2002:a63:2fc3:: with SMTP id v186-v6mr4177552pgv.42.1525120234902; Mon, 30 Apr 2018 13:30:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525120234; cv=none; d=google.com; s=arc-20160816; b=R6UUueX2j0NiXrr92rIcnvqhcDAQZlJ7IAX0KwgocQDOjk4vPHBuQ4YOrwP+6b9Ihn t09le39vI5p5+xTH3An61Duq7Ok/1JOJVmCh2CoXdWi7F9ri+Qo6ifnZu7UbbG6g7S1M K3oaYPIIQq2zRMD8QiI0VMecaRZITdtpexNkny7ORzBrpINQcjM5u1Hd2Fr/hNX8YdFI Tg1hta9yWfVrsqUNkOaLq1IGYuK/A9Yu4n/1dQR27Sbal7Aw9KmHvaPYl+AccI5wowXu h7tU2Qi6YFg+NGpnzyjEKFm91Eo1Z1qtBgAPW7NfJf5D23Re+aY6ndKTCm0BWpB3vnJs gs2Q== 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=gS9kPzm7EMYGvyX/eVlfKuQV0SjiLqMBua/mlqzqWkk=; b=Y5NK/1sC7Fwi5lgwremtKVN/7VugV6vtiGTaxUtAkgGj1k4VTTvJoMeS/FJD2RPaQ4 uFmSzsoDOCvYXLu0KiJh+SOzAuugmZ5X4GrR+zEOHLYD2Syx87AqjjSDb++MdXkOJmLw /KdtAV+UESEQ+k3Z8gepbtgxmFBCvCB6wYUd5XOOlflKK+69nmkX4q2/Zu3ZA51OU2ZN eAkKKePFAvjsFFpQsbRKGu8rg0eOaAi07NGqOxhbRJVhxrVzzc0yfJprmmBJ25xtaa+B Kbq1l2jcZ2GerqMrlF6tJBDp3CdnfuUwceCw6HwNtsCLPAKOT27h4lV48KwCgxV7oTPs OKdw== 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 e187-v6si6752184pgc.127.2018.04.30.13.30.20; Mon, 30 Apr 2018 13:30:34 -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 S1755578AbeD3T0S (ORCPT + 99 others); Mon, 30 Apr 2018 15:26:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:59628 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755562AbeD3T0P (ORCPT ); Mon, 30 Apr 2018 15:26:15 -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 8CED522DC0; Mon, 30 Apr 2018 19:26:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8CED522DC0 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.4 16/44] tty: Dont call panic() at tty_ldisc_init() Date: Mon, 30 Apr 2018 12:24:27 -0700 Message-Id: <20180430190946.991889911@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430190946.093694747@linuxfoundation.org> References: <20180430190946.093694747@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.4-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 @@ -3154,7 +3154,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 @@ -804,12 +804,13 @@ void tty_ldisc_release(struct tty_struct * 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 @@ -586,7 +586,7 @@ extern int tty_unregister_ldisc(int disc extern int tty_set_ldisc(struct tty_struct *tty, int ldisc); 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 void tty_ldisc_begin(void);