Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1307750rwi; Thu, 13 Oct 2022 11:48:40 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5ilE1rB0M/M5Ze4YvSfvb62oQ8D9HhputV5nQ/Jb0exUzmfJMS4YSbrvCNPm5NWD/5VXtl X-Received: by 2002:a17:90b:4d90:b0:20d:9ded:4144 with SMTP id oj16-20020a17090b4d9000b0020d9ded4144mr1283948pjb.90.1665686920459; Thu, 13 Oct 2022 11:48:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665686920; cv=none; d=google.com; s=arc-20160816; b=P6NC1CV4mNkbYNQDs0eJy+UjwYeuI7vI0AXh1w9kQ4ktyxBSKrzyhufZ4KvLUDVUtV lxuedUW0h8oSGYtz8R+K+UMXOXgSxpeEEaPuyy9VTZtdLRXGyG7boGvJjL2HRKC1MMXb sesFgaZgAZRLu3aWJYMldfLswgkGWReHitHGh6wb+IqxsyH6cdLLKDw2IB7zNCZSf3jr 293iUyWgDnwq4vNvtERP6ga91BdjVBrGI22ora7wm5WmpDgq0iiyRHLLKzYCYeBIiF7x 6OlzC6IxeeFquJvvcHEXE+zAHXP4VYFmsw1uDmj0XJzOw0iyg5DAub053Xh2NmIqP4kk YAng== 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=3fnqahB3pEL8yH+lvrZc7SIR6p/cnxCKjJbkZQptMgg=; b=ZiQk+2opN/FgA8LHESWi4P9rVN6nOt0Vq1FUDhwr9/oYULxxze0fj4wdIPMRMDrIG4 XHCJnQENtzG3fr9Cjv/PsW9m9JUn5SBGMflj6eWvly+JafGLg53BG8Hk/VAwSA7MAk9m P5n9XjEVCsLWYH7oqZUqWWCvevsHN4Gz2nELEFH+TMJ/0tGXphsMMukd9wCdbl1PkLSY nmmLfS4GqnByEaGbfb5MdzZWMJIHbH2F8pLKPJP5BOD+9ObhL3y06QfytSMJX+84goVg /2Q0lOoZ8K1DxEeCBtGp+i2SLmR++UO8mL+7y1x+f5rifk3psR+KuUKKaodxMaBYiQmc Z4Cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2NciiWDz; 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 k9-20020a170902c40900b0017d2311af5dsi627454plk.69.2022.10.13.11.48.29; Thu, 13 Oct 2022 11:48:40 -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=2NciiWDz; 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 S229550AbiJMSTe (ORCPT + 99 others); Thu, 13 Oct 2022 14:19:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232107AbiJMSTE (ORCPT ); Thu, 13 Oct 2022 14:19:04 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC09E2FFF7; Thu, 13 Oct 2022 11:14:55 -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 7DD0F6192B; Thu, 13 Oct 2022 17:57:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80B9DC433C1; Thu, 13 Oct 2022 17:57:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1665683863; bh=+1JS/ScgbebCTbepqx7MKXQYJzZPylwvLEfDVcFSmgE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2NciiWDzoCeeGnz1c4DbYz1+DGxYavr8jZTfiRjujYJkiecrL5lEdBt1PZq6L1nDg oJ2cvPGykw1U3YVZcsp5xEgowt3+YMgrSDczCV6S17KpUoMwz+vCgbDmxhljnW/H+f s4qHx0oSkRPzv/v0ZaKw5J1rdgX+Eiusmz3pQEnk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kees Cook , Johannes Berg Subject: [PATCH 5.15 17/27] wifi: cfg80211/mac80211: reject bad MBSSID elements Date: Thu, 13 Oct 2022 19:52:46 +0200 Message-Id: <20221013175144.181064984@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221013175143.518476113@linuxfoundation.org> References: <20221013175143.518476113@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 @@ -1414,6 +1414,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 @@ -2103,6 +2103,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;