From patchwork Mon Mar 20 10:52:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Genoud X-Patchwork-Id: 9633713 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 375A6602D6 for ; Mon, 20 Mar 2017 10:53:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24D2F27D29 for ; Mon, 20 Mar 2017 10:53:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 18B2A27F85; Mon, 20 Mar 2017 10:53:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9D20027D29 for ; Mon, 20 Mar 2017 10:53:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=rbZlviAlhQpYpEae6jsi5bTeMkWrRfm2Wv9g1bHByBw=; b=Kb6 UHPHwXv0VROVSjAj5yIuYr+Th0SzQsiBw/Npm/xMMtUSv4ostc3DzZsSORMFAIVQ/NuQZEZFODv+G uIRN5JaKd1CKvUBf+A9uMAu9nU3A1+8YrHVTM4kON+2CtSCqojqUS7o9MKbc9Cq7pPAx/sxXtO7g0 EebgjkJ/WC9A6+soTSOLuMyDUcya55H2s9+d8jjGbJY91OvwQuTF4dZLsxiuk5U2fayBW1h48Y7Yb wP8D6qf/sWqDpe1vm4u+dsUXxZA7YwpoEMez0Kx2ESBV/3mvycf7oq1IF4pCMK5/1UGYqjuamvqsn vK438WDjdHeRWLlPtjzDxc7NeE8ueOQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cpuwF-0003Dl-Ac; Mon, 20 Mar 2017 10:53:23 +0000 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cpuwB-0003BL-Vm for linux-arm-kernel@lists.infradead.org; Mon, 20 Mar 2017 10:53:21 +0000 Received: by mail-wr0-x243.google.com with SMTP id g10so17517211wrg.0 for ; Mon, 20 Mar 2017 03:52:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=QUjy8/eAYnnAYtymBKGb9MVCeDUAOJU9UxzNu6ZWVgg=; b=hMNS8OoV17w6VrRyeqvxlXGwLIB7+Gc6lrI7tIhO7ExwFXaChrkJmFNl0j7Ho89BvZ ZGuQ4QNsPSLr4j2kImHDfFjixCz9mk4ImgH5GJpImbFGgUCDAENf+D5aMOBMWCUO753r PeYBZBEpJ01fu9C+EhPMnEFtg54zinUI15/nOBy3XcxX0ykrdM0D+EVEYjJyG5uWuaDB z31ma1I58RYH/wu/Nu0SxNsILv4E65jd4u0QrWlLAgGHD+iT8d4rcLayPAzTSqqctl4m JrD4ues9JKkaFjmDC9qaYYdK/YEy5ESBRvf/pKUu18ZDApZgbaEWLyjf5sBKOUZ7UB2P VCPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=QUjy8/eAYnnAYtymBKGb9MVCeDUAOJU9UxzNu6ZWVgg=; b=JO+EFylhjN7pAqqr7ZiaW91iSlYFazxXB2+hF00t3P/Pbv13A7ohe2TNqN4sR75JUA p5BLx1zWvTfjOmUxgFzug2hY4nejDb0beVzLqQdN8v1dQVINc7TFPfCqXbgizBGSYkm0 yiuK9VzjOWZ9BlHhgMndPMGoQzd6g9WYHKdZGvENcqmXrnavuuVYBF8K0/vd/aVI1h5T Z4hs4dyovaagTaDr/Ov3wOLGaagSax22TfL7Jl/Zz7SLkX1uSCpJdk+m0MfAxqLJT8nr PTh/+TOk5RNnUPNbdcsGepZl1X8Ws/rAI1gpfOMhNlyhLgSyt1MX7/2EVpvAbCLDz6kA XVxw== X-Gm-Message-State: AFeK/H3m152j79eTzXsUrd7Wz6h/k4ivO2YiJS5VWHTW7nwaF9mmN+K1sS/Nmk4gFPreUA== X-Received: by 10.223.171.239 with SMTP id s102mr24105409wrc.23.1490007178301; Mon, 20 Mar 2017 03:52:58 -0700 (PDT) Received: from localhost ([46.227.18.67]) by smtp.gmail.com with ESMTPSA id d42sm20392974wrd.37.2017.03.20.03.52.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Mar 2017 03:52:57 -0700 (PDT) From: Richard Genoud To: Greg Kroah-Hartman Subject: [PATCH] tty/serial: atmel: fix race condition (TX+DMA) Date: Mon, 20 Mar 2017 11:52:41 +0100 Message-Id: <20170320105241.25648-1-richard.genoud@gmail.com> X-Mailer: git-send-email 2.11.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170320_035320_200590_09DA4287 X-CRM114-Status: GOOD ( 11.19 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Genoud , "stable # 3 . 12+" , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Cc: stable # 3.12+ --- NB: this will apply on kernels 4.3+, for kernels before 4.3, the code will be: sg_dma_len(&atmel_port->sg_tx) = 0; 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 d9c05e05d896..5c23fb4e552b 100644 --- a/drivers/tty/serial/atmel_serial.c +++ b/drivers/tty/serial/atmel_serial.c @@ -1954,6 +1954,11 @@ static void atmel_flush_buffer(struct uart_port *port) atmel_uart_writel(port, ATMEL_PDC_TCR, 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; } /*