From patchwork Thu Nov 16 18:44:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13458176 Received: from mail-qt1-f170.google.com (mail-qt1-f170.google.com [209.85.160.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 18DB463A4 for ; Thu, 16 Nov 2023 18:45:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="c4w+QzK4" Received: by mail-qt1-f170.google.com with SMTP id d75a77b69052e-41c157bbd30so6869351cf.0 for ; Thu, 16 Nov 2023 10:45:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700160307; x=1700765107; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=MIMhsRX5I6Zmn3n6vGAdEXdvE08DpBxwEnnneJtPlQM=; b=c4w+QzK4qfR97ah1i1SRypWx9tI3sM9Y1ZKzvuB+pIGAU4loCCNfpg+XfwDC8Ib9Wn 0imq3b3OKj+lqybdgrxOwCsqd9YCabRIJaoJWAZVFjtY5cXWpDmoosZoASZgujrXSlba wz2+I72G4Je6+yo/fhPF4g+mOlw4faTKLPvbD8ikBFiG0tgmB1I29fYyuQ9QlIgLXDsK pvyE6ju3gFoTlIgUfzODBu+CTeP04Hk8i23hWQ5504DM92ciBOp/7xzW2zKCxBj2raym ruomVNWoscinJtSjSPNaI+5axgcRczPhyd3BwigUSgoO4C5uUJ2QF7p95RVmjg4n7F9F WfEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700160307; x=1700765107; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=MIMhsRX5I6Zmn3n6vGAdEXdvE08DpBxwEnnneJtPlQM=; b=feWKmzv9wVinaANSaGA0kjIPvgaPBih4087ilH2RjuKhBUmQpD3LGHJkgMmrcTM1QS Aq7qcGnbtva83mTJiUrVi90eOSJHhlmMcJVwpaYk+ET633bQDW9r35R3Shctngi7rShr jUe7QVbJamk0ob9X1xJZ0B9JxgK+BC1+m2nhoIZVhWj3LpaXYNGY2qApnKbP/DpJpThc AyzKJha2ogiJ6vYWB4UwG19xjsFV9Fh6JpqHZM/faLm3aHa4qHvX5C8BNPAuEk/Y+Ey8 VIegKnOEi0rv0KE8JF1Qx8+/7vSxDGxMF79/GNZ/eUR5QJ8ZS3oQN92tKq/bYHjznR8E y92w== X-Gm-Message-State: AOJu0YxIRtWcZjJnpUtXLkTwY90cmPr14pEz+oPLjRcF0S8GuvDxk+tK jIbQRQl175vgiUCBXj0y/aAA6KglvJc= X-Google-Smtp-Source: AGHT+IHf80TYDy+TV3DrZa+t9NK+y3c/10AT72E0E7cm5LZ1o8KXfnLdNVgNWYDoZzn5/UWEdacQmA== X-Received: by 2002:ac8:5d05:0:b0:417:bd2c:2683 with SMTP id f5-20020ac85d05000000b00417bd2c2683mr12758875qtx.19.1700160306503; Thu, 16 Nov 2023 10:45:06 -0800 (PST) Received: from LOCLAP699.rst-02.locus (50-78-19-50-static.hfc.comcastbusiness.net. [50.78.19.50]) by smtp.gmail.com with ESMTPSA id b7-20020ac84f07000000b004196d75d79csm4533261qte.46.2023.11.16.10.45.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 10:45:06 -0800 (PST) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v2 1/3] dpp-util: store SSID as string, not raw buffer Date: Thu, 16 Nov 2023 10:44:57 -0800 Message-Id: <20231116184459.292601-1-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Nearly every use of the ssid member first has to memcpy it to a buffer and NULL terminate. Instead just store the ssid as a string when creating/parsing from JSON. --- src/dpp-util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dpp-util.h b/src/dpp-util.h index b5fc029c..222ba053 100644 --- a/src/dpp-util.h +++ b/src/dpp-util.h @@ -112,7 +112,7 @@ enum dpp_attribute_type { }; struct dpp_configuration { - uint8_t ssid[32]; + char ssid[33]; size_t ssid_len; uint32_t akm_suites; char *passphrase; From patchwork Thu Nov 16 18:44:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13458177 Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com [209.85.160.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E73C9CA6B for ; Thu, 16 Nov 2023 18:45:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="M2eH6GCZ" Received: by mail-qt1-f176.google.com with SMTP id d75a77b69052e-41cc535cd5cso6078641cf.2 for ; Thu, 16 Nov 2023 10:45:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700160309; x=1700765109; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IkHB3BocsRCRIYN78GjMhPcogYaQuLRPMjm82svwRe8=; b=M2eH6GCZsWS9CXFJDl8GB88E4uTuxxA9cN9aRhYkUgaOuUHvuzB0FfDh77oMUbjAoO UUc0bVjPdmBf1hjlgYHhHcPpSpjxE/qS/Xama/a95A1IDCPYa7O5RFvgv/+xmlE5hZi5 3t1DxIIEjAgpxKvs0SmlUUYqkcy81NcDBEp4y52fbVn+URHLd+79Gu8+/QF4i7bRZRVD Jd5/EnBeYryf8oEyNs0aHs6FqOOHA3LB/omGjiDHxJhPr5rOkieCP/RBCHY4cVNeLccu AtgA5XQqF/qOeddy2B36DwA44yh2dVpZnhghSK9W+9HxHPxmHzY1SWdsm/mbmNE8GHiB OelA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700160309; x=1700765109; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IkHB3BocsRCRIYN78GjMhPcogYaQuLRPMjm82svwRe8=; b=OpHKsgwFhvLs7QSzDE8q6h07wKegR8itY2LEdT88KpEdgP3UBaglP6kyKr4qBKVGOE lbvm2lgAoOouOF7MTnkY8oZK96KbZNaca1pEona7sVlJiOtgFQ+wbT/vieICANW5xBZn 7dEZhfY8gdFJ7I58wL3P0iEHSaxtNeiQibWZHiVhZ4KlVSd0IGBFlZQvpb7g/HlOOAbF s/v3ZGgYbA2iM1MDuAx5J+qPEeCllH/sB8Xv8idAFMoQKDioXeTqmB5J9LamT10WNAjw k0NKfx9930ws+YOjkbHgO8g6abh8LjUs8dYliGKFsf+fLC1iT9K7dj/J2e0reF3+EErD WWqw== X-Gm-Message-State: AOJu0YxMuavZ1Q762seVOMRf6RNfesQHCSS00yHOKpfkPBi6J2nV6BWV mQFT9ocOgEerJa17oyj/xBJY3Wk4RtY= X-Google-Smtp-Source: AGHT+IF+0+QKdKrjmnSe3DBphtiFpFa1ZvaVWUdl4fB5nNTcrZOw1BfP1d0dunjDr2ZPxy/CzaAMUw== X-Received: by 2002:ac8:7c44:0:b0:410:9111:4a0b with SMTP id o4-20020ac87c44000000b0041091114a0bmr11333247qtv.13.1700160308705; Thu, 16 Nov 2023 10:45:08 -0800 (PST) Received: from LOCLAP699.rst-02.locus (50-78-19-50-static.hfc.comcastbusiness.net. [50.78.19.50]) by smtp.gmail.com with ESMTPSA id b7-20020ac84f07000000b004196d75d79csm4533261qte.46.2023.11.16.10.45.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 10:45:08 -0800 (PST) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v2 2/3] dpp: use the new config->ssid member Date: Thu, 16 Nov 2023 10:44:58 -0800 Message-Id: <20231116184459.292601-2-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231116184459.292601-1-prestwoj@gmail.com> References: <20231116184459.292601-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This is now a NULL terminated string so it can be used directly. --- src/dpp.c | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/src/dpp.c b/src/dpp.c index 18b2a7c6..b1f9c5ac 100644 --- a/src/dpp.c +++ b/src/dpp.c @@ -809,7 +809,6 @@ static void send_config_result(struct dpp_sm *dpp, const uint8_t *to) static void dpp_write_config(struct dpp_configuration *config, struct network *network) { - char ssid[33]; _auto_(l_settings_free) struct l_settings *settings = NULL; _auto_(l_free) char *path; _auto_(l_free) uint8_t *psk = NULL; @@ -820,10 +819,7 @@ static void dpp_write_config(struct dpp_configuration *config, else settings = l_settings_new(); - memcpy(ssid, config->ssid, config->ssid_len); - ssid[config->ssid_len] = '\0'; - - path = storage_get_network_file_path(SECURITY_PSK, ssid); + path = storage_get_network_file_path(SECURITY_PSK, config->ssid); if (l_settings_load_from_file(settings, path)) { /* Remove any existing Security keys */ @@ -846,9 +842,9 @@ static void dpp_write_config(struct dpp_configuration *config, network_set_psk(network, psk); } - l_debug("Storing credential for '%s(%s)'", ssid, + l_debug("Storing credential for '%s(%s)'", config->ssid, security_to_str(SECURITY_PSK)); - storage_network_sync(SECURITY_PSK, ssid, settings); + storage_network_sync(SECURITY_PSK, config->ssid, settings); } static void dpp_scan_triggered(int err, void *user_data) @@ -937,8 +933,6 @@ static void dpp_handle_config_response_frame(const struct mmpdu_header *frame, struct station *station = station_find(netdev_get_ifindex(dpp->netdev)); struct network *network = NULL; struct scan_bss *bss = NULL; - char ssid[33]; - size_t ssid_len; if (dpp->state != DPP_STATE_CONFIGURING) return; @@ -1067,17 +1061,13 @@ static void dpp_handle_config_response_frame(const struct mmpdu_header *frame, * credentials out and be done */ if (station) { - memcpy(ssid, config->ssid, config->ssid_len); - ssid_len = config->ssid_len; - ssid[config->ssid_len] = '\0'; - - network = station_network_find(station, ssid, SECURITY_PSK); + network = station_network_find(station, config->ssid, + SECURITY_PSK); if (network) bss = network_bss_select(network, true); } dpp_write_config(config, network); - dpp_configuration_free(config); send_config_result(dpp, dpp->peer_addr); @@ -1089,19 +1079,22 @@ static void dpp_handle_config_response_frame(const struct mmpdu_header *frame, else if (station) { struct scan_parameters params = {0}; - params.ssid = (void *) ssid; - params.ssid_len = ssid_len; + params.ssid = (void *) config->ssid; + params.ssid_len = config->ssid_len; - l_debug("Scanning for %s", ssid); + l_debug("Scanning for %s", config->ssid); dpp->connect_scan_id = scan_active_full(dpp->wdev_id, ¶ms, dpp_scan_triggered, dpp_scan_results, dpp, dpp_scan_destroy); - if (dpp->connect_scan_id) + if (dpp->connect_scan_id) { + dpp_configuration_free(config); return; + } } + dpp_configuration_free(config); dpp_reset(dpp); } From patchwork Thu Nov 16 18:44:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13458178 Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7E41EACB for ; Thu, 16 Nov 2023 18:45:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EhkzZPgh" Received: by mail-qt1-f177.google.com with SMTP id d75a77b69052e-41cbf8e1f77so6851381cf.0 for ; Thu, 16 Nov 2023 10:45:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700160310; x=1700765110; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=a0RztHXs19y7K8vEwMVjpk4GbmngtwrpQSgC2fAdauU=; b=EhkzZPghTRwN1J/+e/+GhdyiyZFod8kYp+u+Ov614Z21ciZFmG6y5lprd0q99NlYAM 6MlWgfJi4j46W0YYKTAhAJJ3+EmO2VABTug/I5vSZAZpOJ/nVqYmZN6suT7ieLtvcSoJ M5A2onnMqTJQvlzK0PeuVLRU1aBiqgCQEJf+bkOXn8qoVqqO87+4xjfJZKrzAC2npQ1p in1GHosl+co4KIWy2QqrsCVDJFaWNonXe0WY6y5G7JPKu+4Zg9zJM94lTjQXu+9DzL07 18W7wBNoErWcdBAEVQrj54zY4KI0PKu74W6bZq/6HWMNjmIL3laVsAJOJ3uResT/RsdR hkEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700160310; x=1700765110; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=a0RztHXs19y7K8vEwMVjpk4GbmngtwrpQSgC2fAdauU=; b=KA2RkvUUQ+pPzi/jj0g9C1ln+XgXN/4WYZncxbGomzXpJvp24/wEw28UoxyiVT2nbO CGDlj6kkb8XIlgPDH5z1L7e0Lb2vcw15GzMQ1iysBtS1q1N2c1VoBqNLz8GTNjI9rXG7 +nh4eigB/MSQQyOMGoLMlJVquuvG5bMr1xUkJTUB7BK0h8wBNehUcshl4KCYa8Jl0XMq OIhICMaq9fEbaDyAEM1GGBzhu9CFFE6g+mZMxo2fdlkVjdnx/4AjIHqSHCFsK2ZRrYKs e1+jLvgvzKuMamIuMY/3pO50F4xEVp7yOh4KlMGIAUcQ48X//wWPsqHd3s/Qnt94WPwH J5yQ== X-Gm-Message-State: AOJu0YwUdUP1PBlftapawI958cUryE62cjBfvCEm+3I3ML3yAOgadHtR Y9dKrQB3uKIK0SejxDw9cnPRJBe47Ok= X-Google-Smtp-Source: AGHT+IEgQpksh/Zfz8RcUJytmSPh6011rqCwd3WdxPYD44xoKACpnRXNV/WS/LHDdYOTfyzldDxzDw== X-Received: by 2002:a05:622a:1714:b0:41c:bb79:ad45 with SMTP id h20-20020a05622a171400b0041cbb79ad45mr12100993qtk.12.1700160310310; Thu, 16 Nov 2023 10:45:10 -0800 (PST) Received: from LOCLAP699.rst-02.locus (50-78-19-50-static.hfc.comcastbusiness.net. [50.78.19.50]) by smtp.gmail.com with ESMTPSA id b7-20020ac84f07000000b004196d75d79csm4533261qte.46.2023.11.16.10.45.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 10:45:09 -0800 (PST) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v2 3/3] dpp: use the config's SSID to process scan results Date: Thu, 16 Nov 2023 10:44:59 -0800 Message-Id: <20231116184459.292601-3-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231116184459.292601-1-prestwoj@gmail.com> References: <20231116184459.292601-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The scan result handling was fragile because it assumed the kernel would only give results matching the requested SSID. This isn't something we should assume so instead keep the configuration object around until after the scan and use the target SSID to lookup the network. --- src/dpp.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/dpp.c b/src/dpp.c index b1f9c5ac..fab114ad 100644 --- a/src/dpp.c +++ b/src/dpp.c @@ -861,7 +861,6 @@ static bool dpp_scan_results(int err, struct l_queue *bss_list, struct dpp_sm *dpp = userdata; struct station *station = station_find(netdev_get_ifindex(dpp->netdev)); struct scan_bss *bss; - char ssid[33]; struct network *network; if (err < 0) @@ -877,18 +876,18 @@ static bool dpp_scan_results(int err, struct l_queue *bss_list, if (L_WARN_ON(station_get_connected_network(station))) goto reset; - /* Purely for grabbing the SSID */ - bss = l_queue_peek_head(bss_list); - - memcpy(ssid, bss->ssid, bss->ssid_len); - ssid[bss->ssid_len] = '\0'; - station_set_scan_results(station, bss_list, freqs, false); - network = station_network_find(station, ssid, SECURITY_PSK); + network = station_network_find(station, dpp->config->ssid, + SECURITY_PSK); dpp_reset(dpp); + if (!network) { + l_debug("Network was not found after scanning"); + return true; + } + bss = network_bss_select(network, true); network_autoconnect(network, bss); @@ -1089,7 +1088,7 @@ static void dpp_handle_config_response_frame(const struct mmpdu_header *frame, dpp_scan_results, dpp, dpp_scan_destroy); if (dpp->connect_scan_id) { - dpp_configuration_free(config); + dpp->config = config; return; } }