From patchwork Wed Nov 18 01:53:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia-Ju Bai X-Patchwork-Id: 11913765 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 20E0BA6A for ; Wed, 18 Nov 2020 01:54:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E853E2151B for ; Wed, 18 Nov 2020 01:54:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iOOTgarB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726205AbgKRBxx (ORCPT ); Tue, 17 Nov 2020 20:53:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725730AbgKRBxx (ORCPT ); Tue, 17 Nov 2020 20:53:53 -0500 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C634C061A48; Tue, 17 Nov 2020 17:53:51 -0800 (PST) Received: by mail-pj1-x1042.google.com with SMTP id js21so219902pjb.0; Tue, 17 Nov 2020 17:53:51 -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=t5eReXO4wqmdOiCBF4R3AZcbfxasgeFRgSN87jtfTOA=; b=iOOTgarBSRRV3nOEIu7RPO2lJzpE7H0bWf/Qkv32Dwl6ecP2lZqAw7+9hfCztF88lC His2eJEuigwDBhcb9hfT6xTOzQiZwORJCx67+WrAQGLSwIqpWOuZ/VX6Gh6/HkC+2aRq KEf67tHBbfprzTe+J1pEJQbnO6bdDHVf8SoIy2krfHhWsaZ31xIe7HbqPdAt534yxBIe DbP/bXXy27S9bOantElC6qzqEDgBXRGKel3B4MOdILOz7TODEmn06lLxC4+eOiJz3JR9 y/M1GrVNQgxFTVtVuQAs7lfPhQVHTUlB8GTpqHKICauG/J6euAUjJMSbS1Jg1NS//FiR Y9gQ== 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=c3Sd/NzeGJwMwNE5NgxeHweviNkDG1Mz7ejc1gHyTzlIBa92mpQ5EG5WUeM3X78fPm Trn1lSpZj4fWJ5ZYWxUk8AZKhDZ6ZjNJfDNSjps8pwZD0FYaH8t3TE6ComU4ppeExNFe 72yKU/v/ZkWmU73TDs9s+ocOhE3ouXa0M+sB8EMtKoXAg6zdk9DNOtmEnwX1Euka4kp0 ReWD08ym3PLE2jvjCDITvKYxk+4WMMNx7GyjF2MkWGre9ykCAcdPaHljSuJ+3AqaBZMX i91p3NV9YPq90+diHdP3jtPm2vZzTTBnmhrlsNmy1omoxjWvTU5MM/9J9tR0eefdZphR BqTw== X-Gm-Message-State: AOAM530FjbTsVYtaLZkXp+p5O4a3skc5JhJzoakufqJ0pM8dp8d8z3Fj IiO3zw1jQGBofqNFJfSr4i8= X-Google-Smtp-Source: ABdhPJxTtKOhfudWJ+Y1l0w8jEU3rSWDhUb1E21+wQSdIi35mopiq4+sofDFLHqLhSuaxds8II+/Lg== X-Received: by 2002:a17:90a:f0c7:: with SMTP id fa7mr1876767pjb.3.1605664430920; Tue, 17 Nov 2020 17:53:50 -0800 (PST) Received: from oslab.tsinghua.edu.cn ([166.111.139.137]) by smtp.gmail.com with ESMTPSA id t32sm21430494pgl.0.2020.11.17.17.53.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Nov 2020 17:53:50 -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 1/4] rtlwifi: rtl8188ee: avoid accessing the data mapped to streaming DMA Date: Wed, 18 Nov 2020 09:53:14 +0800 Message-Id: <20201118015314.4979-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 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 Acked-by: Ping-Ke Shih --- 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"); From patchwork Wed Nov 18 01:54:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia-Ju Bai X-Patchwork-Id: 11913767 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4696A14C0 for ; Wed, 18 Nov 2020 01:54:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2352A2151B for ; Wed, 18 Nov 2020 01:54:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iiFu2ayh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726719AbgKRByR (ORCPT ); Tue, 17 Nov 2020 20:54:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725730AbgKRByQ (ORCPT ); Tue, 17 Nov 2020 20:54:16 -0500 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4D84C061A48; Tue, 17 Nov 2020 17:54:14 -0800 (PST) Received: by mail-pg1-x544.google.com with SMTP id j19so103240pgg.5; Tue, 17 Nov 2020 17:54:14 -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=kE2vWbri16fQXY9rpZDoR0E3WjS1MfyWuTMn6iwlvi0=; b=iiFu2ayhZnskDuDsAvBIsBT9XoHdbAP5FCqNxNZEshQQTBwoK57TUH7I4nwEPs3yiA YcZtjmYGNovytP0200S0c5iIfLjKAJzGDjJ3aFtU5WCrhxWDKfng1pO0Y0XnFLE2BWgZ /X44f7HDqpaQNkJBIXW/abwxdvuLcK4OYn3UHX33TpSDzhXhCvgRB6Mejbxiz3qHrHS6 hwXWesxEaTxrHWMwtLOcOndeIjWPK09Qps74dBJxf7H9PyvpYA7wM7gCaluJJUDkBkmi t7DkpSYOlICkVc8llYIkf5R2aMZ8NtQwmOMZ6Gu70o80Im+Jsobss6+Bq4rLyUdb/dRd ifqw== 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=kE2vWbri16fQXY9rpZDoR0E3WjS1MfyWuTMn6iwlvi0=; b=HYKZgPxGYx3mDAQ1C76opSvZYVIihL2x4X8ZvTXyR7faOzDXMbZ8VXdCdkz7FTxlsf OvU0Nw4jkB5DEpaZ53H49BAugjgvxCNE+TH6efFN1u4xi/Hj2q8SBYIJi1f406NYyFh+ K3e1qQ1Wax/aCE16hgcYkt2YwdhArIdBGNz7IauCqLfRh7dV/VCEKknEHK7Gf1IVeVVo EciDija3gQb9Mdn05T2REWCUf8lbagzb/q5B/DjPDqFfGXu8026rRa4A80VXaXfYMZtu eZM77bT25xBXU/JhNyHod3Mbt3+896bl2VV81ugx/HmzrwkUqoCE39+DLgN8N1gM+Gto QiyA== X-Gm-Message-State: AOAM531pTPyE0VX7b1x0chr7LiaSriPdm/bahyssMvk+7vVhyLk/ee+G 7ciGHXVLc7mqBGL4l471HXLBzEJPFJH27g== X-Google-Smtp-Source: ABdhPJwS8sEN4T0K9UeLEWD5OYJsN/8uWi/+Ml/mDUWddf454R3fQuAuhsXE55kA3Homy5+gJvdjvg== X-Received: by 2002:a05:6a00:8c4:b029:196:6931:2927 with SMTP id s4-20020a056a0008c4b029019669312927mr2233801pfu.56.1605664454506; Tue, 17 Nov 2020 17:54:14 -0800 (PST) Received: from oslab.tsinghua.edu.cn ([166.111.139.137]) by smtp.gmail.com with ESMTPSA id v23sm22617513pfn.141.2020.11.17.17.54.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Nov 2020 17:54:13 -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 2/4] rtlwifi: rtl8192ce: avoid accessing the data mapped to streaming DMA Date: Wed, 18 Nov 2020 09:54:06 +0800 Message-Id: <20201118015406.5063-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 --- 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"); From patchwork Wed Nov 18 01:54:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia-Ju Bai X-Patchwork-Id: 11913769 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7A2F917CF for ; Wed, 18 Nov 2020 01:54:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5820D2151B for ; Wed, 18 Nov 2020 01:54:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LYfvQ9lI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726993AbgKRBy0 (ORCPT ); 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-Google-Smtp-Source: ABdhPJyrs5SICFqofuIp7QcyHMO6bgLTzwDISjnQhdiB0ni+j5Egq/Zs1vhmZIq9KxyPBGyQVVw4Sw== 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"); From patchwork Wed Nov 18 01:57:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia-Ju Bai X-Patchwork-Id: 11913771 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5BABBA6A for ; Wed, 18 Nov 2020 01:58:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3804324248 for ; Wed, 18 Nov 2020 01:58:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="s5xp+g5k" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727008AbgKRB5t (ORCPT ); Tue, 17 Nov 2020 20:57:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725730AbgKRB5s (ORCPT ); Tue, 17 Nov 2020 20:57:48 -0500 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99215C061A48; Tue, 17 Nov 2020 17:57:48 -0800 (PST) Received: by mail-pl1-x644.google.com with SMTP id d3so138498plo.4; Tue, 17 Nov 2020 17:57:48 -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=4a7zDL5lInqafK1HE5+sC1LmnDT92uD20FAhjTWB/2c=; b=s5xp+g5klPD2WapB/Q7IK1Z0TXAqCLWSgcMGccoj/cwiZX3HzKsIMb3rnXdjbL/8+r bvJCXZ0aH/lQj6Fgj3HCqo67qe3b/ZUEMWVkh9sGwq6S06hVwIY3gS8jlrXfJWKyCcop //lIEZNIXniuq4adWq2IPzDaLGQVnvb11jNu6D0Fr1AJRyWUnNn3Y/d92pycNfkP/XPl xLJltjv78d2xuE5b7q9x5Fk8a4ZP6ZywChYNAKdWw7OgLWluj6SUUWmCituDbv5DZZcA 6gJ6ZjTytgQgWLAa0FglUj/nr6yrTkiwEoyY/UtCJF053gBAqFuk4auJUQnCX9Udmb0a Kq8w== 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=4a7zDL5lInqafK1HE5+sC1LmnDT92uD20FAhjTWB/2c=; b=fJyJfwE6cB7A2l/orPBM5sm+aS3TW3A00lGzy2QaINT9PBGLKcZCbeM9cvxy2UiYJH 6091mox8grK8zoNZp6CUHNMJmD+ZYl7Oekq36YGot4TtKvZg47iV8rguM6qKtuOtgKIy jzSu+9JOu1VsaBJXQDg4BXD3eTHNf2fMmXtd2xou5n0peHomuzscXgJepakuEwUKl7c8 AplsBeKWoaGPwolL2Ga7J1n1PsWyZ0AnKOKTFLoRWezE+frIc5xwAtcAiu22OB7XG8P0 gATZsaMMpF90Tg1Hgj1ipsJyRnuX7LPcnh/YTCbOJC65LNgE+8NkdodFcuSMT+8QvYHB X4Qw== X-Gm-Message-State: AOAM5331ySRCv5xqJ/CGyWadwzXWH535IeTcu3xo3F+qSOjAWElcRrBU PLkshSUjtkDXtCsz5RRVwBw= X-Google-Smtp-Source: ABdhPJw6aJl7AaGR6mNa5ccupT7DbLlBABl/RTfldgoA3kMAQHzcLZmNZqpt992LoKTSIEWbRGo/lA== X-Received: by 2002:a17:90a:e016:: with SMTP id u22mr1935038pjy.54.1605664668234; Tue, 17 Nov 2020 17:57:48 -0800 (PST) Received: from oslab.tsinghua.edu.cn ([166.111.139.137]) by smtp.gmail.com with ESMTPSA id e201sm22988444pfh.73.2020.11.17.17.57.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Nov 2020 17:57:47 -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 4/4] rtlwifi: rtl8723ae: avoid accessing the data mapped to streaming DMA Date: Wed, 18 Nov 2020 09:57:08 +0800 Message-Id: <20201118015708.5445-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 rtl8723e_tx_fill_cmddesc(), skb->data is mapped to streaming DMA on line 531: dma_addr_t mapping = dma_map_single(..., skb->data, ...); On line 534, 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 535: __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/rtl8723ae/trx.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/trx.c b/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/trx.c index e3ee91b7ea8d..340b3d68a54e 100644 --- a/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/trx.c +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/trx.c @@ -528,12 +528,12 @@ void rtl8723e_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");