Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2655456imj; Mon, 11 Feb 2019 06:33:05 -0800 (PST) X-Google-Smtp-Source: AHgI3IY3Uu4sMR7zmbpAnQXVqJfK6otQx2zndE6jgw9PKPGosmk/zjJUKEhsEL7XGzPqlsdgHW0B X-Received: by 2002:a62:39c5:: with SMTP id u66mr9726519pfj.245.1549895585255; Mon, 11 Feb 2019 06:33:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549895585; cv=none; d=google.com; s=arc-20160816; b=y32cXSdbd5Cl7Yc4elC7LU2f9z6Uki7iOm69HWxrAxCtUHBhDKD93v7ooYN1v01CkJ 1B+CETBgrNnADQKOPYtsZxOAyTx9mcMf5GuZjH4s0h0ViDa3Tg3oxhWEQU2goHHbn1PD xZL5D44ra8v3DSgfQGrUBhWulHtbjKD8RWivprlNcnvZ2nNTf0iotqwf/LVBXED8lOOy coC5SwWbrAymxwyL6OBaoyx0J68+lT/ho4BEoxSmCE4Fp/aPVNtQGUVxA+K4Jqjovt0F 7ZLlmoe2ho24O4WeXlqJA+MjIuDnNt6T1QuljliMcHRAYj3K3ZneiDYqL/6V40rHa9Bf LgXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/oK9uBYWNLbXIE8w2R98V6ERdjJCkTWdoYzK7VIe8NQ=; b=hc4hgjtFMo2ijzGn3ZmXdbOrDsmuBbvtD5ykXMSAkL882zV6yduQikdkoZstRk3hFS CzsQPY/G86DpScPOrIysghu4chC1cpkUH2e7n7402PUGH36dmDNPuxU1ssgrTgQSRT7j MboZqqIlth0nseRZW7JKyNAOamzV3/benZFcUAb6X1vooWVjWhAhT0nRZJSqNwE/dqOz 2zQBg30Sf5niImu0eWXDKppyuf42D1tCuKShWQ4YaflljBEv4vDaPYHmsykw4ks4UIJS 9m1VWC6R3zSwe72ftaa3ONtNzkU4maLx1AaFR1FKgaitKjb7iXCMt7RQMrMJ9Ke1bdKn wCtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IVO1bbBh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s4si10337140pfb.190.2019.02.11.06.32.47; Mon, 11 Feb 2019 06:33:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IVO1bbBh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730385AbfBKObz (ORCPT + 99 others); Mon, 11 Feb 2019 09:31:55 -0500 Received: from mail.kernel.org ([198.145.29.99]:38972 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730371AbfBKObu (ORCPT ); Mon, 11 Feb 2019 09:31:50 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 49E9620838; Mon, 11 Feb 2019 14:31:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549895509; bh=J/PGS4QtCJRmZwvkxxHS8zu1o9NPE7gcdXg1esxE6pI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IVO1bbBhfB4ooq/PMNYgrGRzEpy6Zf2DkwUHK9sKM58Nh3jZ+PnOQrhjcQwII1mvF bmg2ryt66tOPaE/nxGKt7OnvVXZsRKoaP90J4g7UVI6admkQZKkgY+vfVM+7DDuk2Z YslaIfxONul3KEccnjSauaRAk+kxcz+6B8igGWKc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Karthikeyan Periyasamy , Kalle Valo , Sasha Levin Subject: [PATCH 4.20 229/352] ath10k: fix kernel panic due to use after free Date: Mon, 11 Feb 2019 15:17:36 +0100 Message-Id: <20190211141901.799812058@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141846.543045703@linuxfoundation.org> References: <20190211141846.543045703@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 553a7cca769d551f1317186760631487c47e23bf ] This issue arise in a race condition between ath10k_sta_state() and ath10k_htt_fetch_peer_stats(), explained in below scenario Steps: 1. In ath10k_sta_state(), arsta->tx_stats get deallocated before peer deletion when the station moves from IEEE80211_STA_NONE to IEEE80211_STA_NOTEXIST state. 2. Meanwhile ath10k receive HTT_T2H_MSG_TYPE_PEER_STATS message. In ath10k_htt_fetch_peer_stats(), arsta->tx_stats get accessed after the peer validation check. Since arsta->tx_stats get freed before the peer deletion [1]. ath10k_htt_fetch_peer_stats() ended up in "use after free" situation. Fixed this issue by moving the arsta->tx_stats free handling after the peer deletion. so that ath10k_htt_fetch_peer_stats() will not end up in "use after free" situation. Kernel Panic: Unable to handle kernel NULL pointer dereference at virtual address 00000286 pgd = d8754000 [00000286] *pgd=00000000 Internal error: Oops: 5 [#1] PREEMPT SMP ARM ... CPU: 0 PID: 6245 Comm: hostapd Not tainted task: dc44cac0 ti: d4a38000 task.ti: d4a38000 PC is at kmem_cache_alloc+0x7c/0x114 LR is at ath10k_sta_state+0x190/0xd58 [ath10k_core] pc : [] lr : [] psr: 20000013 sp : d4a39b88 ip : 00000000 fp : 00000001 r10: 00000000 r9 : 1d3bc000 r8 : 00000dc0 r7 : 000080d0 r6 : d4a38000 r5 : dd401b00 r4 : 00000286 r3 : 00000000 r2 : d4a39ba0 r1 : 000080d0 r0 : dd401b00 Flags: nzCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment user Control: 10c5787d Table: 5a75406a DAC: 00000015 Process hostapd (pid: 6245, stack limit = 0xd4a38238) Stack: (0xd4a39b88 to 0xd4a3a000) ... [] (kmem_cache_alloc) from [] (ath10k_sta_state+0x190/0xd58 [ath10k_core]) [] (ath10k_sta_state [ath10k_core]) from [] (sta_info_insert_rcu+0x418/0x61c [mac80211]) [] (sta_info_insert_rcu [mac80211]) from [] (ieee80211_add_station+0xf0/0x134 [mac80211]) [] (ieee80211_add_station [mac80211]) from [] (nl80211_new_station+0x330/0x36c [cfg80211]) [] (nl80211_new_station [cfg80211]) from [] (extack_doit+0x2c/0x74 [compat]) [] (extack_doit [compat]) from [] (genl_rcv_msg+0x274/0x30c) [] (genl_rcv_msg) from [] (netlink_rcv_skb+0x58/0xac) [] (netlink_rcv_skb) from [] (genl_rcv+0x20/0x34) [] (genl_rcv) from [] (netlink_unicast+0x11c/0x204) [] (netlink_unicast) from [] (netlink_sendmsg+0x30c/0x370) [] (netlink_sendmsg) from [] (sock_sendmsg+0x70/0x84) [] (sock_sendmsg) from [] (___sys_sendmsg.part.3+0x188/0x228) [] (___sys_sendmsg.part.3) from [] (__sys_sendmsg+0x4c/0x70) [] (__sys_sendmsg) from [] (ret_fast_syscall+0x0/0x44) Code: ebfffec1 e1a04000 ea00001b e5953014 (e7940003) ath10k_pci 0000:01:00.0: SWBA overrun on vdev 0, skipped old beacon Hardware tested: QCA9984 Firmware tested: 10.4-3.6.0.1-00004 Fixes: a904417fc ("ath10k: add extended per sta tx statistics support") Signed-off-by: Karthikeyan Periyasamy Signed-off-by: Kalle Valo Signed-off-by: Sasha Levin --- drivers/net/wireless/ath/ath10k/mac.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/ath/ath10k/mac.c b/drivers/net/wireless/ath/ath10k/mac.c index b4764fee4751..6436dc229be5 100644 --- a/drivers/net/wireless/ath/ath10k/mac.c +++ b/drivers/net/wireless/ath/ath10k/mac.c @@ -6387,11 +6387,6 @@ static int ath10k_sta_state(struct ieee80211_hw *hw, "mac vdev %d peer delete %pM sta %pK (sta gone)\n", arvif->vdev_id, sta->addr, sta); - if (ath10k_debug_is_extd_tx_stats_enabled(ar)) { - kfree(arsta->tx_stats); - arsta->tx_stats = NULL; - } - if (sta->tdls) { ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta, @@ -6431,6 +6426,11 @@ static int ath10k_sta_state(struct ieee80211_hw *hw, } spin_unlock_bh(&ar->data_lock); + if (ath10k_debug_is_extd_tx_stats_enabled(ar)) { + kfree(arsta->tx_stats); + arsta->tx_stats = NULL; + } + for (i = 0; i < ARRAY_SIZE(sta->txq); i++) ath10k_mac_txq_unref(ar, sta->txq[i]); -- 2.19.1