From patchwork Fri Feb 12 02:13:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuah Khan X-Patchwork-Id: 12084639 X-Patchwork-Delegate: kuba@kernel.org 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=-19.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,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 74CBAC433DB for ; Fri, 12 Feb 2021 02:13:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4D7C264E35 for ; Fri, 12 Feb 2021 02:13:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229862AbhBLCN6 (ORCPT ); Thu, 11 Feb 2021 21:13:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229623AbhBLCNx (ORCPT ); Thu, 11 Feb 2021 21:13:53 -0500 Received: from mail-io1-xd2e.google.com (mail-io1-xd2e.google.com [IPv6:2607:f8b0:4864:20::d2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86079C0613D6 for ; Thu, 11 Feb 2021 18:13:13 -0800 (PST) Received: by mail-io1-xd2e.google.com with SMTP id n201so7830967iod.12 for ; Thu, 11 Feb 2021 18:13:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KNCXIuhBf/yLZUR6g/Q3bWrDbjCkAY4sfEfqXAFf6ac=; b=PwLlHkN9fXZfpRWioXDoeeGXdYYWvqi46HIRhejT36qNkWkJyGKc4zk3p0GOfmzgr6 Q/r+kYD7SMKLoFSi2dITxN9BC40NtITXEhxpXIFZ7jEQw+fgXpFsRrgxKaxo8EMxO880 LfoxXYyzUgNNBgbgBxSnjPtjJfglTE2CrxRr4= 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=KNCXIuhBf/yLZUR6g/Q3bWrDbjCkAY4sfEfqXAFf6ac=; b=hVI8Y4A3j0lLsNo9XqPSomdlrB9WjIzqEXLcAQbMNc+SlJj1qJON4nHyoGNCZqOZsi Z9WPfGZq2jjd5huEB9vqI1BmKnkEitebuurbthdH/K3ffjyYZa0+JlAiqteHn6/C5lXl G1hTUppk8U9UmyhNjk16PF9+qbSotn8EBMONkqsCqS0ZcNFrdMCmlGSFpnQ7f1syoDlv 94XLxkczJUWGZwfU9m8UFMWg44dLgwRHsJOPLDmplZNmG22S3dXPlSBsi27MSs2jWPn9 dWazu1PHMbc7RkYsWMirWvU9ELXqXFrw422UATULPrlUmpIn0H8SnspL30HDsSJkeHG7 FQnQ== X-Gm-Message-State: AOAM532qchtynJ4i3BAxog7d9nfe85wEOLz5/mrvMPAlCDzhMWMxhrrR uK3Jy4D3fGEa+6rlpFpJP2N3XA== X-Google-Smtp-Source: ABdhPJxHRgQuh8MMHCQ262DBYXeGkeepRITcB4r+KoyS6RHQeVleSejAtUPLHOQGUvq9MZCYHSNzWg== X-Received: by 2002:a05:6602:2c4e:: with SMTP id x14mr548974iov.58.1613095992862; Thu, 11 Feb 2021 18:13:12 -0800 (PST) Received: from shuah-t480s.internal (c-24-9-64-241.hsd1.co.comcast.net. [24.9.64.241]) by smtp.gmail.com with ESMTPSA id c2sm3480594ilk.32.2021.02.11.18.13.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Feb 2021 18:13:12 -0800 (PST) From: Shuah Khan To: kvalo@codeaurora.org, davem@davemloft.net, kuba@kernel.org Cc: Shuah Khan , ath9k-devel@qca.qualcomm.com, linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] ath9k: hold RCU lock when calling ieee80211_find_sta_by_ifaddr() Date: Thu, 11 Feb 2021 19:13:05 -0700 Message-Id: <1cfa036227cfa9fdd04316c01e1d754f13a70d9e.1613090339.git.skhan@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org ieee80211_find_sta_by_ifaddr() must be called under the RCU lock and the resulting pointer is only valid under RCU lock as well. Fix ath_tx_process_buffer() to hold RCU read lock before it calls ieee80211_find_sta_by_ifaddr() and release it when the resulting pointer is no longer needed. This problem was found while reviewing code to debug RCU warn from ath10k_wmi_tlv_parse_peer_stats_info() and a subsequent manual audit of other callers of ieee80211_find_sta_by_ifaddr() that don't hold RCU read lock. Signed-off-by: Shuah Khan --- - Note: This patch is compile tested. I don't have access to hardware. drivers/net/wireless/ath/ath9k/xmit.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/wireless/ath/ath9k/xmit.c b/drivers/net/wireless/ath/ath9k/xmit.c index e60d4737fc6e..1d36aae3f7b6 100644 --- a/drivers/net/wireless/ath/ath9k/xmit.c +++ b/drivers/net/wireless/ath/ath9k/xmit.c @@ -701,6 +701,9 @@ static void ath_tx_process_buffer(struct ath_softc *sc, struct ath_txq *txq, ts->ts_rateindex); hdr = (struct ieee80211_hdr *) bf->bf_mpdu->data; + + rcu_read_lock(); + sta = ieee80211_find_sta_by_ifaddr(hw, hdr->addr1, hdr->addr2); if (sta) { struct ath_node *an = (struct ath_node *)sta->drv_priv; @@ -725,6 +728,8 @@ static void ath_tx_process_buffer(struct ath_softc *sc, struct ath_txq *txq, if (!flush) ath_txq_schedule(sc, txq); + + rcu_read_unlock(); } static bool ath_lookup_legacy(struct ath_buf *bf) From patchwork Fri Feb 12 02:13:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuah Khan X-Patchwork-Id: 12084645 X-Patchwork-Delegate: kuba@kernel.org 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=-19.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,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 E5CE2C433E6 for ; Fri, 12 Feb 2021 02:14:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BF9C464E39 for ; Fri, 12 Feb 2021 02:14:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229965AbhBLCOu (ORCPT ); Thu, 11 Feb 2021 21:14:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229912AbhBLCOg (ORCPT ); Thu, 11 Feb 2021 21:14:36 -0500 Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43959C0617A7 for ; Thu, 11 Feb 2021 18:13:17 -0800 (PST) Received: by mail-io1-xd2d.google.com with SMTP id e133so7833383iof.8 for ; Thu, 11 Feb 2021 18:13:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=b//uXdEXn/IbyWUN9jECjkifnnE9MDyqXLg0odI7qQ8=; b=eXyRVsRfEN70euVgiAtmESC4LEMBc5UdUY6dgr3lsi5tPhEcUNuJKHboVU/N4Z265E g2OYFrPAw/oLLZRyqHCo//ujRwPC/5I0w7ywJ0ZJqi9IrwIo7aFiqcZrgyncJHuYJizB rXHnCfSBrNh4n6qGKt2bOvDMi0tLR4BhXM5w0= 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=b//uXdEXn/IbyWUN9jECjkifnnE9MDyqXLg0odI7qQ8=; b=H5TWVcKKXXVHQa9iGovNW+NFNSP+4HkMWo2Psk2fFwP4EgL55rMSQIO637vwnovAfW 9v0TqPRVxXZS1Mjz9nveYMJZN556XBcMXA/HMJajGF/9lLYT5yexqp3lx4H1TminD5c+ RHQHs7MgoospywVCUH6y0dWgr7U911J39lNvy0WJcgFkXtbcX0/atILxjRzo/td3bI9g ePJh+udxesJvjff34+VaSXGHejBy+cJs/SDNkc08LbzisL6hOx0L+4R+ifTBpnAOhGO7 jwGEADkvUyt1okDZQOhb6xJnZBtroYFdqvqv3bI0q+R/6E9+2AP+4vUmHu8ownfqa6uK UjLg== X-Gm-Message-State: AOAM533JvREB5OLvR9kjGmGizGTykPe0oLvMSSq77QorK/HuxlZ6GD5k jPbtfxwz1bkgFvDti1Z+jj2iZA== X-Google-Smtp-Source: ABdhPJx/RCdCsRX+e5oooz5vMln7HcisejHBH5jilCl4mDg+LF74Is7NKrlK5kw310Vr5GykMGekEA== X-Received: by 2002:a6b:5a0f:: with SMTP id o15mr506350iob.49.1613095996797; Thu, 11 Feb 2021 18:13:16 -0800 (PST) Received: from shuah-t480s.internal (c-24-9-64-241.hsd1.co.comcast.net. [24.9.64.241]) by smtp.gmail.com with ESMTPSA id c2sm3480594ilk.32.2021.02.11.18.13.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Feb 2021 18:13:16 -0800 (PST) From: Shuah Khan To: kvalo@codeaurora.org, davem@davemloft.net, kuba@kernel.org Cc: Shuah Khan , ath9k-devel@qca.qualcomm.com, linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] ath9k: fix ath_tx_process_buffer() potential null ptr dereference Date: Thu, 11 Feb 2021 19:13:08 -0700 Message-Id: <43ed9abb9e8d7112f3cc168c2f8c489e253635ba.1613090339.git.skhan@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org ath_tx_process_buffer() references ieee80211_find_sta_by_ifaddr() return pointer (sta) outside null check. Fix it by moving the code block under the null check. This problem was found while reviewing code to debug RCU warn from ath10k_wmi_tlv_parse_peer_stats_info() and a subsequent manual audit of other callers of ieee80211_find_sta_by_ifaddr() that don't hold RCU read lock. Signed-off-by: Shuah Khan --- - Note: This patch is compile tested. I don't have access to hardware. drivers/net/wireless/ath/ath9k/xmit.c | 28 +++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/drivers/net/wireless/ath/ath9k/xmit.c b/drivers/net/wireless/ath/ath9k/xmit.c index 1d36aae3f7b6..735858144e3a 100644 --- a/drivers/net/wireless/ath/ath9k/xmit.c +++ b/drivers/net/wireless/ath/ath9k/xmit.c @@ -711,20 +711,24 @@ static void ath_tx_process_buffer(struct ath_softc *sc, struct ath_txq *txq, ath_tx_count_airtime(sc, sta, bf, ts, tid->tidno); if (ts->ts_status & (ATH9K_TXERR_FILT | ATH9K_TXERR_XRETRY)) tid->clear_ps_filter = true; - } - if (!bf_isampdu(bf)) { - if (!flush) { - info = IEEE80211_SKB_CB(bf->bf_mpdu); - memcpy(info->control.rates, bf->rates, - sizeof(info->control.rates)); - ath_tx_rc_status(sc, bf, ts, 1, txok ? 0 : 1, txok); - ath_dynack_sample_tx_ts(sc->sc_ah, bf->bf_mpdu, ts, - sta); + if (!bf_isampdu(bf)) { + if (!flush) { + info = IEEE80211_SKB_CB(bf->bf_mpdu); + memcpy(info->control.rates, bf->rates, + sizeof(info->control.rates)); + ath_tx_rc_status(sc, bf, ts, 1, + txok ? 0 : 1, txok); + ath_dynack_sample_tx_ts(sc->sc_ah, + bf->bf_mpdu, ts, sta); + } + ath_tx_complete_buf(sc, bf, txq, bf_head, sta, + ts, txok); + } else { + ath_tx_complete_aggr(sc, txq, bf, bf_head, sta, + tid, ts, txok); } - ath_tx_complete_buf(sc, bf, txq, bf_head, sta, ts, txok); - } else - ath_tx_complete_aggr(sc, txq, bf, bf_head, sta, tid, ts, txok); + } if (!flush) ath_txq_schedule(sc, txq);