From patchwork Thu Nov 19 01:51:27 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: 329660 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C83AAC63798 for ; Thu, 19 Nov 2020 01:51:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 678D4246B0 for ; Thu, 19 Nov 2020 01:51:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="B68UiTUZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727395AbgKSBvk (ORCPT ); Wed, 18 Nov 2020 20:51:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726413AbgKSBvk (ORCPT ); Wed, 18 Nov 2020 20:51:40 -0500 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 762F1C0613D4; Wed, 18 Nov 2020 17:51:38 -0800 (PST) Received: by mail-pf1-x444.google.com with SMTP id y7so2890137pfq.11; Wed, 18 Nov 2020 17:51:38 -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=3r5FZrPv+WHArPH9yqncOxdfTiMaYsbEsDIytgtTf2k=; b=B68UiTUZfXssmJtMqOe1VvpB4J8RMb+KXeHqyINfBPaG9OGRrl9a3ALtiPByvZFTcy R7CUYBAq4tmfgEzDBc8Sc0JnIe1obvw622jeEDHSuh8E6FNqVWB0kXo9ABMY6XRZ707R XOflQwYUMSm2U9uiJelSrw1Q22h+ZCRUb4dyWx8jGQ++bdQ1fM2io0rgxAIGCvdNhgLV cYxu4ZZIi++mocXnbuOvRUMq+h1/YQn5x6fErsAqbXnFonqwQVnlgPtVQEsQ4qJSs7SS I0b6i5jXM7IZ0TSbzDAbNOtMboVrUSuJbeMeU3CDB3aqexqtCxhUGz3w72suGnqZ8HBB M41g== 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=3r5FZrPv+WHArPH9yqncOxdfTiMaYsbEsDIytgtTf2k=; b=ldYXqNNeM51KB0tzQwVoaAOkdlg5lv4U3YV+lDydwon+6n1KlP4FgEJmUJHVrTmsHJ PuJpaAH9rYhGGUQwgc88zS66geVBvNG9wVW640tyIjToMeZ65kM9/ikgI8K03RUJevDy UKSHAs8taMI1agbswFDKhfxsUl8ZY4L9gL1s7y5Cbp+NHXg0Qg7zqxQ2XdhqM8AZ11U5 5NP4Exlrhfixp/n9S9pb7sbQlFFu6JGDaEcuyrrEVCO9AGvTHUVabjXnisxfS8IZwnjY MF0YYDMD+pNd+6kDpj9ouCRZu6Lvn6CqS/YFPXHNcSlSoTYYQ0JrjoWe3uED2v2mgUa0 F5HA== X-Gm-Message-State: AOAM5317B0en3eD3l/0pWR+MLMP+37Uu7s6V//zEc/WlUDh3DPSm3AWo WYC7MIGBZ8FHG17zUnOAlcs= X-Google-Smtp-Source: ABdhPJxn1hPFjguU/lx7e1TERyJiuCSd2U9KvvRdrHXrqmCBn6zNigbbZIltJmjpFG3kOv7JBO0UDw== X-Received: by 2002:aa7:981a:0:b029:18b:490f:77d9 with SMTP id e26-20020aa7981a0000b029018b490f77d9mr7033443pfl.46.1605750697927; Wed, 18 Nov 2020 17:51:37 -0800 (PST) Received: from localhost.localdomain ([45.56.153.149]) by smtp.gmail.com with ESMTPSA id e201sm27003636pfh.73.2020.11.18.17.51.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2020 17:51:37 -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 1/4 resend] rtlwifi: rtl8188ee: avoid accessing the data mapped to streaming DMA Date: Thu, 19 Nov 2020 09:51:27 +0800 Message-Id: <20201119015127.12033-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 --- 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/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 Thu Nov 19 01:51:51 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: 328910 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3684C6369E for ; Thu, 19 Nov 2020 01:52:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8CA83246B0 for ; Thu, 19 Nov 2020 01:52:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ajV/Z+fh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727478AbgKSBwD (ORCPT ); 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-Google-Smtp-Source: ABdhPJxO8eA5HqG71Zp8OEePb2qToBb3iQ+7QEwSvpJmyRzGwheiB6FSeLPerEjOpyAvQ3/G4hF74g== 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"); From patchwork Thu Nov 19 01:52:05 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: 329659 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01BC6C64E69 for ; Thu, 19 Nov 2020 01:52:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9B192246B0 for ; Thu, 19 Nov 2020 01:52:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="at1kCgQJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727621AbgKSBwO (ORCPT ); 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-Google-Smtp-Source: ABdhPJzICtfYjpI2GQXdBLTyYUvqqtGVGQDEQFhVQmIYp6gzD2kN/3XYB3VuQyBHlPbYZo6seRxoXg== 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"); From patchwork Thu Nov 19 01:52: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: 328909 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0BA3AC64E8A for ; Thu, 19 Nov 2020 01:52:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A7EBA246B0 for ; Thu, 19 Nov 2020 01:52:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hiJ1JsBn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727695AbgKSBw1 (ORCPT ); Wed, 18 Nov 2020 20:52:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727265AbgKSBw1 (ORCPT ); Wed, 18 Nov 2020 20:52:27 -0500 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37874C0613D4; Wed, 18 Nov 2020 17:52:27 -0800 (PST) Received: by mail-pl1-x641.google.com with SMTP id s2so2061435plr.9; Wed, 18 Nov 2020 17:52:27 -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=O3ThiUwvLYqwNqLXRXRAUrUNjVW2CgIY+DR5znXz6Ck=; b=hiJ1JsBn/XfhJvTqOg5P+dJhfHx+stklBu/B2NHegIqQsB9wnc2pQk/h8lYQ3NIOvW vqDpbL1dF+2kaESBd2miRG232EAgJVT/BK8ptTrePs0lONFzRfewbt7f00PxujiLtyOn bd2Pf9vSrr0gOfcxO+Em7ut9u1ViFzrw0uD8f9iPqIHAujRTg9Yh0tj4kEosj2u1N8t1 3pxhHQymoAb6XZd1xtrAsBkr5KkYQZuJZVz8cFSVl/dqLYMwai+jP/hHZ5GtosnwTdpx HACeMLml3N4jCBSZ5JDlFBQ63CZgB6io2axKP9tI5XDIeAqx6R808vVdLQ8Pyj1JuN++ +J4A== 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=O3ThiUwvLYqwNqLXRXRAUrUNjVW2CgIY+DR5znXz6Ck=; b=MunXofqeX16ntKLI8lsyBd2L/btu3auFAcNpOKCUVqmsnxkKdem+k0L8T8GX7sBxJH 8uR/U7RFOGVnbE1OV4J6mj6Ghi2hQqDycw9x7wDI4Fvw9L3It22nY/VPtWkc4IH5/q7f 8ltArNjFBTNh20O6ynhUHQ/A5vFh6QopTfgAjCnswT7dH5id6ZHyrLGP0/BNqQEpzmFG tTFNaBrfyqrgNyfITQAwwNM08WLZ26+njSeT7OPH7MyAYzN07nRCuB99dRxaroujR8L2 2zus+bMd77aT+AWmnbC23L9YKAAiJklpXSdvT8QA9a79x7e3/7wrHh7UxR2XIXp3ngmL 0QZQ== X-Gm-Message-State: AOAM533TnfFgdiX4lfYDMWTopjpLuNpvpTS6WWWapBDaemouoRSp0tfk CaL5UYQ6U8EdjCw4f0ehoEz9oXDbfyxfrQ== X-Google-Smtp-Source: ABdhPJywqIvy+2ZVL/7mOsL29r7EzB+mlhB406Ko6cPrwXDRr0gTX3vUKy9dCGxgO3W2gaNBUi1BVw== X-Received: by 2002:a17:902:9f90:b029:d9:da48:6021 with SMTP id g16-20020a1709029f90b02900d9da486021mr600256plq.81.1605750746645; Wed, 18 Nov 2020 17:52:26 -0800 (PST) Received: from localhost.localdomain ([45.56.153.149]) by smtp.gmail.com with ESMTPSA id r3sm3976638pjl.23.2020.11.18.17.52.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2020 17:52:25 -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 4/4 resend] rtlwifi: rtl8723ae: avoid accessing the data mapped to streaming DMA Date: Thu, 19 Nov 2020 09:52:18 +0800 Message-Id: <20201119015218.12220-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 --- 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/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");