Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp103697pxb; Wed, 18 Nov 2020 17:53:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJw83XewyySByK2PnzuSzJgpnJ5Zz26ReAOmExHHCJQDe2Jk2qpKtIhKIEH2uxK3B2ag9Czf X-Received: by 2002:a05:6402:114c:: with SMTP id g12mr28517040edw.167.1605750810547; Wed, 18 Nov 2020 17:53:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605750810; cv=none; d=google.com; s=arc-20160816; b=Y078kPKRVFo6/QglRYP3bAE0+95Um2Imzcem0S7y7wglUUJC9VXE9jxb2s3y/4iZlc Py352kPd50mMIoaoQmA7ghxQuR2lUl5eE2mAtclBfyvQ97V92Xtn6poQHVfF1qftAsta 05kkD08tvmnK0zkohiSLDaeSmDPoM+KGAYALa0tCyNks5c67J53glhQl+N3oPIWI5W3n JZ5h8RMtVAbQV46PKcyajd6Er0QORIkPsnTKlWeSoAm9zhdL5l5yioFeHcGjAOFsm62F 7dec9BVqvdKEwUWv/cnqagv/8l3ulswGg7Mizixz2YDVqWNItRWfokcb8fg0xBK39aVE nAIQ== 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=Lrkjv0IBlzMwL2dF9c7iw3uUdxBLddCoE9twLMsxPXo=; b=ac/BUhbK4Kun/lyVJV3lkN80stVgxjjoZABam3ow/fMAPe9BSc7iKxHP91imUsCTma mSiwzvPoZk4IAzudQUn/XfBZrgCeTwgvWLs+ldBmrpbzyMTgVho4Z3tRL+RN9/D1oJXR n7ZN7lp3fgvEESe4XdOrFiPRwBct/BEM0tbbbp5Tx8WJDcC9drD2erynwCPuIXB4OMK9 cF+3H67JGZSFL9H6kPfR9sHvl4H09lwT6dKZxm/m8GuHb2GZ7b2hwKW7YVjEh9i1mr6h ayggQSZRd64csosTAwwyjuexMjIrVqVxgzVplHSkmvb8IC5JFl730PPv/adGuUi3OPCG lbMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="ajV/Z+fh"; 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 c11si2378213edy.463.2020.11.18.17.52.52; Wed, 18 Nov 2020 17:53:30 -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="ajV/Z+fh"; 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 S1727478AbgKSBwD (ORCPT + 99 others); Wed, 18 Nov 2020 20:52:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726413AbgKSBwC (ORCPT ); Wed, 18 Nov 2020 20:52:02 -0500 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F608C0613D4; Wed, 18 Nov 2020 17:52:01 -0800 (PST) Received: by mail-pf1-x441.google.com with SMTP id w6so2931723pfu.1; Wed, 18 Nov 2020 17:52:01 -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=Lrkjv0IBlzMwL2dF9c7iw3uUdxBLddCoE9twLMsxPXo=; b=ajV/Z+fhiyNanIOxETfhfJLaJYHu+1oGRqUi3qlpaKI5gFOLbbEs72B5mWjPHClM0k OxRw427HObo7ge9kr1+jvq0gJQtADcoDfoadEalIpdqXTKU9dN7XCkWzPPQ74KrHjfq4 loy/w3NvIUDCctLNfJ8WNmSVyi37D+9VUZBbUMg9kEp6bKt9m4HxiwFWE3oA2aW8xe3e WITAKDZAj1qsHC6N62QZWBOZzXAhR/gtkdT2AZM5CDlVlqbD2EzBgt2NDGpFi8GqnmEy LdCCAlSVTAvJHqiHbuMYr9ajlgL0zLMRscoVdBmeRDsWTPFSr1j2cTT85J3mSboDB5wu nAxA== 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=Lrkjv0IBlzMwL2dF9c7iw3uUdxBLddCoE9twLMsxPXo=; b=R4xpkYnsjsO0m7hY0TW7zJnjyI9itC8UDrLbbCyG/K3WG8Orm91Z4/Sowyg3fb8Izg iFdhgbZ0Aaukqv711g7FdGC4ijLfpWgwlFhogSHpMeJcWHOivwDiKKEBCS4/t9ztEhVS x5HlIE8RdE1+h8SWDrczEvONv3ryN2P80p99DqiNns/h6rQwYRE6oTEyqqHyJvVnhKvV 71Aph4u8YIQwETDOMh4wIM4Y8+BwdsbJeZm8MvegIP0P09PdJduc39L6OUlGxLDCzuxS 7OYOhR60aHN6VJBCszVyjQfjtsQUigvw92wNHZOG6t1LeKKamVCPx9U/rpwMQ5ryjhib novw== X-Gm-Message-State: AOAM531EIW0oB1LR2oPS5tSEHxClWxSq4pU/N+Ey8RpsX+eoeZy9nZdY nryvVRCqU5KN/PsJKqtM9LA= X-Received: by 2002:a05:6a00:1684:b029:18b:665e:5211 with SMTP id k4-20020a056a001684b029018b665e5211mr6947014pfc.20.1605750720578; Wed, 18 Nov 2020 17:52:00 -0800 (PST) Received: from localhost.localdomain ([45.56.153.149]) by smtp.gmail.com with ESMTPSA id b1sm9799308pgg.74.2020.11.18.17.51.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2020 17:51:59 -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 2/4 resend] rtlwifi: rtl8192ce: avoid accessing the data mapped to streaming DMA Date: Thu, 19 Nov 2020 09:51:51 +0800 Message-Id: <20201119015151.12110-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 rtl92ce_tx_fill_cmddesc(), skb->data is mapped to streaming DMA on line 530: dma_addr_t mapping = dma_map_single(..., skb->data, ...); On line 533, 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 534: __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/rtl8192ce/trx.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/trx.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/trx.c index c0635309a92d..4165175cf5c0 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/trx.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/trx.c @@ -527,12 +527,12 @@ void rtl92ce_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