[PATCH 3.12 142/142] tty/serial: atmel: fix race condition (TX+DMA)

From: Jiri Slaby
Date: Mon Apr 10 2017 - 11:35:45 EST


From: Richard Genoud <richard.genoud@xxxxxxxxx>

3.12-stable review patch. If anyone has any objections, please let me 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 <nicolas.ferre@xxxxxxxxxxxxx>
[rg] backport to 3.12
Signed-off-by: Richard Genoud <richard.genoud@xxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
Signed-off-by: Jiri Slaby <jslaby@xxxxxxx>
---
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;
}

/*
--
2.12.2