Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1404274pxa; Sun, 2 Aug 2020 06:35:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwopmaiaaF+FH9mUSdT5hddyZ9T/VaRzRRVFV2aJdyPhITugUypEw0YpKFjVXBwkpNT8fZk X-Received: by 2002:a17:906:d217:: with SMTP id w23mr12961694ejz.292.1596375351335; Sun, 02 Aug 2020 06:35:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596375351; cv=none; d=google.com; s=arc-20160816; b=NzQjM7wBVA5Nx05BZZDyX7P5ctQb41KWJA/7kIhHLN7FT456kRsjVGVKweexf++/wG 7JWehMRlpvkgGfznhNS2+YQKtDlMd/r6efdcYQlJLibCcc9nuDEiqaCE0M2iIaVP3E9G 683PVug57c1sRHheAf+5kvUaNkG/4h4A0NIIK3nd0D/B5WDRh3qSBsXTesblDQYrIKL1 ozeQiUr0/icsHeJbBvOxalPMgrGa4l55rDoejormR9OBceQfkqVlAIycvygCL13J7RE3 jAH8AeZBakG6FF/DrmcCvd+orrg4kzFHaJIeYbbEpIeXKZ5oaKmPIhXF21Qkiw0+HSRG v87g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=HYXg3bcHewuOCq/X50oay0Ris6ZLRhYRa5mQLBIHNys=; b=Kd5bytmC+C+LoaWL2jFEHJXI+YCOQOHQbyh3UgSajQTPxVwt5tuid8zDArQO/EJuCW xhE65RP6jsrOqdp6Jmfx5rJsuTYsa4BivX8BMHxe7ZyNpLWJ2ER644etlXvY9Vi38wdq zDfrOUKPe54gFBk5+5TeIxyNqNm9KS6NgxKwzUq5PRuduevsAQz1rY3ZtY2UyeXUjmw/ lg0HWav25KxhrZkz2VnvQFcbYYCuuX/TBdDQMYYkbsc7GY67PKAGidoe5/CnLHqNZy8y UIa0gz79IO0GwOl9FbgLMaWHqcpHlm/tyvAZAzqXxrpwH+l/e6kZNQVr/aUQ7Pep3kRn 1YcA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u13si8634063edp.260.2020.08.02.06.35.29; Sun, 02 Aug 2020 06:35:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728217AbgHBNaW (ORCPT + 99 others); Sun, 2 Aug 2020 09:30:22 -0400 Received: from zg8tmtm5lju5ljm3lje2naaa.icoremail.net ([139.59.37.164]:38745 "HELO zg8tmtm5lju5ljm3lje2naaa.icoremail.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1726578AbgHBNaW (ORCPT ); Sun, 2 Aug 2020 09:30:22 -0400 X-Greylist: delayed 1139 seconds by postgrey-1.27 at vger.kernel.org; Sun, 02 Aug 2020 09:30:19 EDT Received: from oslab.tsinghua.edu.cn (unknown [166.111.139.112]) by app-1 (Coremail) with SMTP id DwQGZQDn7MjOvyZfkEDqAw--.5190S2; Sun, 02 Aug 2020 21:29:57 +0800 (CST) From: Jia-Ju Bai To: chunkeey@googlemail.com, kvalo@codeaurora.org, davem@davemloft.net, kuba@kernel.org Cc: linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] p54: avoid accessing the data mapped to streaming DMA Date: Sun, 2 Aug 2020 21:29:49 +0800 Message-Id: <20200802132949.26788-1-baijiaju@tsinghua.edu.cn> X-Mail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evJa73UjIFyTuYvjfUnpnQUUUUU X-CM-SenderInfo: xedlyxhdmxq3pvlqwxlxdovvfxof0/ Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In p54p_tx(), skb->data is mapped to streaming DMA on line 337: mapping = pci_map_single(..., skb->data, ...); Then skb->data is accessed on line 349: desc->device_addr = ((struct p54_hdr *)skb->data)->req_id; This access may cause data inconsistency between CPU cache and hardware. To fix this problem, ((struct p54_hdr *)skb->data)->req_id is stored in a local variable before DMA mapping, and then the driver accesses this local variable instead of skb->data. Signed-off-by: Jia-Ju Bai --- drivers/net/wireless/intersil/p54/p54pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/intersil/p54/p54pci.c b/drivers/net/wireless/intersil/p54/p54pci.c index 80ad0b7eaef4..f8c6027cab6b 100644 --- a/drivers/net/wireless/intersil/p54/p54pci.c +++ b/drivers/net/wireless/intersil/p54/p54pci.c @@ -329,10 +329,12 @@ static void p54p_tx(struct ieee80211_hw *dev, struct sk_buff *skb) struct p54p_desc *desc; dma_addr_t mapping; u32 idx, i; + __le32 device_addr; spin_lock_irqsave(&priv->lock, flags); idx = le32_to_cpu(ring_control->host_idx[1]); i = idx % ARRAY_SIZE(ring_control->tx_data); + device_addr = ((struct p54_hdr *)skb->data)->req_id; mapping = pci_map_single(priv->pdev, skb->data, skb->len, PCI_DMA_TODEVICE); @@ -346,7 +348,7 @@ static void p54p_tx(struct ieee80211_hw *dev, struct sk_buff *skb) desc = &ring_control->tx_data[i]; desc->host_addr = cpu_to_le32(mapping); - desc->device_addr = ((struct p54_hdr *)skb->data)->req_id; + desc->device_addr = device_addr; desc->len = cpu_to_le16(skb->len); desc->flags = 0; -- 2.17.1