Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1310592rwi; Thu, 13 Oct 2022 11:51:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6woZsvSXse9RSX+7Zo+QPxRRMRGa5YwHAPpjSSVCEBRxblSY6PVzv06NYQKFBudbPwXiPx X-Received: by 2002:a05:6a02:190:b0:43c:7997:4d69 with SMTP id bj16-20020a056a02019000b0043c79974d69mr1110443pgb.15.1665687083382; Thu, 13 Oct 2022 11:51:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665687083; cv=none; d=google.com; s=arc-20160816; b=lG/kCx8P3t1zc6V24C0xKsXXFuJSFN2hHgq9mVT0IQA2QK2VIo9vcoe2eWDGC3anFJ 5XwyFtMSlib9x2Gch/P/v/W+sKJWkec73wDUR5g/Kh83R8MjxrGD5pZhzq3Wuv5c8fY0 C5DKAdVchleph8Y/RTcZJxLdIuOKqtmXSL0VpTQ+0NBbVV+huRVCFoDcKkiQDPDQmw3Y Ezb64qYXb7d1Y+QB6vGTdYmFoP/vHyv2Bmv91jihCiGoTPfxNzbr8mmBVX1Xs3lIHfkr MQ1dn4qNx/51Tw/ZMSrn8kVZtmAwEuCovFvvRybpaNLYUu+5XnA/FWVh3URR+55cJX85 wDLg== 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=YJIg0gTZNVbopiUkXpogYfFM7xDZJVVqzq5UKrp2Cko=; b=QmjYOxWEkL1QnUZjBpWsdc/SVcuzM4HCU9o1nalAxi741rxk5w/u6aaFkieOhu+IOo eyjPx5aD4ThCRwtnyVXwSyncpK5cPmDLN9PBYukxM1PxNiBy3ePyoG6b4Q902VaMa6QC fxPYPEqqvt4REOyClU5OvHXaNgxIUsbKWMrT02eBK+f1lNa8ARqZeTv/nHXtIVEGlrkW SbpMHWZ2q9MF4I2Uk2DqscnhXNk8UZ8M9PcDg5FSIs/ls5axIHOaWSr+/LB7dBq2Z0m4 F2ds8N/hrXtdMT6zXJybTET5kqwkqNB37IGGmqSydV0rCOLA6y3xXji9cxw19t7XzchG vuEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HD1CrisC; 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 w3-20020a639343000000b00452bab4de6fsi83250pgm.749.2022.10.13.11.51.11; Thu, 13 Oct 2022 11:51:23 -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=HD1CrisC; 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 S231362AbiJMSKr (ORCPT + 99 others); Thu, 13 Oct 2022 14:10:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231443AbiJMSKJ (ORCPT ); Thu, 13 Oct 2022 14:10:09 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F4E4175795; Thu, 13 Oct 2022 11:07:34 -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 dfw.source.kernel.org (Postfix) with ESMTPS id B7B5E61A47; Thu, 13 Oct 2022 18:01:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A56BCC433D6; Thu, 13 Oct 2022 18:01:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1665684093; bh=ABVtqPRgxmZIFlVSQtFaRqnHz1dauK3i7uCum+wmrFc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HD1CrisClRoFpKLiQMJhtk58tAiwL+ZkZsQsG9RLGZjHYm+uKuT/fJw8kJ6js4kdc EUFnz8pGznCEmlvZUzQ/1pM/UGBkNJg6AxFXW1BE8C3Z8npcPaCIsaWx0WoY1Xor1j Mj0aGm8JCt+BaKazkAOZHxqRnniW0/Fy/TbP9OIw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kees Cook , Johannes Berg Subject: [PATCH 6.0 22/34] wifi: cfg80211/mac80211: reject bad MBSSID elements Date: Thu, 13 Oct 2022 19:53:00 +0200 Message-Id: <20221013175147.094790325@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221013175146.507746257@linuxfoundation.org> References: <20221013175146.507746257@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 8f033d2becc24aa6bfd2a5c104407963560caabc upstream. Per spec, the maximum value for the MaxBSSID ('n') indicator is 8, and the minimum is 1 since a multiple BSSID set with just one BSSID doesn't make sense (the # of BSSIDs is limited by 2^n). Limit this in the parsing in both cfg80211 and mac80211, rejecting any elements with an invalid value. This fixes potentially bad shifts in the processing of these inside the cfg80211_gen_new_bssid() function later. I found this during the investigation of CVE-2022-41674 fixed by the previous patch. Fixes: 0b8fb8235be8 ("cfg80211: Parsing of Multiple BSSID information in scanning") Fixes: 78ac51f81532 ("mac80211: support multi-bssid") Reviewed-by: Kees Cook Signed-off-by: Johannes Berg Signed-off-by: Greg Kroah-Hartman --- net/mac80211/util.c | 2 ++ net/wireless/scan.c | 2 ++ 2 files changed, 4 insertions(+) --- a/net/mac80211/util.c +++ b/net/mac80211/util.c @@ -1442,6 +1442,8 @@ static size_t ieee802_11_find_bssid_prof for_each_element_id(elem, WLAN_EID_MULTIPLE_BSSID, start, len) { if (elem->datalen < 2) continue; + if (elem->data[0] < 1 || elem->data[0] > 8) + continue; for_each_element(sub, elem->data + 1, elem->datalen - 1) { u8 new_bssid[ETH_ALEN]; --- a/net/wireless/scan.c +++ b/net/wireless/scan.c @@ -2143,6 +2143,8 @@ static void cfg80211_parse_mbssid_data(s for_each_element_id(elem, WLAN_EID_MULTIPLE_BSSID, ie, ielen) { if (elem->datalen < 4) continue; + if (elem->data[0] < 1 || (int)elem->data[0] > 8) + continue; for_each_element(sub, elem->data + 1, elem->datalen - 1) { u8 profile_len;