Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp1197079pxb; Fri, 22 Apr 2022 23:10:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdXujLXuSG8hiZDspyOW2YyPnav4Y+Q4Ms0oOgwD/yjHPTzOQvhJ4x4bsJoNKuIizirSWU X-Received: by 2002:a17:906:9c09:b0:6e8:89e7:9807 with SMTP id ff9-20020a1709069c0900b006e889e79807mr7211103ejc.473.1650694220525; Fri, 22 Apr 2022 23:10:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650694220; cv=none; d=google.com; s=arc-20160816; b=DRCTbOBSha3Jq4kZP+CifSogUFqrUhUHtLHrjjqUjvs9uXZguHB+An51U3fsVizE8X kLXCFuDiMEiEUNSd/fWgkiKQoYQqC8bNMh5L1cxjdTk77N8NxtUoxpMWWbvWV4RtFzw7 lP5vWgAyo80fxRKdvU6az6+6vleeEKkR908yFIDeK7IoSvP3GHtCrasJBustqBo6rm/8 NAvAn1cX6iVMYhCan8+My8983yQW+BZmKyXD1dnQECxEV6BA4pHBEOENqNe5Fh4GjEzo tEIuIbbfihXKt7ql/NgFNCHa9NwzNNu4zNuH4OXAF7INZ6rLeE7Cb/cR+oGSdanwkWl7 KCYg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=WcYERNmbGHz6qnpdXVE+fTJevHMz5wvD2HERDxIzTKA=; b=mCqiKigW5jnxAVbuZHgZjBxQDO/gfYkiBO8qxyXmbGdZVzlJmoCGTHGR292nLWHlX4 QfOn09vSJTmapigpJ5BEGCw/vy+KoHE8G7RCLuL4JOmoe4+FSkpBTfDPg1YsqOblLqqq QCztkPW78grAWV74z+GMEJ6lUAABcvfok4F/cfXqh/g13mWFaW0mal6UqwhP08m5UbhO 8giFaNSDvUWbtNVcNVuE4g75zzEWW7p9s6CZJYBjN9R+FL/inTfcHwJODH6jxcPr158G oswrr4gBnPrJkDW8JhEiA0z6Yqh6s7bRTSaScjPJFhcwdap8IZC+DBac8RzLt6530BYu AXyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@nbd.name header.s=20160729 header.b=LGu8eDCx; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id rv9-20020a17090710c900b006df76385d0esi6976673ejb.430.2022.04.22.23.09.52; Fri, 22 Apr 2022 23:10:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@nbd.name header.s=20160729 header.b=LGu8eDCx; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233157AbiDWFTx (ORCPT + 66 others); Sat, 23 Apr 2022 01:19:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229945AbiDWFTw (ORCPT ); Sat, 23 Apr 2022 01:19:52 -0400 Received: from nbd.name (nbd.name [IPv6:2a01:4f8:221:3d45::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 691678D6B1 for ; Fri, 22 Apr 2022 22:16:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nbd.name; s=20160729; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject :Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=WcYERNmbGHz6qnpdXVE+fTJevHMz5wvD2HERDxIzTKA=; b=LGu8eDCxK/Wujg2lPwoMOlRFrX mKnECNI9203Jz5H0bmnDAopmr68RMqIlupO2qtGHG5Dhk2c/heKpkSlOIo9UaaCVYGVn11vwfqdsI 2iUE6s6mfiWiP0Ko7+q7xgDPbmO9WH/WaEqBV7sjjVQqgrhtr2euxL+xpKcE/3Uz0bPY=; Received: from [217.114.218.20] (helo=localhost.localdomain) by ds12 with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1ni88b-0002gY-2W; Sat, 23 Apr 2022 07:16:53 +0200 From: Felix Fietkau To: linux-wireless@vger.kernel.org Cc: Ben Greear Subject: [PATCH] mt76: fix tx status related use-after-free race on station removal Date: Sat, 23 Apr 2022 07:16:48 +0200 Message-Id: <20220423051648.17362-1-nbd@nbd.name> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org There is a small race window where ongoing tx activity can lead to a skb getting added to the status tracking idr after that idr has already been cleaned up, which will keep the wcid linked in the status poll list. Fix this by only adding status skbs if the wcid pointer is still assigned in dev->wcid, which gets cleared early by mt76_sta_pre_rcu_remove Fixes: bd1e3e7b693c ("mt76: introduce packet_id idr") Tested-by: Ben Greear Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mac80211.c | 2 ++ drivers/net/wireless/mediatek/mt76/tx.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/mac80211.c b/drivers/net/wireless/mediatek/mt76/mac80211.c index 2dd3ebd1863f..8a2fedbb1451 100644 --- a/drivers/net/wireless/mediatek/mt76/mac80211.c +++ b/drivers/net/wireless/mediatek/mt76/mac80211.c @@ -1381,7 +1381,9 @@ void mt76_sta_pre_rcu_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct mt76_wcid *wcid = (struct mt76_wcid *)sta->drv_priv; mutex_lock(&dev->mutex); + spin_lock_bh(&dev->status_lock); rcu_assign_pointer(dev->wcid[wcid->idx], NULL); + spin_unlock_bh(&dev->status_lock); mutex_unlock(&dev->mutex); } EXPORT_SYMBOL_GPL(mt76_sta_pre_rcu_remove); diff --git a/drivers/net/wireless/mediatek/mt76/tx.c b/drivers/net/wireless/mediatek/mt76/tx.c index c3be62f58b62..d5a8456c108b 100644 --- a/drivers/net/wireless/mediatek/mt76/tx.c +++ b/drivers/net/wireless/mediatek/mt76/tx.c @@ -120,7 +120,7 @@ mt76_tx_status_skb_add(struct mt76_dev *dev, struct mt76_wcid *wcid, memset(cb, 0, sizeof(*cb)); - if (!wcid) + if (!wcid || !rcu_access_pointer(dev->wcid[wcid->idx])) return MT_PACKET_ID_NO_ACK; if (info->flags & IEEE80211_TX_CTL_NO_ACK) -- 2.35.1