Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3809633ybi; Mon, 29 Jul 2019 13:04:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqzbFYi6FC0FE/1/SuwVIkNsddtOB07xWUtUdKSSsAZDyplYa6TIRlwgoqrM1e2rCVysHN7u X-Received: by 2002:a17:90a:2627:: with SMTP id l36mr116476609pje.71.1564430643482; Mon, 29 Jul 2019 13:04:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564430643; cv=none; d=google.com; s=arc-20160816; b=vlARZIILcl7qCMkmAepl5wYfi6quk8KVMBW+2N7qZcswkI40rlKKkCw0imqx2kK1UL 1yor/8UQuXTgHFegS+dppE0o+D0QLHYip7SVgFOgz4L7QS3HBhQJaunWkGLatn5g/cYK dZCShLLjdQJhuX3AVMqNSyBvTnZzSgP3gge4/+0vhpePkd10pplHk4v8KZVbS+vhyeK5 xHpwW86nsc9rBI7PVFd8OAVGzxBPLDO3Sr477bbW5IzWoqRwJnEid1B0a7WGHRmMxowS T1Ka/Lqrsa1JMAccoDKRKL2WW6WZu64xDAOXPrMUJdO3p76a5ykvZL9m8xdMnogj+2ec RVRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2psITQNRcGWr8vadtKdnJRgNn38H7tU2OXJHHFLh6+g=; b=EkxzGN/yhjYr3+QHSI2NW6XMQ6gKpPG7HeEbPIvrRulQLNGyZxAPkg24ZZXIEqP4G8 fbg0EAcg/5cfEkv+OV+7yuqtyubAE/2umsSZRzZQ8rKogSoQ2WSe8uX04ANm7QSlV+ev m46vSkiNJLB3lZpHJ0YBNA/JxCbBbC+dd1FP2M3rVL5fxfXo0H2ykdEnYcQTvabqLf/C g/5/dyuxxoN/oJ+vzY/RR0WcWvKNBO/SFRMBKPsvKsdIAa5iirunej7Hg+TuaftdTrrE L7gKDfkuwPWaX2+5UtCPDJjXeTEtTFGbqXSlocTHWRrqn7bXmQWwRcycmnIWSbIXBYUb GwiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dBWYEgu3; 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 k16si26269366pfi.174.2019.07.29.13.03.48; Mon, 29 Jul 2019 13:04:03 -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; dkim=pass header.i=@kernel.org header.s=default header.b=dBWYEgu3; 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 S2389254AbfG2UCd (ORCPT + 99 others); Mon, 29 Jul 2019 16:02:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:38614 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390116AbfG2Ts0 (ORCPT ); Mon, 29 Jul 2019 15:48:26 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 CD6E9205F4; Mon, 29 Jul 2019 19:48:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564429705; bh=8dUIjr2MUd/Rlw9eJYgxNMwwu865DgmO5oeE6/wrXgk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dBWYEgu3zqTol+F/RgF2yE63Wgbg7kKWCtTIzFhIHtUQi0UXJgKtGq6nraEBQuG74 vHqCRArMRgBvhm/Dxzna0vj3sgfdUO/iNXR5q7MaBWhUMsffFUOIXNijy8PmY45D4J JPeaMo427osyhi00jRIwwXXCva0sfk8ZQIdWA3DI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sergey Organov , Sasha Levin Subject: [PATCH 5.2 067/215] serial: imx: fix locking in set_termios() Date: Mon, 29 Jul 2019 21:21:03 +0200 Message-Id: <20190729190751.985542237@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190739.971253303@linuxfoundation.org> References: <20190729190739.971253303@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 4e828c3e09201512be5ee162393f334321f7cf01 ] imx_uart_set_termios() called imx_uart_rts_active(), or imx_uart_rts_inactive() before taking port->port.lock. As a consequence, sport->port.mctrl that these functions modify could have been changed without holding port->port.lock. Moved locking of port->port.lock above the calls to fix the issue. Signed-off-by: Sergey Organov Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/tty/serial/imx.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index 8b752e895053..10db3e54ac9e 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -383,6 +383,7 @@ static void imx_uart_ucrs_restore(struct imx_port *sport, } #endif +/* called with port.lock taken and irqs caller dependent */ static void imx_uart_rts_active(struct imx_port *sport, u32 *ucr2) { *ucr2 &= ~(UCR2_CTSC | UCR2_CTS); @@ -391,6 +392,7 @@ static void imx_uart_rts_active(struct imx_port *sport, u32 *ucr2) mctrl_gpio_set(sport->gpios, sport->port.mctrl); } +/* called with port.lock taken and irqs caller dependent */ static void imx_uart_rts_inactive(struct imx_port *sport, u32 *ucr2) { *ucr2 &= ~UCR2_CTSC; @@ -400,6 +402,7 @@ static void imx_uart_rts_inactive(struct imx_port *sport, u32 *ucr2) mctrl_gpio_set(sport->gpios, sport->port.mctrl); } +/* called with port.lock taken and irqs caller dependent */ static void imx_uart_rts_auto(struct imx_port *sport, u32 *ucr2) { *ucr2 |= UCR2_CTSC; @@ -1549,6 +1552,16 @@ imx_uart_set_termios(struct uart_port *port, struct ktermios *termios, old_csize = CS8; } + del_timer_sync(&sport->timer); + + /* + * Ask the core to calculate the divisor for us. + */ + baud = uart_get_baud_rate(port, termios, old, 50, port->uartclk / 16); + quot = uart_get_divisor(port, baud); + + spin_lock_irqsave(&sport->port.lock, flags); + if ((termios->c_cflag & CSIZE) == CS8) ucr2 = UCR2_WS | UCR2_SRST | UCR2_IRTS; else @@ -1592,16 +1605,6 @@ imx_uart_set_termios(struct uart_port *port, struct ktermios *termios, ucr2 |= UCR2_PROE; } - del_timer_sync(&sport->timer); - - /* - * Ask the core to calculate the divisor for us. - */ - baud = uart_get_baud_rate(port, termios, old, 50, port->uartclk / 16); - quot = uart_get_divisor(port, baud); - - spin_lock_irqsave(&sport->port.lock, flags); - sport->port.read_status_mask = 0; if (termios->c_iflag & INPCK) sport->port.read_status_mask |= (URXD_FRMERR | URXD_PRERR); -- 2.20.1