Received: by 10.192.165.148 with SMTP id m20csp4187831imm; Mon, 30 Apr 2018 13:28:48 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpqXIaGBXE6yi1ZuawX/iOEaolgNDEOFIgEYxWqVx5xCk1HD7dYtbg2s1iwc8Ii04oINLJf X-Received: by 2002:a17:902:5a88:: with SMTP id r8-v6mr13783475pli.78.1525120128942; Mon, 30 Apr 2018 13:28:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525120128; cv=none; d=google.com; s=arc-20160816; b=VwEjwxTG7oxgy6Wy88OqGZO+pdTByHCBpQxI7REof1jStKlUN8UO/jiHWKN7cO2GYb ce+WFZIlQY3bC1UykYc43SIInSwS2UELWgavbXIZEKfePnpicVf1ahnItn87WG8EmX6E fuMcTw4lfDzvmgO6OycaZiUNUO/2YE4cBoiBWvSLwMroSbqRkI4m4rqRu61ZJB6oEXnF 0VzeJHzMS5UnHUKD5p8NIRNos9/8QbbYPnsI0Jz8uN8jeHDTSvBaUT10SjZbxnsaa0zI KN69+VaW6BaduONzENJIX6LDgrntjJXgdlxeGv5610pDtzyzdXHa6CgWs9GTBdubIL3e jfvg== 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=HPWSTAAxc9Yssk+EU4HevgU1OcRbyHNTmjZ/JwHE6rk=; b=PbefolWj25epRC3WVzlMR/puW7nZKNpojCuQjNC8y8yCmVBXb9mAKmh/Kb17HPycS0 9QqYDZN6Ajr92Z4vpZMrfn2GySxxWsN/UE3f3ab5bCWBbQKhPSKV/UObl7JI15rS277G JmvWBEOFKNNAA2TPaXMqqUBXPXUs5/eURitwXe/59+kq1693R795sW3dPvjJKSpZeCqV 4k5+INNt9SxS+Wx7RT6o+y5HL6XkHa5s6B9R9mvixUJw3JqKdQrUxIjQ9kFDYrinV1Ym 8+AXbtMlb6Qr5HAL+FWD9l+bs0sbd6MMgPEvFX0vVioVdZ/JP7JRhJwuNHwUgiWx6lbx 4HoA== 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 p14-v6si5793891pli.250.2018.04.30.13.28.35; Mon, 30 Apr 2018 13:28:48 -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 S1755669AbeD3U2U (ORCPT + 99 others); Mon, 30 Apr 2018 16:28:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:59904 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755596AbeD3T0W (ORCPT ); Mon, 30 Apr 2018 15:26:22 -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 3750822DC1; Mon, 30 Apr 2018 19:26:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3750822DC1 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.9 20/61] tty: Dont call panic() at tty_ldisc_init() Date: Mon, 30 Apr 2018 12:24:23 -0700 Message-Id: <20180430183953.029803481@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430183951.312721450@linuxfoundation.org> References: <20180430183951.312721450@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.9-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 @@ -3170,7 +3170,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 @@ -753,12 +753,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 @@ -657,7 +657,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, unsigned char *p, char *f, int count);