Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp104127pxb; Wed, 18 Nov 2020 17:54:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJx15Mk2W11sjO42+p370ZtmuiuwztMFuunHjHDentVQVYGBHiFhBoycYk1tXG0AcBkllDhh X-Received: by 2002:a17:906:3413:: with SMTP id c19mr25684573ejb.421.1605750864107; Wed, 18 Nov 2020 17:54:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605750864; cv=none; d=google.com; s=arc-20160816; b=OHtVdKIgESPw5WaXUYd/sZk82k587tmEgxMJZyPV5XGppkW9CNsf2nv9BdFStHGhCr 8M3Y2g3LIlgIEjfim1sp0zqzY7Uc9HCuxuH9O+47plkertTSi6Hu13S+SNvfbJ73L0Y4 pMpONbf6gEKLv6AElv4rPMtHAzg2VVw1krtA5oix7x6RgYdLa3fWbBSX/l688oEymSJb vXre3TMPvwKXqTFgS6Qg4n6h/G682MCTwdawYkxyWxifsfz5cg/X1xDKvIzwwAowqUIc wf0esQZz39tek8XqFR6sKH41KRnWp9WQpGakeWmDITfb25I5uLDLPjqPWGVBcwRsQdcs YLVQ== 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=9025Wc1+t1+Asl4+HE2JiiCcXuZsf9kAEp5Y/mjiQ7I=; b=Ie2E5tbjh6J9w2aUZKzeFmd8u2y5PiAkNALpmqhaGFnFBqSOtnEr1RdJQhAE3vAWOt LEkkVfMvYiZW8qT22v70fKCYyveorHotNyr5kfWacYgI0XAT7oOKfv3MiyuvHVrmHDPV HmxRT9V2nLK1R4rDXPXrgf9An8o0k4lSND3wbL3sC+ZXpuBASTCElaMgFrGtuk5aB4V7 eAGfrQONnAmKWUqdzHQ34WNqFtSeKJRI374PCmgIWszFmIvR0UsLkECQgJUucJ75bdSc WSL6tuhuKYWP5gx4BpScdF824SS0sRWdjnKLULr/y/9dr3yQjsPvKA4nTk6wJUfM/6h5 ChQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=at1kCgQJ; 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 a16si15804507ejd.678.2020.11.18.17.54.00; Wed, 18 Nov 2020 17:54:24 -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=at1kCgQJ; 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 S1727621AbgKSBwO (ORCPT + 99 others); Wed, 18 Nov 2020 20:52:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726413AbgKSBwN (ORCPT ); Wed, 18 Nov 2020 20:52:13 -0500 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8681CC0617A7; Wed, 18 Nov 2020 17:52:13 -0800 (PST) Received: by mail-pg1-x543.google.com with SMTP id m9so2762939pgb.4; Wed, 18 Nov 2020 17:52:13 -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=9025Wc1+t1+Asl4+HE2JiiCcXuZsf9kAEp5Y/mjiQ7I=; b=at1kCgQJTObwy+2jmdlGcjwCXnikQgSV4v9IToVIQLPzLOrm5dSm8lc9gDsISjJpoy kq4DbGbvQ0xnuRXX6nyMsAGyPuEpuUyewplrqz1fSuPaKofSELvTLTw6E+g1SjQbXPac CzOxnVHGN/IUkgzigWpAVtQ2SQaPNHzsudK009LbTx9t+BaoD3E2FR3GvjLjqbRLGUDr EF91MyNDe5Te8ikU5YxBWPft5RiojerqB934+BjIuPUNh2L2I1kfIlwJUN+xSs3bS+Ze R9lqmbFLPCGqHVr7uSpUzku4tRxQOkPIMwdCZUnD194tCquZ9l5UwwaR+BU2nJErxn1J E1YA== 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=9025Wc1+t1+Asl4+HE2JiiCcXuZsf9kAEp5Y/mjiQ7I=; b=D43soLDih5auf9lmFmGJXMtsHZkiB2+oqDAuDonFa8meLnz4siP/HBvFglra16zZgZ e108XCol5Uu2osq/eW5SUtcDt+NY+bEy8CYoWx5rWmWSJ4o2L2uTawYv6DwlG9NE4LL0 CdCDhWIjjUegkfBP5KhYjtvw2euEsOZbpVETiI8P0rmjJ7x0ceD+XQjb2Jc7vjxBDE5p RSDhbDVgbuZ6d0bb16KfjyX9vez5YegBLLv1dbxnFd0DkJOz9KA04qz95usG8PBz5ssZ es0Ei8Lrh4jqHphCtnNmhaaDf6tGtfaZzrTR4PCIRVpiPV2UJquGqRk/qdct8oD7AXZ6 sAPA== X-Gm-Message-State: AOAM530oVuMTGBctJf5AKGWRgweSY1IcFJwHIbSfp1UUWSRqpVYbSX+a M9p6T+DwUObof+I9mn1wYYw= X-Received: by 2002:a17:90a:fa04:: with SMTP id cm4mr1815855pjb.24.1605750733194; Wed, 18 Nov 2020 17:52:13 -0800 (PST) Received: from localhost.localdomain ([45.56.153.149]) by smtp.gmail.com with ESMTPSA id o62sm4038168pjo.7.2020.11.18.17.52.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2020 17:52:12 -0800 (PST) From: Jia-Ju Bai To: pkshih@realtek.com, kvalo@codeaurora.org, davem@davemloft.net, kuba@kernel.org, Larry.Finger@lwfinger.net Cc: linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH v2 3/4 resend] rtlwifi: rtl8192de: avoid accessing the data mapped to streaming DMA Date: Thu, 19 Nov 2020 09:52:05 +0800 Message-Id: <20201119015205.12162-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 --- v2: * Use "rtlwifi" as subject prefix and have all rtlwifi patches in the same pathset. Thank Ping and Larry for good advice. --- 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