Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9036475pxu; Mon, 28 Dec 2020 05:05:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJwlDzh6Kp1l8yzL3nRHJsl8jxtjtMW/j+zns7aVt6ZlFdsZ/yULibf0yDA8elgfyUkLlNfS X-Received: by 2002:a50:9f4a:: with SMTP id b68mr41681217edf.296.1609160705721; Mon, 28 Dec 2020 05:05:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609160705; cv=none; d=google.com; s=arc-20160816; b=wSBtfQk295O5Khpf024OqWx/UwFO7HUEMp1wQX5ZLANizaHVA+UG0J8QeOoGYPn/nr XaZeCk5RSNVCQL+VtAWnntXI6MAq+FCGajk1kj7FxnD9Ce2q179BuWq4qcS6uMwW5dx8 JGjHz+tvNqUqAaetyIPpY4OH/k3z58V3lISMuPooe4ppkyB5f58ynh+Itt3So1qqyRun mSbULDvdA6pjcqwo1NEBhx405tYzYD6s1i6vzMSIk3Vbx9uLfmFKJ4xCSvZveWzc/V38 X76JgX6U0hoyK/KXs5HhRFcBGQWZ2PbMBiuWiH0WlPX3djpGpi074nM+fgK05QHaUHE2 iYsA== 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=6QDRiCmm1BCUF/2NefSjq40/G4YcgSIAoQZ7rUeX2SQ=; b=tiH1CdwB/4HtpYu6ZHdUQY3ulowJ5qil/XEVFZ3SaDFaR+T0eb0jlWIUWxVRgt1kwj 901aerXT41ZnOby3X1y/dDoSj0cyaggKJFDXoNd+Fn0+SA/e6H3Wd2wNr80t9KQFdnS+ RYi3r1Fh6ZhRe7O+bIHLnolo/1enVnvkdF0I+50wKFhk1/Mle2J8Nbn2VBGYwhPGYai6 UFSapLqNnX5QFEuX54BN1GyZK1PkmvebzKtye2TXpEPgsm1EFhtivKJRanKboWDGqHj3 Ah4w7RawIYAK387ikhRUkXQojSQzZTS/zyaMFKj3wv0UMwGHzsm2mmXsqBE0Adyz82fD 9hng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=M4vOIC83; 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 pw18si18233728ejb.163.2020.12.28.05.04.41; Mon, 28 Dec 2020 05:05:05 -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=M4vOIC83; 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 S1729862AbgL1NBu (ORCPT + 99 others); Mon, 28 Dec 2020 08:01:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:57512 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729633AbgL1NBE (ORCPT ); Mon, 28 Dec 2020 08:01:04 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id AFA8722573; Mon, 28 Dec 2020 13:00:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609160424; bh=2qAZyJ0KhRZMRyr9LxKdCJ+yR8vg/BJqnkPg1iliz4U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M4vOIC83mfm5wUN9qarhQBZFlTXdAeF5ItM9L/nEYQFlyu8VjX5WtxDAmFKam+WYn EWOpqMelClI25pQYwpgO6oUlEAcfYX5voZVAOfKXwMQLk5P2Qj/IBNb89qC+LLGxf4 RMG2fChxWemkmIUsmm4/O9BJGNYC8FGdqjiPsCMo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexey Kardashevskiy Subject: [PATCH 4.9 046/175] serial_core: Check for port state when tty is in error state Date: Mon, 28 Dec 2020 13:48:19 +0100 Message-Id: <20201228124855.485989423@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124853.216621466@linuxfoundation.org> References: <20201228124853.216621466@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 @@ -1415,6 +1415,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);