Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp343639rdb; Mon, 29 Jan 2024 04:14:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IHtUJRyIG6XRg2LG2dyTFFHfH3FVG559kSvesvCyrNPlQuJiu/LF18s72F3V3P8JqVEpnBv X-Received: by 2002:ae9:f710:0:b0:783:2ba2:9ab7 with SMTP id s16-20020ae9f710000000b007832ba29ab7mr5310898qkg.130.1706530476046; Mon, 29 Jan 2024 04:14:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706530476; cv=pass; d=google.com; s=arc-20160816; b=KkpJQHeIWpQVrZ1a64nKh4pvqYzIUA3gOB7zS7wkScDypo2UZYEB2seqboiihJIB/V YTWNMQY0eBSM4h40vcDkTQEdU8LTgslfz5E8sEoGy//xsZbymG6t7r91DjcG3GCc7uhg 679BL67xMxgT16raQCdhVJIsitzOWNO423A32oxbsim8qaVBetokSENXpu3GBgrnj7a7 Han39v+TY3wxEi1wgSkTS7QoZ89uDaB6/SQZLiZ11rwiy9Ea/k+xsa7mHuoU5DOInps5 ZCLF6hp3SwLg2U9UqH8Rnc+3ZKGSoDtKX1EvNRY4ENDOrks4F0UVHaIIc8xMNYtY/mY/ vIRA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=iT9Y/uDSI26VhSJPF0hg9eTl2O2jJRFsT4qMaN/I1hQ=; fh=Ef2Y5OfUZ+94X9X5EvpkjOHA6VPFb3Y2Qnu6LYw/C3k=; b=qFC539GHTxiAw900JkyEszBKNuubVxZUjHKFou/Z+/ZAxazZzcmcZViH0G2JXQtbB6 wWJwIsYkhOxKgwT1mdkrgWfgRCMKddcs5QNelaoEK3DChD0Bem+juMkdhAv7ew63cwEf op3M+DbBVdpWMi9nTySSbQJwtS7zeUR1kfluUMqkfXN+TtOAOa2YNkonJ7Ink9b09zwK 4LIIYBhXqaUWQZWAARi6CUb0TtpNcTQfeLDXKGztqqqxrWFZ8IM/ho913B08ZGTSxcDd gDP1fByOMT3+W0gE2drgJZHMHCIzwzxz2Liha8GpmtSmpcaN63F7UMmSe+eFrt45Q0UZ 4qtw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sipsolutions.net header.s=mail header.b=bF5vvmaB; arc=pass (i=1 spf=pass spfdomain=sipsolutions.net dkim=pass dkdomain=sipsolutions.net dmarc=pass fromdomain=sipsolutions.net); spf=pass (google.com: domain of linux-wireless+bounces-2665-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-wireless+bounces-2665-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=sipsolutions.net X-Forwarded-Encrypted: i=1; AJvYcCVum4b3CF9DIWJRvmRKBINgk4SEy0ixBcMn4KhpXjrFeKa/2ObsjcB1wqmlfAZdZwyY/XrbX7YZzfHUohMif/rcrUkY7HOlOk6pG3+R+w== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id x20-20020a05620a0ed400b00783070846e9si7348626qkm.385.2024.01.29.04.14.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 04:14:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless+bounces-2665-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@sipsolutions.net header.s=mail header.b=bF5vvmaB; arc=pass (i=1 spf=pass spfdomain=sipsolutions.net dkim=pass dkdomain=sipsolutions.net dmarc=pass fromdomain=sipsolutions.net); spf=pass (google.com: domain of linux-wireless+bounces-2665-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-wireless+bounces-2665-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=sipsolutions.net Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id BC5F81C21BDD for ; Mon, 29 Jan 2024 12:14:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6F4C560265; Mon, 29 Jan 2024 12:14:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b="bF5vvmaB" X-Original-To: linux-wireless@vger.kernel.org Received: from sipsolutions.net (s3.sipsolutions.net [168.119.38.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF4FC60242 for ; Mon, 29 Jan 2024 12:14:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=168.119.38.16 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706530471; cv=none; b=C7d5sEGjdk1yxcstOAG9mi3C/tq0mkDIh7PjosArXoRJJvmmdURLq0HoIhBUu8OeRfZMyGEBJ6O8nwB4UkRHPNUbFvFRqWtY0ALfQUx0XQ7eyK1vTPNEUl/Gn9raiHe8KYZTeJ57d67ai9pXGdsrk6bsn8U1qEflLEk6S4BNM4I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706530471; c=relaxed/simple; bh=Gs89PZed4BgdDQEDFKrvKcQJydk759cHZNZLQpXl5nk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Fa9aojGnVWyWCyD+LoGnuZ4Xu+TiUY6kAXwoAKhI7vaDNdgnnD7+bSrVAORvnr7ahp5Moh/cHSF+4NHSZSKKHwxTZceiRAPnlQyu3LI9m/Iz+euPS7Vds17RHgPiGrLlgmA9RH5rJjWsCTlmC7I78yEleUUrkvSvRJ1gB8PJANA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net; spf=pass smtp.mailfrom=sipsolutions.net; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b=bF5vvmaB; arc=none smtp.client-ip=168.119.38.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sipsolutions.net DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Content-Type:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=iT9Y/uDSI26VhSJPF0hg9eTl2O2jJRFsT4qMaN/I1hQ=; t=1706530466; x=1707740066; b=bF5vvmaBZqn4JDM7H9eGszpQYbjPzglBpARlleP/NaB8Xes yLib3YgK5J9kKHQTVzG9kNFKAWa+farlwipuRl1ZYzQ392bj78mfc8z2VcEyFBP27dhgQTRgALKo2 Qt3vgzd4f8O+lm79pBdPocme7G2Uf2PegdtHPLAUbUjGc6iX8p6qiviMByYTvlEc75vTf7U1YtDye +pJ89QEqvuz6huso4upMkBASwpO69AHhr3xsced02cRu6WXFzIHBQkRSd6L2ixMkS35Hbj9cYdlKr u3ZTnrqsAvDlj7Ywlj/o51+vUm+7lmDHcv0rbAcyGK4V8SRGgt3OjJrvSwd0577A==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.97) (envelope-from ) id 1rUQWm-00000004p5l-2cHn; Mon, 29 Jan 2024 13:14:17 +0100 From: Johannes Berg To: linux-wireless@vger.kernel.org Cc: Johannes Berg , coldolt , Miriam Rachel Korenblit Subject: [PATCH 2/2] wifi: mac80211: improve CSA/ECSA connection refusal Date: Mon, 29 Jan 2024 13:14:14 +0100 Message-ID: <20240129131413.cc2d0a26226e.I682c016af76e35b6c47007db50e8554c5a426910@changeid> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240129131413.246972c8775e.Ibf834d7f52f9951a353b6872383da710a7358338@changeid> References: <20240129131413.246972c8775e.Ibf834d7f52f9951a353b6872383da710a7358338@changeid> Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Johannes Berg As mentioned in the previous commit, we pretty quickly found that some APs have ECSA elements stuck in their probe response, so using that to not attempt to connect while CSA is happening we never connect to such an AP. Improve this situation by checking more carefully and ignoring the ECSA if cfg80211 has previously detected the ECSA element being stuck in the probe response. Additionally, allow connecting to an AP that's switching to a channel it's already using, unless it's using quiet mode. In this case, we may just have to adjust bandwidth later. If it's actually switching channels, it's better not to try to connect in the middle of that. Reported-by: coldolt Closes: https://lore.kernel.org/linux-wireless/CAJvGw+DQhBk_mHXeu6RTOds5iramMW2FbMB01VbKRA4YbHHDTA@mail.gmail.com/ Fixes: c09c4f31998b ("wifi: mac80211: don't connect to an AP while it's in a CSA process") Reviewed-by: Miriam Rachel Korenblit Signed-off-by: Johannes Berg --- net/mac80211/mlme.c | 105 ++++++++++++++++++++++++++++++++------------ 1 file changed, 77 insertions(+), 28 deletions(-) diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c index 073105deb424..c62c7c6ce91f 100644 --- a/net/mac80211/mlme.c +++ b/net/mac80211/mlme.c @@ -7309,6 +7309,75 @@ static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata, return err; } +static bool ieee80211_mgd_csa_present(struct ieee80211_sub_if_data *sdata, + const struct cfg80211_bss_ies *ies, + u8 cur_channel, bool ignore_ecsa) +{ + const struct element *csa_elem, *ecsa_elem; + struct ieee80211_channel_sw_ie *csa = NULL; + struct ieee80211_ext_chansw_ie *ecsa = NULL; + + if (!ies) + return false; + + csa_elem = cfg80211_find_elem(WLAN_EID_CHANNEL_SWITCH, + ies->data, ies->len); + if (csa_elem && csa_elem->datalen == sizeof(*csa)) + csa = (void *)csa_elem->data; + + ecsa_elem = cfg80211_find_elem(WLAN_EID_EXT_CHANSWITCH_ANN, + ies->data, ies->len); + if (ecsa_elem && ecsa_elem->datalen == sizeof(*ecsa)) + ecsa = (void *)ecsa_elem->data; + + if (csa && csa->count == 0) + csa = NULL; + if (csa && !csa->mode && csa->new_ch_num == cur_channel) + csa = NULL; + + if (ecsa && ecsa->count == 0) + ecsa = NULL; + if (ecsa && !ecsa->mode && ecsa->new_ch_num == cur_channel) + ecsa = NULL; + + if (ignore_ecsa && ecsa) { + sdata_info(sdata, + "Ignoring ECSA in probe response - was considered stuck!\n"); + return csa; + } + + return csa || ecsa; +} + +static bool ieee80211_mgd_csa_in_process(struct ieee80211_sub_if_data *sdata, + struct cfg80211_bss *bss) +{ + u8 cur_channel; + bool ret; + + cur_channel = ieee80211_frequency_to_channel(bss->channel->center_freq); + + rcu_read_lock(); + if (ieee80211_mgd_csa_present(sdata, + rcu_dereference(bss->beacon_ies), + cur_channel, false)) { + ret = true; + goto out; + } + + if (ieee80211_mgd_csa_present(sdata, + rcu_dereference(bss->proberesp_ies), + cur_channel, bss->proberesp_ecsa_stuck)) { + ret = true; + goto out; + } + + ret = false; +out: + rcu_read_unlock(); + return ret; +} + /* config hooks */ int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata, struct cfg80211_auth_request *req) @@ -7317,7 +7386,6 @@ int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata, struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; struct ieee80211_mgd_auth_data *auth_data; struct ieee80211_link_data *link; - const struct element *csa_elem, *ecsa_elem; u16 auth_alg; int err; bool cont_auth; @@ -7360,21 +7428,10 @@ int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata, if (ifmgd->assoc_data) return -EBUSY; - rcu_read_lock(); - csa_elem = ieee80211_bss_get_elem(req->bss, WLAN_EID_CHANNEL_SWITCH); - ecsa_elem = ieee80211_bss_get_elem(req->bss, - WLAN_EID_EXT_CHANSWITCH_ANN); - if ((csa_elem && - csa_elem->datalen == sizeof(struct ieee80211_channel_sw_ie) && - ((struct ieee80211_channel_sw_ie *)csa_elem->data)->count != 0) || - (ecsa_elem && - ecsa_elem->datalen == sizeof(struct ieee80211_ext_chansw_ie) && - ((struct ieee80211_ext_chansw_ie *)ecsa_elem->data)->count != 0)) { - rcu_read_unlock(); + if (ieee80211_mgd_csa_in_process(sdata, req->bss)) { sdata_info(sdata, "AP is in CSA process, reject auth\n"); return -EINVAL; } - rcu_read_unlock(); auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len + req->ie_len, GFP_KERNEL); @@ -7684,7 +7741,7 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata, struct ieee80211_local *local = sdata->local; struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; struct ieee80211_mgd_assoc_data *assoc_data; - const struct element *ssid_elem, *csa_elem, *ecsa_elem; + const struct element *ssid_elem; struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg; ieee80211_conn_flags_t conn_flags = 0; struct ieee80211_link_data *link; @@ -7707,6 +7764,12 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata, cbss = req->link_id < 0 ? req->bss : req->links[req->link_id].bss; + if (ieee80211_mgd_csa_in_process(sdata, cbss)) { + sdata_info(sdata, "AP is in CSA process, reject assoc\n"); + kfree(assoc_data); + return -EINVAL; + } + rcu_read_lock(); ssid_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_SSID); if (!ssid_elem || ssid_elem->datalen > sizeof(assoc_data->ssid)) { @@ -7715,20 +7778,6 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata, return -EINVAL; } - csa_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_CHANNEL_SWITCH); - ecsa_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_EXT_CHANSWITCH_ANN); - if ((csa_elem && - csa_elem->datalen == sizeof(struct ieee80211_channel_sw_ie) && - ((struct ieee80211_channel_sw_ie *)csa_elem->data)->count != 0) || - (ecsa_elem && - ecsa_elem->datalen == sizeof(struct ieee80211_ext_chansw_ie) && - ((struct ieee80211_ext_chansw_ie *)ecsa_elem->data)->count != 0)) { - sdata_info(sdata, "AP is in CSA process, reject assoc\n"); - rcu_read_unlock(); - kfree(assoc_data); - return -EINVAL; - } - memcpy(assoc_data->ssid, ssid_elem->data, ssid_elem->datalen); assoc_data->ssid_len = ssid_elem->datalen; memcpy(vif_cfg->ssid, assoc_data->ssid, assoc_data->ssid_len); -- 2.43.0