Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3132793ybi; Thu, 18 Jul 2019 21:40:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqz8FCatbT1ZZmPUg5j02XI/ydZS7oZKA4ztLfag6/k8XEb4U5KpEUYkGtKaqSHyIzrbSAKl X-Received: by 2002:a17:90a:bd0b:: with SMTP id y11mr52779956pjr.141.1563511220823; Thu, 18 Jul 2019 21:40:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563511220; cv=none; d=google.com; s=arc-20160816; b=b0HDioQc1DfktpsPo/3VuB/b5AJgBxNqMUb66Dk/K7Vjqt+gGdx3FeJn8KuNVaOsZc Xhbe70IusrppEPZTmM+HZlF8+fZY3nH8tBj3HKHbz5v02Vqo3AVNOaBD+G/avLK7yKnn cBwd+MRySkPg628Fn3hbJbSVPr4JdCRCVXVt0kzXWqKeLmDuzMYM82UMZg5PS09k2hY3 YS5Uh+tI+ExbJpFPnjyHpFZmmBV+un5nZPvp0FUB5SHqPXGtylPM7n2NpiVVmKFphHkD f2m0thEXZp6CoY/6dVLcgiL+Ka4S2V7K4B93ipt7gEdoFgxY1SVMSWdouquH4a3aqfZl X3Yw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=UhFjVSjRJnfWgx/JzPgu7W6RgUUxE9RnAw6eJl1Ku+w=; b=NA8ZL7btxthGBOivJQdZHeldDDkPpbGHJNVe+DapoKKG0jtoIHm+O0LvxDYvxaME/R BaQQ+OxzFJAYWZlfnVCI+2SU3cwEJmExCmggh9N49TvAMGxJv3IgswmFKnqsPOed+KYF QR2E4SlQiq0+4Hl3LUoKlKQILe9LOpDRQCQc6QRLTl79o4Nhi1KNdMLrA68+lujXo5IC bNpD/pAWy8EWRBPwj5cfQYOxWaaRBrmVoutL5B3lPUa4x3JiquM6Da6jy/aPaTP/RKTh 3FP6U6uRW1w6EyKafAuEXajDYfQMR0qK/4+gGK1SqMiXdvOneVyHsdY7DsKTlbvG74pJ eAmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Gbpz9j8a; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t9si348744pjw.22.2019.07.18.21.40.05; Thu, 18 Jul 2019 21:40:20 -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=Gbpz9j8a; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732140AbfGSEi6 (ORCPT + 99 others); Fri, 19 Jul 2019 00:38:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:58568 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728469AbfGSD7G (ORCPT ); Thu, 18 Jul 2019 23:59:06 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0416821852; Fri, 19 Jul 2019 03:59:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563508745; bh=dxgGkTCEKN+iBBtVZ0FjeumraVHO0H3g3lPhpHsRdgY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Gbpz9j8az8hUkJi9YaP1uKDI97fZbehtoaCe4I2q0KS33o3e3iNjI1sy/LBC7rJ+x IJFwUvgqQL0tywxw+ZzuzlHrOWFCu0jAtIsokuPxjndawj+V+jQLSSXLvhyrQS24J/ TFl4zt5+hKADeGRYYPKYep0RLj3nSS9kGc8reOD8= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Sergey Organov , Greg Kroah-Hartman , Sasha Levin , linux-serial@vger.kernel.org Subject: [PATCH AUTOSEL 5.2 066/171] serial: imx: fix locking in set_termios() Date: Thu, 18 Jul 2019 23:54:57 -0400 Message-Id: <20190719035643.14300-66-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190719035643.14300-1-sashal@kernel.org> References: <20190719035643.14300-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sergey Organov [ 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