From patchwork Fri Jun 5 13:46:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Jensen X-Patchwork-Id: 6553561 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 1B112C0020 for ; Fri, 5 Jun 2015 13:54:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 431CC20712 for ; Fri, 5 Jun 2015 13:54:53 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 208DB2070C for ; Fri, 5 Jun 2015 13:54:52 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z0s0Q-0007D4-S8; Fri, 05 Jun 2015 13:49:54 +0000 Received: from merlin.infradead.org ([205.233.59.134]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z0s0O-0007Co-Jg for linux-arm-kernel@bombadil.infradead.org; Fri, 05 Jun 2015 13:49:52 +0000 Received: from mail-la0-x22f.google.com ([2a00:1450:4010:c03::22f]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z0ryJ-0005AG-HY for linux-arm-kernel@lists.infradead.org; Fri, 05 Jun 2015 13:47:44 +0000 Received: by labko7 with SMTP id ko7so54702753lab.2 for ; Fri, 05 Jun 2015 06:46:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=Hc/G/JfeWQFl0B4eclgjSiF/il13n5/Ygc/G1UjcUB4=; b=hZdVt18NByIRlOCpkQDZZ6CvbcxW/NTdVlLrHrDfeyg/3dHWQ1DoCTl4whhvJb1T9h 0w4r9JfXVMqTbVqf0PfjF7SJlzppja+JpXTFQNdNL/gZ7OJw1JqX3zR0r1A/p58xH9nV 78t8BYfx8Jvf76lJv404gm5FAgCFyULqh+p5sg372kGFI+2BwsLHQpAQSkOaBl/0VegA Dn1ujCjBijYqUWpnmTEkJd7IIZ9MOGZP91FyTKrTeHckQD4a7yqseVH+9iegIOyDfRoq mAKk+CmCE4uY56cwQN3c14m9byHrpvDL8EJYoIoBa9aaCBczi8xjPwmHC7VJFeXLXSQe rP8g== X-Received: by 10.152.30.4 with SMTP id o4mr3360717lah.74.1433511993353; Fri, 05 Jun 2015 06:46:33 -0700 (PDT) Received: from ildjarn.test.com (static-213-115-41-10.sme.bredbandsbolaget.se. [213.115.41.10]) by mx.google.com with ESMTPSA id gn6sm1787465lbc.28.2015.06.05.06.46.31 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 05 Jun 2015 06:46:32 -0700 (PDT) From: Jonas Jensen To: netdev@vger.kernel.org Subject: [PATCH] net: moxa: fix TX overrun memory leak Date: Fri, 5 Jun 2015 15:46:18 +0200 Message-Id: <1433511978-17666-1-git-send-email-jonas.jensen@gmail.com> X-Mailer: git-send-email 1.8.2.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150605_094743_874607_62B18128 X-CRM114-Status: GOOD ( 14.15 ) X-Spam-Score: -1.9 (-) Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Jonas Jensen X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_WEB, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP moxart_mac_start_xmit() doesn't care where tx_tail is, tx_head can catch and pass tx_tail, which is bad because moxart_tx_finished() isn't guaranteed to catch up on freeing resources from tx_tail. Add a check in moxart_mac_start_xmit(), exit to make sure tx_head never passes tx_tail. Move tx_head and place tx_tail within spinlock, avoiding read-write race that could happen when interrupts hit at the wrong moment. Addresses https://bugzilla.kernel.org/show_bug.cgi?id=99451 Signed-off-by: Jonas Jensen --- Notes: Applies to next-20150604 drivers/net/ethernet/moxa/moxart_ether.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/moxa/moxart_ether.c b/drivers/net/ethernet/moxa/moxart_ether.c index becbb5f..e0af86c 100644 --- a/drivers/net/ethernet/moxa/moxart_ether.c +++ b/drivers/net/ethernet/moxa/moxart_ether.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "moxart_ether.h" @@ -312,13 +313,22 @@ static int moxart_mac_start_xmit(struct sk_buff *skb, struct net_device *ndev) struct moxart_mac_priv_t *priv = netdev_priv(ndev); void __iomem *desc; unsigned int len; - unsigned int tx_head = priv->tx_head; + unsigned int tx_head, tx_tail; u32 txdes1; int ret = NETDEV_TX_BUSY; + spin_lock_irq(&priv->txlock); + + tx_head = priv->tx_head; + tx_tail = priv->tx_tail; + desc = priv->tx_desc_base + (TX_REG_DESC_SIZE * tx_head); - spin_lock_irq(&priv->txlock); + if (CIRC_SPACE(tx_head, tx_tail, TX_DESC_NUM) == 0) { + priv->stats.tx_dropped++; + goto out_unlock; + } + if (readl(desc + TX_REG_OFFSET_DESC0) & TX_DESC0_DMA_OWN) { net_dbg_ratelimited("no TX space for packet\n"); priv->stats.tx_dropped++;