Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp3070644pxu; Mon, 19 Oct 2020 03:12:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzuBJcGzM2WBAyk5KT2jXlZa0dZ2tUcBbkH/irXGTaRqtA66Jr8m3xO3CZjoaLYaQi8KWcw X-Received: by 2002:a05:6402:601:: with SMTP id n1mr17981356edv.240.1603102325400; Mon, 19 Oct 2020 03:12:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603102325; cv=none; d=google.com; s=arc-20160816; b=zptb8R5jiqvJncJFxUWPpphNP8eb/KrzTsBJvD8j130SMxTDNjUmzjl1G2PKMZopGo IrwrHGnRzAyXjI5+hPX1fP/stqLoFng2zWkWupDR0xEmOf3tqjGfNZSXLcdQkR9ncUYJ oKeN8Te/gHnNMVQXjEJomfpTjIXzGnSJ1W+SBlRK6WMfXLxJhHRKpt3NSvCi6aig9Cne 742yvHbhMeW3F5T9tnD9IceYUhkTkHcY/JcKjF6Cit11fUC8vgOkqxhIqKSqfNtDC0FK QsQ5YdbNFQF5YRw88/VOW0+5CjHcLDY6tWRTqolRgZmUkFT5JcE/PAcHaH2AW4JMjZYA UZfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=t5eReXO4wqmdOiCBF4R3AZcbfxasgeFRgSN87jtfTOA=; b=dsN3JT6GgH9ev9IiYzQ/vVCihcXCUzekWYKu/n/Nskx0OQgdyDufXSMJHVMjNb/GGp Gfhsy7d33BK17ch5rzQ2HveK6EzMV1h/TceTTKUMCtp7C66HQr/Ai4oNl3DsY6X7HKB0 y/HWBcDWvRLS1jrBq9CRFWmcKDlBac96XucLbCM6p6piio9c2urS6NyZtBsFuTX2nzMt v9+43RagjiBuZWXD6XeIoLtXsfUhWmcLUbBmZnJu49ttRQC1ENt163IdZoc2eAjTRynT mQPSo+tkNlvnDgd3SP6nU8+KoxctJXJSy47IatHmYcf3Lc0qO8dBLQRG3gvCqD0s3641 xM3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=YyEN54Pk; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ay8si7409664edb.400.2020.10.19.03.11.41; Mon, 19 Oct 2020 03:12:05 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=YyEN54Pk; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727308AbgJSECE (ORCPT + 99 others); Mon, 19 Oct 2020 00:02:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725800AbgJSECE (ORCPT ); Mon, 19 Oct 2020 00:02:04 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32953C061755; Sun, 18 Oct 2020 21:02:04 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id e7so5202305pfn.12; Sun, 18 Oct 2020 21:02:04 -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=t5eReXO4wqmdOiCBF4R3AZcbfxasgeFRgSN87jtfTOA=; b=YyEN54Pkrupuqjn9CbeFnnwes1U/Mn6o6wmsKwP185/yOGqAfJhYtkg9B+z7AUsyOp RJhD9kYdaA20LVoBfFs+Ph3F8iKmf0JpCsHJEYpnhQG1oCW0BpoQXiqJ6tjVdblLhPRv aaZYSix85W/sdmkEepbRWLkaMLVQpxuScCBGSVvNKPjspj8dMRXleyLwbmdM930sGGVb IUnRo0LaMd4HYCEYhP1wHRz7AH4/inlITmMo5LeuW/ctq44w8XKgyIAYzhPmsFHpXg08 hJFhERNTJoEcIUiwMWWZpDXsmkvmb+0494dgikhQgSQWlhrvOa20KCWfXt4TZXUs2mvp EWXw== 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=t5eReXO4wqmdOiCBF4R3AZcbfxasgeFRgSN87jtfTOA=; b=qLAgCuPpWZ3YUj1mI6OTUCSRiEb9RvPDc6l+MMhqdEcDB2DqyUaKUatlO2qHKwV6cd vXEmTojqMTahi4s+8bAl+A7gaFVlBqTNE0UqWZFm2cHStkkcMg2hkdCarM9DkRWUFVyf ALJfR5ngd0MRzosf03tCEOHS+EoECQsHw5atNnesJlMrH5fRw4CoJ+FYfB4ZrnLKGZFC OO0+RnhNgkBqgDEe0tCHkrBqldqyCyjtvGDh4KzDgrRtjCGAKnSNks7Mdi+xU+JB4Owi ctJY6G672zf6v77uehqBB3r0Q+rjNCVI8KmXxM/m1JcdYiuSscZM8jA+kaGPJKhiAiN1 GggA== X-Gm-Message-State: AOAM533mvBBMA/FtrYjNwZ4YBvt6ZMe38aJrkL5njXUxWp1Id7lH26FK mZrELy7+turckmv1ZrJgLTk= X-Received: by 2002:a63:2145:: with SMTP id s5mr11947483pgm.288.1603080123790; Sun, 18 Oct 2020 21:02:03 -0700 (PDT) Received: from oslab.tsinghua.edu.cn ([166.111.139.137]) by smtp.gmail.com with ESMTPSA id y8sm10096359pfg.104.2020.10.18.21.02.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Oct 2020 21:02:03 -0700 (PDT) From: Jia-Ju Bai To: pkshih@realtek.com, kvalo@codeaurora.org, davem@davemloft.net, kuba@kernel.org, Larry.Finger@lwfinger.net, christophe.jaillet@wanadoo.fr, zhengbin13@huawei.com Cc: linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] rtl8188ee: avoid accessing the data mapped to streaming DMA Date: Mon, 19 Oct 2020 12:01:55 +0800 Message-Id: <20201019040155.6961-1-baijiaju1990@gmail.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In rtl88ee_tx_fill_cmddesc(), skb->data is mapped to streaming DMA on line 677: dma_addr_t mapping = dma_map_single(..., skb->data, ...); On line 680, skb->data is assigned to hdr after cast: struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data); Then hdr->frame_control is accessed on line 681: __le16 fc = hdr->frame_control; This DMA access may cause data inconsistency between CPU and hardwre. To fix this bug, hdr->frame_control is accessed before the DMA mapping. Signed-off-by: Jia-Ju Bai --- drivers/net/wireless/realtek/rtlwifi/rtl8188ee/trx.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/trx.c b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/trx.c index b9775eec4c54..c948dafa0c80 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/trx.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/trx.c @@ -674,12 +674,12 @@ void rtl88ee_tx_fill_cmddesc(struct ieee80211_hw *hw, u8 fw_queue = QSLT_BEACON; __le32 *pdesc = (__le32 *)pdesc8; - dma_addr_t mapping = dma_map_single(&rtlpci->pdev->dev, skb->data, - skb->len, DMA_TO_DEVICE); - struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data); __le16 fc = hdr->frame_control; + dma_addr_t mapping = dma_map_single(&rtlpci->pdev->dev, skb->data, + skb->len, DMA_TO_DEVICE); + if (dma_mapping_error(&rtlpci->pdev->dev, mapping)) { rtl_dbg(rtlpriv, COMP_SEND, DBG_TRACE, "DMA mapping error\n"); -- 2.17.1