Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1307827rwi; Thu, 13 Oct 2022 11:48:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5x7cqS+EFhGVUlvl0k96ZFhReyqRSxnjDOWd8YebFRsqFQsL+1F4QrnqvdvsDgU3NzZbO0 X-Received: by 2002:a05:6a00:c86:b0:563:b89c:3d0b with SMTP id a6-20020a056a000c8600b00563b89c3d0bmr1001018pfv.50.1665686924720; Thu, 13 Oct 2022 11:48:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665686924; cv=none; d=google.com; s=arc-20160816; b=F/F0Is2MWLVzl/Zdp5sYQdO4Sq/ZI6YSiUR/w0uCNsHHP2flgvNHTv6iIr4IDuDiBX INzOdCYUV8GRnGZ7LDp+ykyAg7Km8hSf02E49U66E742bIOkH/nE5vbfHt8jEvG5hRlG ubvkcEIJJuRkFpxGEIi1XlFj5ktvO70iCvKP84fKbDe+KVuDRy2JpXiS16a68NuuFqMX 3W6LY2ALFG+zsnG7JyIyyIgXYBPWtSZJgQgeegBufVQ9VcCGvrUHePb8SmdsyQsD3RSw RXmI3vi8LfPW8yVQOA83x5Vob/EqTyhQ1+iIQHTmngf5dl7m11XXRNGBaagwEQ+J8lp/ FaAA== 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=TQvgsnO13THoZg3oenn3JCsGdp6P+fx9HwDVc2bqW2w=; b=GM6ZlhGDW9CsXcwNFiAs65GdCQW74KOQf0CzaXTUhvUhYKe4oxyVPNSYxVZ9Mrdp37 4sbxeSdlEZENwm6e7K3Y6XolqL0YTpPaqJJast6nzoTXLGUbY7/jO4pZBGlbq2BdSadr XvTp/Akvp5xXtcTEfVVi30BdhA01G5IKOo+7MgWNHSOBD29tjX5X8x+sUrivPyRrbW2R BmkjiAqRi4f/XAkBVge6KLVqMTeq5orZkutroJYhaFbdMTD6CSk9V+tqPZLMyK22g78S 24CQiBVQmvlDlvxYb/FrgcALrIFdAQRT3CB41wWvY/EP+NNush6871+DOXx/7d+2/GZZ miLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=N3CEH3Ud; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z20-20020aa78894000000b0053e7495a394si172440pfe.141.2022.10.13.11.48.32; Thu, 13 Oct 2022 11:48:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=pass header.i=@linuxfoundation.org header.s=korg header.b=N3CEH3Ud; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S230082AbiJMRza (ORCPT + 99 others); Thu, 13 Oct 2022 13:55:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230004AbiJMRyY (ORCPT ); Thu, 13 Oct 2022 13:54:24 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1651115380F; Thu, 13 Oct 2022 10:53:49 -0700 (PDT) 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 A5AB4B82025; Thu, 13 Oct 2022 17:53:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1CD3C433D6; Thu, 13 Oct 2022 17:53:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1665683627; bh=1Ll6/7ocjbBrCFkgVE7FHQn8nDSrcLDqlbjznr3zqsM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N3CEH3Ud/FqaCW7otzq54DeAQqg02A6VJUkwRg8/zaUp8YlUMjTbA3Ttsgu26Q0GR t1K8nopVwPWDaAKid8dRiSpkbPcB6PJaKsfSs566eEHDzgKjjo/zef/x86FMqfLlzz K4HmwBYiLPGpbpLshsozM/WvfAQDU8sBaTQoRzY0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?S=C3=B6nke=20Huster?= , Johannes Berg Subject: [PATCH 5.4 33/38] wifi: cfg80211: fix BSS refcounting bugs Date: Thu, 13 Oct 2022 19:52:34 +0200 Message-Id: <20221013175145.345782325@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221013175144.245431424@linuxfoundation.org> References: <20221013175144.245431424@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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-kernel@vger.kernel.org From: Johannes Berg commit 0b7808818cb9df6680f98996b8e9a439fa7bcc2f upstream. There are multiple refcounting bugs related to multi-BSSID: - In bss_ref_get(), if the BSS has a hidden_beacon_bss, then the bss pointer is overwritten before checking for the transmitted BSS, which is clearly wrong. Fix this by using the bss_from_pub() macro. - In cfg80211_bss_update() we copy the transmitted_bss pointer from tmp into new, but then if we release new, we'll unref it erroneously. We already set the pointer and ref it, but need to NULL it since it was copied from the tmp data. - In cfg80211_inform_single_bss_data(), if adding to the non- transmitted list fails, we unlink the BSS and yet still we return it, but this results in returning an entry without a reference. We shouldn't return it anyway if it was broken enough to not get added there. This fixes CVE-2022-42720. Reported-by: Sönke Huster Tested-by: Sönke Huster Fixes: a3584f56de1c ("cfg80211: Properly track transmitting and non-transmitting BSS") Signed-off-by: Johannes Berg Signed-off-by: Greg Kroah-Hartman --- net/wireless/scan.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) --- a/net/wireless/scan.c +++ b/net/wireless/scan.c @@ -104,18 +104,12 @@ static inline void bss_ref_get(struct cf lockdep_assert_held(&rdev->bss_lock); bss->refcount++; - if (bss->pub.hidden_beacon_bss) { - bss = container_of(bss->pub.hidden_beacon_bss, - struct cfg80211_internal_bss, - pub); - bss->refcount++; - } - if (bss->pub.transmitted_bss) { - bss = container_of(bss->pub.transmitted_bss, - struct cfg80211_internal_bss, - pub); - bss->refcount++; - } + + if (bss->pub.hidden_beacon_bss) + bss_from_pub(bss->pub.hidden_beacon_bss)->refcount++; + + if (bss->pub.transmitted_bss) + bss_from_pub(bss->pub.transmitted_bss)->refcount++; } static inline void bss_ref_put(struct cfg80211_registered_device *rdev, @@ -1233,6 +1227,8 @@ cfg80211_bss_update(struct cfg80211_regi new->refcount = 1; INIT_LIST_HEAD(&new->hidden_list); INIT_LIST_HEAD(&new->pub.nontrans_list); + /* we'll set this later if it was non-NULL */ + new->pub.transmitted_bss = NULL; if (rcu_access_pointer(tmp->pub.proberesp_ies)) { hidden = rb_find_bss(rdev, tmp, BSS_CMP_HIDE_ZLEN); @@ -1462,10 +1458,15 @@ cfg80211_inform_single_bss_data(struct w spin_lock_bh(&rdev->bss_lock); if (cfg80211_add_nontrans_list(non_tx_data->tx_bss, &res->pub)) { - if (__cfg80211_unlink_bss(rdev, res)) + if (__cfg80211_unlink_bss(rdev, res)) { rdev->bss_generation++; + res = NULL; + } } spin_unlock_bh(&rdev->bss_lock); + + if (!res) + return NULL; } trace_cfg80211_return_bss(&res->pub);