From patchwork Sun Mar 31 19:56:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Bauer X-Patchwork-Id: 1918312 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=cl6qkp7W; dkim=fail reason="signature verification failed" (4096-bit key; secure) header.d=david-bauer.net header.i=@david-bauer.net header.a=rsa-sha256 header.s=uberspace header.b=w43oT/Rl; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4V74gl3fBCz1yYB for ; Mon, 1 Apr 2024 06:57:55 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To :From:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=BR3vF+nDnnOJSehIn6jPStn/LNMigXL6pPToXqO8+Og=; b=cl6qkp7W/poFsm yUrQ6xVABUCUDma3p3S3ZtUrH6Bb9qacTMsyb3pLcXBni90T+sy/HJhsfbnVX0iuVcmpZrUyyvHSO jzxcn6YP4cT9HJjmvoPfqHL84sQVPwGGxVBxY/qbKu3ep47qPPONReicPEVDwEPqR4rlwCCjcsR/p 2T0ZNaodiqsR/8+nnaUS151CBrVseOO0wywpbCIfminfX84nUUIJqzGldRW2fWOesCP2wdaFysue4 WSTI/LkkAKKzTU+fEp1BLACdASRAQ6mfM4DtYTKZh2tUe+S9gC7w+xhMc+e8DZ58KNtXa34/76OIT RGlIqjJxEsWB6yvrXwVA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rr1Iu-00000006Cv9-2GrK; Sun, 31 Mar 2024 19:57:20 +0000 Received: from perseus.uberspace.de ([95.143.172.134]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rr1Ii-00000006CsH-3lnP for hostap@lists.infradead.org; Sun, 31 Mar 2024 19:57:12 +0000 Received: (qmail 22516 invoked by uid 988); 31 Mar 2024 19:56:51 -0000 Authentication-Results: perseus.uberspace.de; auth=pass (plain) Received: from unknown (HELO unkown) (::1) by perseus.uberspace.de (Haraka/3.0.1) with ESMTPSA; Sun, 31 Mar 2024 21:56:51 +0200 From: David Bauer To: hostap@lists.infradead.org Subject: [PATCH 1/4] wpa_supplicant: reduce OWE transition network code duplication Date: Sun, 31 Mar 2024 21:56:40 +0200 Message-ID: <20240331195643.47587-1-mail@david-bauer.net> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Rspamd-Bar: - X-Rspamd-Report: MID_CONTAINS_FROM(1) BAYES_HAM(-3) MIME_GOOD(-0.1) R_MISSING_CHARSET(0.5) X-Rspamd-Score: -1.6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=david-bauer.net; s=uberspace; h=from:to:subject:date; bh=DjHJJGnME+/Fj4kdGFsATw5ImC+Yh0463INC43zyIac=; b=w43oT/Rly/PiDs7vkktskdpbDjjFB3IBeG+cn+zNExRtvPNz5LyXF+6J8gCLXNDPfsbVzSqI9E IMOcK8ZAM9GSHQJ6PvJDORy99rRjBSWmzFAUvv8JhGy9liZlrlphD6u9GoNVn+WEaqJgpY73lfZn ozESwfvB1fJKjWHc3tpDOI7sXSbpSOMy23P0RrP4B15rQ+x/FLtcnw+/6XKOeQFTfg5XGSraFbeX DfdzxsHvBjkaCdrxx7GNVgQAd6awyhQT9YxkK6T5/8AIS2jxE39/iPJaXHVlpTV9N6uUzQMEvm79 H0YOmxO5ZK0yEkSQojJkvX1oXJ3kDowN1sr/d25019RAoqyowEAvcQ3PFwLsxFAsj5atfoA5Hywb oDTKmV9CcaSsjCbyroz7vW0n1jflSghXWp7PiutX0u9IMmvlpaFv76/LixNBSyPmIuMwYAC+o9sd 9XrpFiVaN49Ejw37u66ebeUSrjVzIWes2C5zgq16h2iv+ycpDq+NlzuGUe+pmq6m8WlLZ3tZwEce 56YYPT6Oi2OyxMcv8INMYuEI9+jeshLISTTN/QR9I5/sG7Sn5CnuCA3hA/xg6W4peMf6+8Su9RAs 9GVrSNNgRihtgzW1VDQau10HMS2EoLzga/o8vgmgnysW3dCWwHxzGzVei+L0x3PRuKUngJ4L9n4S 0= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240331_125709_565082_C6295761 X-CRM114-Status: GOOD ( 16.29 ) X-Spam-Score: -0.9 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Reduce the code-duplication for methods handling the OWE transition mode. This is required for adding bgscan support for transition networks. Signed-off-by: David Bauer --- wpa_supplicant/bss.c | 30 ++++++++++++++++++++++++++++++ wpa_supplicant/bss.h | 2 ++ wpa_supplicant/events.c | 21 +++++ wpa_suppli [...] Content analysis details: (-0.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [95.143.172.134 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: hostap@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Hostap" Errors-To: hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Reduce the code-duplication for methods handling the OWE transition mode. This is required for adding bgscan support for transition networks. Signed-off-by: David Bauer --- wpa_supplicant/bss.c | 30 ++++++++++++++++++++++++++++++ wpa_supplicant/bss.h | 2 ++ wpa_supplicant/events.c | 21 +++++---------------- wpa_supplicant/scan.c | 20 +++----------------- wpa_supplicant/wpa_supplicant.c | 17 +++++------------ 5 files changed, 45 insertions(+), 45 deletions(-) diff --git a/wpa_supplicant/bss.c b/wpa_supplicant/bss.c index 289035310..c213d15ad 100644 --- a/wpa_supplicant/bss.c +++ b/wpa_supplicant/bss.c @@ -817,6 +817,36 @@ void wpa_bss_update_start(struct wpa_supplicant *wpa_s) wpa_s->last_scan_res_used = 0; } +int wpa_bss_get_owe_trans_network(struct wpa_supplicant *wpa_s, const u8 *owe_ie, + const u8 **bssid, const u8 **ssid, size_t *ssid_len) +{ +#ifdef CONFIG_OWE + const u8 *pos, *end; + u8 ssid_len_tmp; + + if (!owe_ie) + return 1; + + pos = owe_ie + 6; + end = owe_ie + 2 + owe_ie[1]; + + if (end - pos < ETH_ALEN + 1) + return 1; + *bssid = pos; + pos += ETH_ALEN; + ssid_len_tmp = *pos++; + if (end - pos < ssid_len_tmp || ssid_len_tmp > SSID_MAX_LEN) + return 1; + + *ssid = pos; + *ssid_len = ssid_len_tmp; + + return 0; +#else /* CONFIG_OWE */ + return 1; +#endif /* CONFIG_OWE */ +} + /** * wpa_bss_update_scan_res - Update a BSS table entry based on a scan result diff --git a/wpa_supplicant/bss.h b/wpa_supplicant/bss.h index cc0496324..8acedbce7 100644 --- a/wpa_supplicant/bss.h +++ b/wpa_supplicant/bss.h @@ -185,6 +185,8 @@ struct wpabuf * wpa_bss_get_vendor_ie_multi_beacon(const struct wpa_bss *bss, u32 vendor_type); int wpa_bss_get_max_rate(const struct wpa_bss *bss); int wpa_bss_get_bit_rates(const struct wpa_bss *bss, u8 **rates); +int wpa_bss_get_owe_trans_network(struct wpa_supplicant *wpa_s, const u8 *owe_ie, + const u8 **bssid, const u8 **ssid, size_t *ssid_len); struct wpa_bss_anqp * wpa_bss_anqp_alloc(void); int wpa_bss_anqp_unshare_alloc(struct wpa_bss *bss); const u8 * wpa_bss_get_fils_cache_id(const struct wpa_bss *bss); diff --git a/wpa_supplicant/events.c b/wpa_supplicant/events.c index ca2794638..b620e3f6a 100644 --- a/wpa_supplicant/events.c +++ b/wpa_supplicant/events.c @@ -1108,30 +1108,19 @@ static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, const u8 **ret_ssid, size_t *ret_ssid_len) { #ifdef CONFIG_OWE - const u8 *owe, *pos, *end, *bssid; - u8 ssid_len; + const u8 *owe, *bssid; owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE); if (!owe || !wpa_bss_get_ie(bss, WLAN_EID_RSN)) return; - pos = owe + 6; - end = owe + 2 + owe[1]; - - if (end - pos < ETH_ALEN + 1) - return; - bssid = pos; - pos += ETH_ALEN; - ssid_len = *pos++; - if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN) + if (wpa_bss_get_owe_trans_network(wpa_s, owe, &bssid, ret_ssid, ret_ssid_len)) return; /* Match the profile SSID against the OWE transition mode SSID on the * open network. */ wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR - " SSID: %s", MAC2STR(bssid), wpa_ssid_txt(pos, ssid_len)); - *ret_ssid = pos; - *ret_ssid_len = ssid_len; + " SSID: %s", MAC2STR(bssid), wpa_ssid_txt(*ret_ssid, *ret_ssid_len)); if (!(bss->flags & WPA_BSS_OWE_TRANSITION)) { struct wpa_ssid *ssid; @@ -1139,8 +1128,8 @@ static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { if (wpas_network_disabled(wpa_s, ssid)) continue; - if (ssid->ssid_len == ssid_len && - os_memcmp(ssid->ssid, pos, ssid_len) == 0) { + if (ssid->ssid_len == *ret_ssid_len && + os_memcmp(ssid->ssid, ret_ssid, *ret_ssid_len) == 0) { /* OWE BSS in transition mode for a currently * enabled OWE network. */ wpa_dbg(wpa_s, MSG_DEBUG, diff --git a/wpa_supplicant/scan.c b/wpa_supplicant/scan.c index 2db4d8b91..9e6d6d8d9 100644 --- a/wpa_supplicant/scan.c +++ b/wpa_supplicant/scan.c @@ -948,8 +948,7 @@ static void wpa_add_owe_scan_ssid(struct wpa_supplicant *wpa_s, wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { - const u8 *owe, *pos, *end; - const u8 *owe_ssid; + const u8 *owe, *owe_bssid, *owe_ssid; size_t owe_ssid_len; if (bss->ssid_len != ssid->ssid_len || @@ -960,21 +959,8 @@ static void wpa_add_owe_scan_ssid(struct wpa_supplicant *wpa_s, if (!owe || owe[1] < 4) continue; - pos = owe + 6; - end = owe + 2 + owe[1]; - - /* Must include BSSID and ssid_len */ - if (end - pos < ETH_ALEN + 1) - return; - - /* Skip BSSID */ - pos += ETH_ALEN; - owe_ssid_len = *pos++; - owe_ssid = pos; - - if ((size_t) (end - pos) < owe_ssid_len || - owe_ssid_len > SSID_MAX_LEN) - return; + if (wpa_bss_get_owe_trans_network(wpa_s, owe, &owe_bssid, &owe_ssid, &owe_ssid_len)) + continue; wpa_printf(MSG_DEBUG, "OWE: scan_ssids: transition mode OWE ssid=%s", diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c index ab71e2f27..c7420b5e0 100644 --- a/wpa_supplicant/wpa_supplicant.c +++ b/wpa_supplicant/wpa_supplicant.c @@ -5272,8 +5272,8 @@ int wpa_supplicant_set_debug_params(struct wpa_global *global, int debug_level, static int owe_trans_ssid_match(struct wpa_supplicant *wpa_s, const u8 *bssid, const u8 *entry_ssid, size_t entry_ssid_len) { - const u8 *owe, *pos, *end; - u8 ssid_len; + const u8 *owe, *owe_bssid, *owe_ssid; + size_t owe_ssid_len; struct wpa_bss *bss; /* Check network profile SSID aganst the SSID in the @@ -5287,18 +5287,11 @@ static int owe_trans_ssid_match(struct wpa_supplicant *wpa_s, const u8 *bssid, if (!owe) return 0; - pos = owe + 6; - end = owe + 2 + owe[1]; - - if (end - pos < ETH_ALEN + 1) - return 0; - pos += ETH_ALEN; - ssid_len = *pos++; - if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN) + if (wpa_bss_get_owe_trans_network(wpa_s, owe, &owe_bssid, &owe_ssid, &owe_ssid_len)) return 0; - return entry_ssid_len == ssid_len && - os_memcmp(pos, entry_ssid, ssid_len) == 0; + return entry_ssid_len == owe_ssid_len && + os_memcmp(owe_ssid, entry_ssid, owe_ssid_len) == 0; } #endif /* CONFIG_OWE */