Received: by 10.223.185.116 with SMTP id b49csp3995908wrg; Mon, 19 Feb 2018 09:15:10 -0800 (PST) X-Google-Smtp-Source: AH8x224/NX59n589IV1o1+tGHTLWEuSHZlV2TWlr9c2G3AmOrys8NPUd/MMwMvAheVLyfG2O3+Ta X-Received: by 2002:a17:902:40a:: with SMTP id 10-v6mr14893951ple.245.1519060510777; Mon, 19 Feb 2018 09:15:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519060510; cv=none; d=google.com; s=arc-20160816; b=f4nIJi8wkYVNNI9+MdzDNQJcM2pe3NTcidEAX+r50cNEitq8r8EL80pJP8G5fR/j5R mAZufkgrNCQVhg4NX6iuWHt1S+q2XsnG3TwLfVmLJ9yrYFFKlrbZDMO2tBWm0hGve4iR HX0qhq8OLjqk7gO7MSnx1YOVQhwO8ke/dVFLEAutjLChY1tnHNc7+a+xJk0907wr+cAw yEKMix1KkkUj8JBbDxi59gttiLtlqvoe20MaHnbojT4/fo3gBE7SGUSZPmeXH2Cq4Vsl resbcO/ArOZpSh7BX6DdS5T5ag0xYEBxsQyTf5Sw0hVJtRWwbwK3qo+RkxUzXUbI9IJe mgkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=mGP6i2b1knX7IbKMqP6sCGbntWxQpsLfJyOB8tu4vtc=; b=naxwCoqyO/YvL1QwWpu+SF6Lx13HTubMVoAwR0DFD/wqhi9k/6IkjG+pXoqQiVFP72 +E6au9NB/3uTnL2FwVOxTKYgJmVM9m5zQ3/0pH7zL7UNvD8i+JYOjEN7boxXlViNf6t0 ronfVrgZyr3diDW+PBW8niBddseFR3mfaXRGHGPU5tFeGmXqMLr7k0wffpqk0D4xN5qA i9//YBOmDpqWwgZdrp35yH+AxsY4naVZ7u52lf6Ozh9jwvxCGUrHAKqG0e5TagTuuzf3 rhYF1t5uX5YhQqE5+aOBM1kzXvGtUtEWBf9sovXG1K5GVfDvHmTaaI+JAaRzGdAhV2hd Lsmg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w12si8282109pgr.211.2018.02.19.09.14.56; Mon, 19 Feb 2018 09:15:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753593AbeBSRLt (ORCPT + 99 others); Mon, 19 Feb 2018 12:11:49 -0500 Received: from bastet.se.axis.com ([195.60.68.11]:38880 "EHLO bastet.se.axis.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753449AbeBSRLq (ORCPT ); Mon, 19 Feb 2018 12:11:46 -0500 Received: from localhost (localhost [127.0.0.1]) by bastet.se.axis.com (Postfix) with ESMTP id E6F111833E; Mon, 19 Feb 2018 18:11:44 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at bastet.se.axis.com Received: from bastet.se.axis.com ([IPv6:::ffff:127.0.0.1]) by localhost (bastet.se.axis.com [::ffff:127.0.0.1]) (amavisd-new, port 10024) with LMTP id dd3JyQTNc-qB; Mon, 19 Feb 2018 18:11:42 +0100 (CET) Received: from boulder03.se.axis.com (boulder03.se.axis.com [10.0.8.17]) by bastet.se.axis.com (Postfix) with ESMTPS id 9767518070; Mon, 19 Feb 2018 18:11:42 +0100 (CET) Received: from boulder03.se.axis.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 85BEC1E080; Mon, 19 Feb 2018 18:11:42 +0100 (CET) Received: from boulder03.se.axis.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 790711E07F; Mon, 19 Feb 2018 18:11:42 +0100 (CET) Received: from seth.se.axis.com (unknown [10.0.2.172]) by boulder03.se.axis.com (Postfix) with ESMTP; Mon, 19 Feb 2018 18:11:42 +0100 (CET) Received: from lnxartpec1.se.axis.com (lnxartpec1.se.axis.com [10.88.4.10]) by seth.se.axis.com (Postfix) with ESMTP id 6CCC21A5E; Mon, 19 Feb 2018 18:11:42 +0100 (CET) Received: by lnxartpec1.se.axis.com (Postfix, from userid 20283) id 681FE401B8; Mon, 19 Feb 2018 18:11:42 +0100 (CET) From: Niklas Cassel To: Giuseppe Cavallaro , Alexandre Torgue Cc: Jose.Abreu@synopsys.com, vbhadram@nvidia.com, Niklas Cassel , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 3/7] net: stmmac: WARN if tx_skbuff entries are reused before cleared Date: Mon, 19 Feb 2018 18:11:11 +0100 Message-Id: <20180219171116.15326-4-niklas.cassel@axis.com> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180219171116.15326-1-niklas.cassel@axis.com> References: <20180219171116.15326-1-niklas.cassel@axis.com> X-TM-AS-GCONF: 00 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The current code assumes that a tx_skbuff entry has been cleared by stmmac_tx_clean() before stmmac_xmit()/stmmac_tso_xmit() assigns a new skb to that entry. However, since we never check the current value before overwriting it, it is theoretically possible that a non-NULL value is overwritten. Add WARN_ONs to verify that each entry in tx_skbuff is NULL before it is assigned a new value. Signed-off-by: Niklas Cassel --- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 24afe7733cde..9881df126227 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -2794,6 +2794,7 @@ static void stmmac_tso_allocator(struct stmmac_priv *priv, unsigned int des, while (tmp_len > 0) { tx_q->cur_tx = STMMAC_GET_ENTRY(tx_q->cur_tx, DMA_TX_SIZE); + WARN_ON(tx_q->tx_skbuff[tx_q->cur_tx]); desc = tx_q->dma_tx + tx_q->cur_tx; desc->des0 = cpu_to_le32(des + (total_len - tmp_len)); @@ -2878,6 +2879,7 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev) priv->hw->desc->set_mss(mss_desc, mss); tx_q->mss = mss; tx_q->cur_tx = STMMAC_GET_ENTRY(tx_q->cur_tx, DMA_TX_SIZE); + WARN_ON(tx_q->tx_skbuff[tx_q->cur_tx]); } if (netif_msg_tx_queued(priv)) { @@ -2888,6 +2890,7 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev) } first_entry = tx_q->cur_tx; + WARN_ON(tx_q->tx_skbuff[first_entry]); desc = tx_q->dma_tx + first_entry; first = desc; @@ -3062,6 +3065,7 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev) entry = tx_q->cur_tx; first_entry = entry; + WARN_ON(tx_q->tx_skbuff[first_entry]); csum_insertion = (skb->ip_summed == CHECKSUM_PARTIAL); @@ -3090,6 +3094,7 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev) bool last_segment = (i == (nfrags - 1)); entry = STMMAC_GET_ENTRY(entry, DMA_TX_SIZE); + WARN_ON(tx_q->tx_skbuff[entry]); if (likely(priv->extend_desc)) desc = (struct dma_desc *)(tx_q->dma_etx + entry); -- 2.14.2