Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753294AbdFSTUd (ORCPT + 2 others); Mon, 19 Jun 2017 15:20:33 -0400 Received: from wtarreau.pck.nerim.net ([62.212.114.60]:52163 "EHLO 1wt.eu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753088AbdFSSfu (ORCPT ); Mon, 19 Jun 2017 14:35:50 -0400 From: Willy Tarreau To: linux-kernel@vger.kernel.org, stable@vger.kernel.org, linux@roeck-us.net Cc: Richard Genoud , Greg Kroah-Hartman , Willy Tarreau Subject: [PATCH 3.10 219/268] tty/serial: atmel: fix race condition (TX+DMA) Date: Mon, 19 Jun 2017 20:31:58 +0200 Message-Id: <1497897167-14556-220-git-send-email-w@1wt.eu> X-Mailer: git-send-email 2.8.0.rc2.1.gbe9624a In-Reply-To: <1497897167-14556-1-git-send-email-w@1wt.eu> References: <1497897167-14556-1-git-send-email-w@1wt.eu> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: From: Richard Genoud 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 [rg] backport to 3.12 Signed-off-by: Richard Genoud Signed-off-by: Greg Kroah-Hartman Signed-off-by: Willy Tarreau --- 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 82127ac..41d1df5 100644 --- a/drivers/tty/serial/atmel_serial.c +++ b/drivers/tty/serial/atmel_serial.c @@ -1090,6 +1090,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; } /* -- 2.8.0.rc2.1.gbe9624a