Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3642379pxb; Mon, 24 Jan 2022 14:13:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJxWsoc3xWUk7BooA00CTBFTGe0AvIv7/6ve1FFtYrI3oU+hD3e55ai5j61UJu2+I2/eedBx X-Received: by 2002:a05:6a00:238e:b0:4c6:2f07:b1b1 with SMTP id f14-20020a056a00238e00b004c62f07b1b1mr15719190pfc.53.1643062411640; Mon, 24 Jan 2022 14:13:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643062411; cv=none; d=google.com; s=arc-20160816; b=SlHz6ELb9EDRsaRCHrZ/BLGCTTwkUrHXuHGM+Lnjwj6+2Xb1fHdpvihaAp8Kd0OQg5 LssvdlHqiqSFSa7OswYb0XnBj/gsGB2i019G+x0UAPOArCbNwCGOsmcDOqsJD1aqBDNx m0gNy11VuOnG4ppWbSIBgzPYgcPyWeEei5IKpl5OXr7XZPJZLjzna3jBh8hPjRY4Aiaz 5sJYyNakk66XINyefQYABbPdg1LxgQuNv3WwH3WBUTtuPuGqiipEvJvdgocKlkB1mah9 VHCZtTJggitZ6idqEFW6TSaN6oZsgz6vQyVtK0361OVDFsxV8kB4/3SF2eX8LA+4YJTI UqZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wJp9bvhcE+BNGvwkh7VhZn9GUxeygJVte7g+FjEkO0M=; b=vAMlEiqkDQq0Dvuhgn34z0w/M/2dksX0ZA4Tq9HKErbo6oFk+NPh7ouyW5n1Av9ekL XWsfJroHA5NnPP3yIf0wphEwQ9xs2H6/8f8fuegk37KxebnYclzBv65SWk4xfz+UVyLP LBYjMw7haGuuX/8PMKF1pk9VnXhzXbM/Vd4+O4nevHI8NyAdox3dGoeruvsDjcp9VNcA EhPHX9NK6LnC7Lnis7OfW50moiaXXFERieDe5Xwr4NAXyEYoP25g7hXS6aLyVImWg3cP z5QuYVnn1H5WyeUrP544IoGysBV/WGlubPEPhpV/MQ+THaFQ/nc3T7AIJNjvWx6rqb6k yu6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2NUygbFY; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n4si495296pjo.27.2022.01.24.14.13.16; Mon, 24 Jan 2022 14:13:31 -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=@linuxfoundation.org header.s=korg header.b=2NUygbFY; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1578020AbiAXWBZ (ORCPT + 99 others); Mon, 24 Jan 2022 17:01:25 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:40324 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1451595AbiAXVXM (ORCPT ); Mon, 24 Jan 2022 16:23:12 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id C93EFB81188; Mon, 24 Jan 2022 21:23:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D3D1CC340E5; Mon, 24 Jan 2022 21:23:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643059389; bh=oFdvVlvLXbZXX4XWSa9QLTGZFtzreFcGxde9rBTrLdI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2NUygbFYQ490/wyb7en+VG5z+kzAJPzCWnwWHr8lcFdaQtwvwthTP90lrmspBNzIQ pkzJwlYaikokh4fTvOMbfYFKfCZ+ZXMWQm1BWhFdKji4sC/Ng3CRUXfh5QApWa/yj/ B7d4b7KYkabOhEkoXM8/1oim61YAgyKZ5ykpfrNY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sriram R , Kalle Valo , Sasha Levin Subject: [PATCH 5.16 0600/1039] ath11k: Avoid NULL ptr access during mgmt tx cleanup Date: Mon, 24 Jan 2022 19:39:49 +0100 Message-Id: <20220124184145.512012358@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sriram R [ Upstream commit a93789ae541c7d5c1c2a4942013adb6bcc5e2848 ] Currently 'ar' reference is not added in skb_cb during WMI mgmt tx. Though this is generally not used during tx completion callbacks, on interface removal the remaining idr cleanup callback uses the ar ptr from skb_cb from mgmt txmgmt_idr. Hence fill them during tx call for proper usage. Also free the skb which is missing currently in these callbacks. Crash_info: [19282.489476] Unable to handle kernel NULL pointer dereference at virtual address 00000000 [19282.489515] pgd = 91eb8000 [19282.496702] [00000000] *pgd=00000000 [19282.502524] Internal error: Oops: 5 [#1] PREEMPT SMP ARM [19282.783728] PC is at ath11k_mac_vif_txmgmt_idr_remove+0x28/0xd8 [ath11k] [19282.789170] LR is at idr_for_each+0xa0/0xc8 Tested-on: IPQ8074 hw2.0 AHB WLAN.HK.2.5.0.1-00729-QCAHKSWPL_SILICONZ-3 v2 Signed-off-by: Sriram R Signed-off-by: Kalle Valo Link: https://lore.kernel.org/r/1637832614-13831-1-git-send-email-quic_srirrama@quicinc.com Signed-off-by: Sasha Levin --- drivers/net/wireless/ath/ath11k/mac.c | 35 +++++++++++++++------------ 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/drivers/net/wireless/ath/ath11k/mac.c b/drivers/net/wireless/ath/ath11k/mac.c index cb41c3e5708cb..a7400ade7a0cf 100644 --- a/drivers/net/wireless/ath/ath11k/mac.c +++ b/drivers/net/wireless/ath/ath11k/mac.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: BSD-3-Clause-Clear /* * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. + * Copyright (c) 2021 Qualcomm Innovation Center, Inc. All rights reserved. */ #include @@ -4935,23 +4936,32 @@ static int __ath11k_set_antenna(struct ath11k *ar, u32 tx_ant, u32 rx_ant) return 0; } -int ath11k_mac_tx_mgmt_pending_free(int buf_id, void *skb, void *ctx) +static void ath11k_mac_tx_mgmt_free(struct ath11k *ar, int buf_id) { - struct sk_buff *msdu = skb; + struct sk_buff *msdu; struct ieee80211_tx_info *info; - struct ath11k *ar = ctx; - struct ath11k_base *ab = ar->ab; spin_lock_bh(&ar->txmgmt_idr_lock); - idr_remove(&ar->txmgmt_idr, buf_id); + msdu = idr_remove(&ar->txmgmt_idr, buf_id); spin_unlock_bh(&ar->txmgmt_idr_lock); - dma_unmap_single(ab->dev, ATH11K_SKB_CB(msdu)->paddr, msdu->len, + + if (!msdu) + return; + + dma_unmap_single(ar->ab->dev, ATH11K_SKB_CB(msdu)->paddr, msdu->len, DMA_TO_DEVICE); info = IEEE80211_SKB_CB(msdu); memset(&info->status, 0, sizeof(info->status)); ieee80211_free_txskb(ar->hw, msdu); +} + +int ath11k_mac_tx_mgmt_pending_free(int buf_id, void *skb, void *ctx) +{ + struct ath11k *ar = ctx; + + ath11k_mac_tx_mgmt_free(ar, buf_id); return 0; } @@ -4960,17 +4970,10 @@ static int ath11k_mac_vif_txmgmt_idr_remove(int buf_id, void *skb, void *ctx) { struct ieee80211_vif *vif = ctx; struct ath11k_skb_cb *skb_cb = ATH11K_SKB_CB((struct sk_buff *)skb); - struct sk_buff *msdu = skb; struct ath11k *ar = skb_cb->ar; - struct ath11k_base *ab = ar->ab; - if (skb_cb->vif == vif) { - spin_lock_bh(&ar->txmgmt_idr_lock); - idr_remove(&ar->txmgmt_idr, buf_id); - spin_unlock_bh(&ar->txmgmt_idr_lock); - dma_unmap_single(ab->dev, skb_cb->paddr, msdu->len, - DMA_TO_DEVICE); - } + if (skb_cb->vif == vif) + ath11k_mac_tx_mgmt_free(ar, buf_id); return 0; } @@ -4985,6 +4988,8 @@ static int ath11k_mac_mgmt_tx_wmi(struct ath11k *ar, struct ath11k_vif *arvif, int buf_id; int ret; + ATH11K_SKB_CB(skb)->ar = ar; + spin_lock_bh(&ar->txmgmt_idr_lock); buf_id = idr_alloc(&ar->txmgmt_idr, skb, 0, ATH11K_TX_MGMT_NUM_PENDING_MAX, GFP_ATOMIC); -- 2.34.1