Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp4311103pxb; Tue, 17 Nov 2020 17:55:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJwlDtJzVtnThxyf/6lxIrV1ToenDLjeUF81+JrFx2o92iM0gtWZ/JpUciNRquYfJvv1B62S X-Received: by 2002:a17:907:1008:: with SMTP id ox8mr21388372ejb.189.1605664550751; Tue, 17 Nov 2020 17:55:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605664550; cv=none; d=google.com; s=arc-20160816; b=ktsU5um0vDba8X2R1zuTQ+IIpvbfyDlllOa4OfgzpZC7DYek3MF/stxQsiLFSns3FU 84dTnyVO5BDRMU6RIh4VXs+S2n6qCx5DA+6xca0kU9EjWDIOBVLeLRRGtuMbUnK9nYYd EslqxbbdkPjVAUmgSzJUhZn5eno/D6fhBfaymYWoiSV1xqxXNF0g7ASJhP4UqjHR+IXP TEH+wi5YDlB3NI1LEpTUi0EhuIUqJIhvw1H4losK2Y7TbZRwMXQqxu3MfXE9Tndofn9p ECMW44W4wTW8gTxhH1rksdwEM/J/0kLdTVf7y+XxqIkBPB8nv87SDQiviVF4/S1aJO65 o2/g== 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=t5eReXO4wqmdOiCBF4R3AZcbfxasgeFRgSN87jtfTOA=; b=xyBIdW0BBFKmXcPJgYikmtCWGXj19rVYcM2wEiygMLxV81Iiz78rZBQ8pVIz/6SGPn GoRINiR22y7RDJuSPpOW8SKQ5cpGNJf74WBvNrFauLYcUdSHlXBg98vogcoHdkTr9teB +qLfT8+0X4hHpJeQrl97PtXk/ewP4+JbQW+awZvTKqI1lqoHSnM+ZNq4zkdqjsR2MLVo 7V0Pzhb2+Pw7VJ/3SdR+LZntHPUf05WGnpf0VaIg6VQOUgE3bxogqxANl6hIeg5Xq3oC Q1UpddqnrwPHAvFpLwtVemFmZCLIyBrWoCdKQdpVqhKZ8GbXBAFUQ6ts/IXwrXeNQhD5 xR3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=iOOTgarB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 hk6si13995108ejb.716.2020.11.17.17.55.26; Tue, 17 Nov 2020 17:55:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=iOOTgarB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 S1726532AbgKRBxx (ORCPT + 99 others); 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-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-kernel@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 --- 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"); -- 2.17.1