From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f193.google.com ([209.85.128.193]:34983 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753484AbdDJNrg (ORCPT ); Mon, 10 Apr 2017 09:47:36 -0400 Received: by mail-wr0-f193.google.com with SMTP id l44so1831970wrc.2 for ; Mon, 10 Apr 2017 06:47:35 -0700 (PDT) Subject: Re: [patch added to 3.12-stable] tty/serial: atmel: fix race condition (TX+DMA) To: Jiri Slaby , stable@vger.kernel.org References: <20170410125930.26495-1-jslaby@suse.cz> <20170410125930.26495-43-jslaby@suse.cz> From: Richard Genoud Message-ID: <31c49511-39de-1a15-f0e8-ce65c6fd8725@gmail.com> Date: Mon, 10 Apr 2017 15:47:33 +0200 MIME-Version: 1.0 In-Reply-To: <20170410125930.26495-43-jslaby@suse.cz> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: stable-owner@vger.kernel.org List-ID: On 10/04/2017 14:59, Jiri Slaby wrote: > From: Richard Genoud > > This patch has been added to the 3.12 stable tree. If you have any > objections, please let us know. > > =============== > > commit 31ca2c63fdc0aee725cbd4f207c1256f5deaabde upstream. > > If uart_flush_buffer() is called between atmel_tx_dma() and > atmel_complete_tx_dma(), the circular buffer has been cleared, but not > atmel_port->tx_len. > That leads to a circular buffer overflow (dumping (UART_XMIT_SIZE - > atmel_port->tx_len) bytes). > > Tested-by: Nicolas Ferre > Signed-off-by: Richard Genoud > Signed-off-by: Jiri Slaby > --- > drivers/tty/serial/atmel_serial.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c > index ab2e22bf54fd..0e0023f7c18d 100644 > --- a/drivers/tty/serial/atmel_serial.c > +++ b/drivers/tty/serial/atmel_serial.c > @@ -1690,6 +1690,11 @@ static void atmel_flush_buffer(struct uart_port *port) > UART_PUT_TCR(port, 0); > atmel_port->pdc_tx.ofs = 0; > } > + /* > + * in uart_flush_buffer(), the xmit circular buffer has just > + * been cleared, so we have to reset tx_len accordingly. > + */ > + atmel_port->tx_len = 0; > } > > /* > Hi, This won't compile on 3.12 kernel since ->tx_len doesn't exist yet. Here is the backported version of this patch: Thanks ! ====================== commit 31ca2c63fdc0aee725cbd4f207c1256f5deaabde upstream. If uart_flush_buffer() is called between atmel_tx_dma() and atmel_complete_tx_dma(), the circular buffer has been cleared, but not atmel_port->tx_len. That leads to a circular buffer overflow (dumping (UART_XMIT_SIZE - atmel_port->tx_len) bytes). Signed-off-by: Richard Genoud --- drivers/tty/serial/atmel_serial.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c index ab2e22bf54fd..04a809284d63 100644 --- a/drivers/tty/serial/atmel_serial.c +++ b/drivers/tty/serial/atmel_serial.c @@ -1690,6 +1690,11 @@ static void atmel_flush_buffer(struct uart_port *port) UART_PUT_TCR(port, 0); atmel_port->pdc_tx.ofs = 0; } + /* + * in uart_flush_buffer(), the xmit circular buffer has just + * been cleared, so we have to reset its length accordingly. + */ + sg_dma_len(&atmel_port->sg_tx) = 0; } /*