Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9042355pxu; Mon, 28 Dec 2020 05:13:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJxBwduKP5KeYTM7NLe9qT/6Un28cORGZ8V0TF2j5GzRX4QtQ2RbleeKIZbmlRhd+pRFEuCH X-Received: by 2002:aa7:c749:: with SMTP id c9mr42746921eds.3.1609161203686; Mon, 28 Dec 2020 05:13:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609161203; cv=none; d=google.com; s=arc-20160816; b=iBz89C6L0pK/+EP4N5sBcfXbFYEND5x9lXZ4B122xRQSOt5zB2KqUu5p7iPi40xoJj 3TBo1GgpN7i+pYOPDahD8MZLUItW3UM3tcqgbJxeIMUzbczBb50QBeBd23Xs8DoO6U9o ALdQAfVrIvGfpDNqjoanzaoGcCedJ0RB2O0g3FH/Jke1ZeyZjJ5fnyEBcPkM/ZjefeSz 32YxzT+EeRfQcYBeVhQp+3z7u0cjNDQe4SRpSkyH2q00ZRf9GRVB4N5Wk0/xN8OdcrK5 tS+53BxJb2dkbLC1v0+36WQLXgjNGWWQrYLHuOSKcdRgfD05ZJ5M+oYgM0C4zIqfXLAA w3mA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3sA23Hf1VcneLUL+JAzo9A0NyKV/R/KceEV0zd7hEAU=; b=Y0aqyMIXv5RRHWnq2A3rBeKU590kEOx/vWYIwgYJSwXLaQMXLpmhXRI/dhXD8kSFTA kFa+w2Tj207aEyK9chnky7BAtPc5MBie94Gbas5vIJcywySi5esaWXagj0WTVsXBqmmB prSdFldPp2o+PXEAX/Bt5zMPewxyfzNiFLFmz0PPghvxVTVLoZO5DrtzcX4w/saEHq6Y bQagmQuDiZp7mW1afxOtiiHvAu3/TT+y82XfxlpS2vtf54VCNRcS4Xvr/wzNJc+xb+13 +5I90NpyEOFiA/SGCmvNI3kvrc0k729azWrUrN5TsRKp0I6a9y+Q/kzlpp6eCTOLhIPc lcYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0QUIM+Ft; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c14si20907167edf.282.2020.12.28.05.13.00; Mon, 28 Dec 2020 05:13:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0QUIM+Ft; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731373AbgL1NKW (ORCPT + 99 others); Mon, 28 Dec 2020 08:10:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:38030 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731359AbgL1NKU (ORCPT ); Mon, 28 Dec 2020 08:10:20 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 246B022A84; Mon, 28 Dec 2020 13:09:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609160979; bh=k48YHGmEnT4sQWtHkPdkLaz6oOYF6LTXY9/Hwp2J8fc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0QUIM+Ftl3Ag78A0UFgzA7Ajdj3CkLiERMRuC8bnrbHKzQAXKU/0u+v2bC0TShYBO 3J+nfFCfguVgdMF+UMFDWUT1u06laQcrw0VJg+HAp8NNcoNmya6pcvtDcrMO/nx+Of qjiaAXNgogrdMguFf2FC8R8lKQwdFtFCt6j9KwDQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexey Kardashevskiy Subject: [PATCH 4.14 059/242] serial_core: Check for port state when tty is in error state Date: Mon, 28 Dec 2020 13:47:44 +0100 Message-Id: <20201228124907.588529532@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124904.654293249@linuxfoundation.org> References: <20201228124904.654293249@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexey Kardashevskiy commit 2f70e49ed860020f5abae4f7015018ebc10e1f0e upstream. At the moment opening a serial device node (such as /dev/ttyS3) succeeds even if there is no actual serial device behind it. Reading/writing/ioctls fail as expected because the uart port is not initialized (the type is PORT_UNKNOWN) and the TTY_IO_ERROR error state bit is set fot the tty. However setting line discipline does not have these checks 8250_port.c (8250 is the default choice made by univ8250_console_init()). As the result of PORT_UNKNOWN, uart_port::iobase is NULL which a platform translates onto some address accessing which produces a crash like below. This adds tty_port_initialized() to uart_set_ldisc() to prevent the crash. Found by syzkaller. Signed-off-by: Alexey Kardashevskiy Link: https://lore.kernel.org/r/20201203055834.45838-1-aik@ozlabs.ru Cc: stable Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serial/serial_core.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -1434,6 +1434,10 @@ static void uart_set_ldisc(struct tty_st { struct uart_state *state = tty->driver_data; struct uart_port *uport; + struct tty_port *port = &state->port; + + if (!tty_port_initialized(port)) + return; mutex_lock(&state->port.mutex); uport = uart_port_check(state);