From patchwork Thu Oct 13 17:52:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 2207 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp410561wrs; Thu, 13 Oct 2022 11:06:51 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6zbT5bBUegI2Z9/jJGb8w+qCsm5045Xol3J4GG6G4b5mradWYPTkTqQZVLmyTjOzEIuHKc X-Received: by 2002:a17:90b:4f4e:b0:20d:9f5b:abbf with SMTP id pj14-20020a17090b4f4e00b0020d9f5babbfmr1158289pjb.148.1665684410719; Thu, 13 Oct 2022 11:06:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665684410; cv=none; d=google.com; s=arc-20160816; b=n/R+bRxVFrvsiBUTt/OTnxkgVrmG93VNLhQmlyoQSVAhVL/Z1UF+eHfdmZNCmNBGie mm+awTH1RytD5sUZHHys8ndPFFC3E3iiYkvENFgUdIsB+ocn5EtXkmgCcySPVfbqhLyG 1EjYszXUnkpJqRmAYh3ndtp4lUr7XN88v1dtETr39Tzw98uh2WDY9ECwa4chh+3QUf3L HDzG55/4OHChl9BDSRtDOHChX7rAyO0/PtfFuc4Sjcvk49B5Sc25fF/L2Ne+4EwmpeCo 5R1a0VO9C69EmDSgyD3hO4vl+zcUbmSeew9KNh8p0tAP6u6PS1MeKpQ2VDtMMpvXLtfF PhoA== 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=TYhzSVKUDpLO5qzT7uCRflR3opGrP+S6W5tbmidrrvM=; b=fAzUlNRe1JDqilE9uF9KFfQrm1JtG0Eh1IlfrFi7t10Ei+5k8rlbPWvC8q7nkLir2d WMwdy+n7Rem7X6islr07t6fcHCWLTiQFVI/c+W41UeFSK988s3eLf60mzbNaw9PvW55i BaYPzHSJK8mY77HW1FIVgJy58j8rPGqmoaLD7jDD6TKGV0QPBAKygd7uR+aVcbEnfQu2 EfKwTUM5phZaWhG+iYedOhXIktDDmdywt7VNQrr+H7BXluF6fLgNUiBqvLDXlzMJJc4b rCv33OifqSZJ9r2eBtmYQjAASSSIZASWpl5HoLZ5z4HrjPDfiOwHD0woGLCmvqcRbEaI eFMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HDi832Mr; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k12-20020a63560c000000b00456f7329d13si76109pgb.279.2022.10.13.11.06.38; Thu, 13 Oct 2022 11:06:50 -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=HDi832Mr; 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 S231280AbiJMSGF (ORCPT + 99 others); Thu, 13 Oct 2022 14:06:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231239AbiJMSDv (ORCPT ); Thu, 13 Oct 2022 14:03:51 -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 E294B15B334; Thu, 13 Oct 2022 11:03:36 -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 C0AE66194D; Thu, 13 Oct 2022 18:00:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8211BC433B5; Thu, 13 Oct 2022 18:00:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1665684032; bh=IxQ0xOPd/CgxYSCw3RHLoSKvbRbv71Q5pnfxySmwIXg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HDi832MrhVajrwc/qZQstyp4UhkTSjpSDJg3gIvzuRECDxhKeZEJEKf6QHR32lYxw UzUp4XZJaC63j7ugcf0AS7StpnCfWiWoG9wa9vQAbNc1OqCOHA9/s1vnL5EiS99QkU 2UUkbNA1JJE9CNTvrYYmufHbwoJdtA0swRYFCYtg= 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.19 21/33] wifi: cfg80211/mac80211: reject bad MBSSID elements Date: Thu, 13 Oct 2022 19:52:53 +0200 Message-Id: <20221013175145.987965400@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221013175145.236739253@linuxfoundation.org> References: <20221013175145.236739253@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746596696428422619?= X-GMAIL-MSGID: =?utf-8?q?1746596696428422619?= 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 @@ -1439,6 +1439,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;