Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp4311497pxb; Tue, 17 Nov 2020 17:56:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJyMADavMMGpF0VIacI8rP8jrjD9ad8PO/mQMXiZ0xwBTC3Gkx/sZ1KRJdggugTKTX/xCROw X-Received: by 2002:a50:9fc5:: with SMTP id c63mr3253412edf.224.1605664607652; Tue, 17 Nov 2020 17:56:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605664607; cv=none; d=google.com; s=arc-20160816; b=fNpjQhpKPDfIwuzj3S+2ZBJsF8ln0y/U42tH1dxJmw5rFQhGT7ZlJ9mQSEkUFxNS2a N99Q+RM7YqbdDKvZxLaWZoa4aXFpzVbyrSuYf4UJqKp1lO+ly98t2N9kr9DHzOk8NSyQ vXrcgjHAAcmmV+729D0JW19nlXf4Eomt8aGlqkiwAkVAF13A9K82D3rGBn+zpFHP9udN NtVpK3sJCFokZm5ET2xY1zqSD6nxMURxMj3QvrOe672/Pcw7bnsdrzcN1mfIPzDNQbek 5vHuwxwmL5deYRkSwLC7ARpveVKK+Uc0DHkc9fklbBCM4vG3U7DmU16QRPM8/IViLwv1 GXSQ== 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=+XVQiLhPjTZQE7BJhiPhjmEEz4RW+ut2EJwMRL1LH18=; b=Fhn5MbJ0blWGwLcSklEooDUNEYlhZ4uZc4hDAdP/KfQ0Z6pOvjuTfN9OqnX0D11IaM 7AlbSO2Q8Tmu8+TWS0FT7awCxxAkf5ul3OynJ5mveyS+dfSphhq/7A0VwR3sQicwpEA8 o6hvHvvJB7aAu7QbwUqIqY4t3Qiu8Y93Go9CPyZdwgq0xWID0a5xjU4C1H3M1UWrU8um TFuKjGRREnsSCIVZu5c0zQl3lXfeScZAVbjQmfqAzFV9KFwnxBwTHvHcwU59c0QSFhI8 sWKlgh29dNjse+VCiGK4KXwAccIhNlM5C28dk1XctOig1yb9eyNQS3rjSOqfP9GdO5g9 LJnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=LYfvQ9lI; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-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 x18si2012884ejj.520.2020.11.17.17.56.24; Tue, 17 Nov 2020 17:56:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless-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=LYfvQ9lI; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-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 S1726993AbgKRBy0 (ORCPT + 99 others); Tue, 17 Nov 2020 20:54:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725730AbgKRByZ (ORCPT ); Tue, 17 Nov 2020 20:54:25 -0500 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DD66C061A48; Tue, 17 Nov 2020 17:54:25 -0800 (PST) Received: by mail-pj1-x1043.google.com with SMTP id h12so214963pjv.2; Tue, 17 Nov 2020 17:54:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=+XVQiLhPjTZQE7BJhiPhjmEEz4RW+ut2EJwMRL1LH18=; b=LYfvQ9lIzEjwOb1CVUstMO/UfVPBBhU9xlsaQopp0IGnfbV4Ns2JSr1z786oJYHYri bd/sQt7CeWlUhRUP2iuTNjA2q3DTgGNdu8K+Lr4WrnPhR6VooyuhmbQ8MjeKBwAXpP54 sT7jT9QQFhWPUubPbQ4bzoIDw0tFntnsYMlmdxwxnmx5KWBfcPhr4j0a4KyJ5TpRLyGh pb4BP8ZUKMZnpzVjOrU/HoibDwgXmoAzg3z3k9oCENcDzGPLoSQ4B1KAbG8jU5AYoNcZ vxMEzjVQxkLNmFF31YrKaWebKf5bULIkoi4HTRcOnwXSBZWogjwc7a6+DVG5dljM2Xti GcTg== 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=+XVQiLhPjTZQE7BJhiPhjmEEz4RW+ut2EJwMRL1LH18=; b=Xf/X+CJ21ILwqjUC4pwWXW4XESU5O49LErf9l/XKcrGraxcRnQE3wNDzXbCL9R4SSH pvaSGvzyEIpppkpwJWwP0Ljv56qLj8mjRsXeRUUfVPicKWSuiSErQKbFqaqk0qi1aHhE 4TQ5HfxVq8c9KKTDFXUsbyQGJ8JCIa7VybWJrdVHiSq8PkPMs9Bc9HMkWB/OCVMc3Hxx eVu2+rk1dw8yi2q6l+vm2+QO/hrhiY6yqTyAbsAOScrgIDoep0hsfBZwn5NEDaF8GoPS C3rYH/7Atk3VO3f7NlDbFJPxOrFwjECtpQNL1M7sM5c6ZHfo9Bff1ec/xOrbiKYD8OpX UH2A== X-Gm-Message-State: AOAM532ujmU6k8k528o5XLX5wfKSRkBATYImZG9Y/2aJagHpZXks6XI8 aReCFYOebBmvLTgttaXQ2Ag= X-Received: by 2002:a17:90b:241:: with SMTP id fz1mr1835713pjb.172.1605664465091; Tue, 17 Nov 2020 17:54:25 -0800 (PST) Received: from oslab.tsinghua.edu.cn ([166.111.139.137]) by smtp.gmail.com with ESMTPSA id w70sm22402883pfc.11.2020.11.17.17.54.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Nov 2020 17:54:24 -0800 (PST) From: Jia-Ju Bai To: pkshih@realtek.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 v2 3/4] rtlwifi: rtl8192de: avoid accessing the data mapped to streaming DMA Date: Wed, 18 Nov 2020 09:54:18 +0800 Message-Id: <20201118015418.5122-1-baijiaju1990@gmail.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org In rtl92de_tx_fill_cmddesc(), skb->data is mapped to streaming DMA on line 667: dma_addr_t mapping = dma_map_single(..., skb->data, ...); On line 669, 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 670: __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/rtl8192de/trx.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192de/trx.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192de/trx.c index 8944712274b5..c02813fba934 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8192de/trx.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192de/trx.c @@ -664,12 +664,14 @@ void rtl92de_tx_fill_cmddesc(struct ieee80211_hw *hw, struct rtl_ps_ctl *ppsc = rtl_psc(rtlpriv); struct rtl_hal *rtlhal = rtl_hal(rtlpriv); u8 fw_queue = QSLT_BEACON; - 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; __le32 *pdesc = (__le32 *)pdesc8; + 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