From patchwork Thu Nov 16 19:15:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13458185 Received: from mail-oa1-f41.google.com (mail-oa1-f41.google.com [209.85.160.41]) (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 A3FCF39FE4 for ; Thu, 16 Nov 2023 19:15:34 +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="O1uB6G9U" Received: by mail-oa1-f41.google.com with SMTP id 586e51a60fabf-1f00b95dc43so590413fac.3 for ; Thu, 16 Nov 2023 11:15:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700162133; x=1700766933; 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=5p7Rgi5L+nZrByKZkLl2tNJctmiQjmc/zPDM+w8NMT4=; b=O1uB6G9URHb2htZzB8c4SOtNlEyYaUznaNeCEKxoaUeTt+8/78wAFHzCnBS1smTySb RsPtFhDz1tFH6aZS/Kw9JgpbBsnl+FEM/gRJCohPBvrJ6+kUZ7CRKFaQyjB0Ngd7/zas 4FLbIA9SJ6BB2jh/aih/mSGtaKaHqyF+R3D4FKac53ZF51Ag0WZ1+U9haPskCioAce0K ratKBwi/2RKujbrOafaE4UMP6UEWw+mxH/sACEsUE+cucyEksizfqXvjiUhFCvPReebv UQo7HKQggxIYo61neACHeB6Qgro8tsBJICJzJAIizi2/4QH6PvThR4pL10qMPpY1kXE4 HJpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700162133; x=1700766933; 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=5p7Rgi5L+nZrByKZkLl2tNJctmiQjmc/zPDM+w8NMT4=; b=crK9R8hgzAHbS2jdWH1L63npfbloDdU0+QWmEGBJlVVdupDE6go3fiswlNvtOjcWK8 ObPH8fApP1+nkppCGao0+OIBec8zPlfZgJiRi6H+DAN3P0hPUH4STQqTryUAhfwXFPBC 0sloRMwr+c4TkT0P0CNLP3jzEEXB6k9D0tfurL/EiL0jyRyh5YhotL9GRgzHUTcYa452 VaMyDJn4gBvYqyNLy86FSo0OIUBxbWE07mp3vU42HL2uqh9rT4bYqHuFv/F1I4JDvp4+ pA+NeopN38aOgYEEEr7byeyJ4zTzgQsUWGcObqtE4vp9Zzg16dmHgJCQUm7yQC0Aj2Kl v/gA== X-Gm-Message-State: AOJu0YwhZqekheRZJTGM2Pb2CnzMQTOGfVNT53F1OKL/XTgg4No824b9 b3IZrTddVlyMGmbMPgQKa6EI0nLC6So= X-Google-Smtp-Source: AGHT+IEqn9zJKJBTPFwBM2zatEUEgT8MNqNwCXa+mft7n1LPotqDI2RsUS4Z+gQ32J9qkq6Ezd38yA== X-Received: by 2002:a05:6870:ac8f:b0:1ef:81dd:34b3 with SMTP id ns15-20020a056870ac8f00b001ef81dd34b3mr21500445oab.59.1700162133280; Thu, 16 Nov 2023 11:15:33 -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 c14-20020ac8660e000000b004198d026be6sm4376qtp.35.2023.11.16.11.15.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 11:15:32 -0800 (PST) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v3 1/3] dpp-util: store SSID as string, not raw buffer Date: Thu, 16 Nov 2023 11:15:26 -0800 Message-Id: <20231116191528.364340-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 053caf8c..0724ee44 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 19:15:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13458186 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 0EE3B39FE4 for ; Thu, 16 Nov 2023 19:15:36 +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="iYS7QKJ8" Received: by mail-qt1-f170.google.com with SMTP id d75a77b69052e-41cc44736f2so7027261cf.3 for ; Thu, 16 Nov 2023 11:15:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700162135; x=1700766935; 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=UJ59JXAT4S8TzjACMcbVJFVWJVTCoy1LWfuPZx0+EmQ=; b=iYS7QKJ8v8baL9ZYuJkVNBOvqMQR+zN21Y+FqBLQKSsGpSO3QuPhRlS6NTw1dcLVXR y5S0Twn12dWBs/hpa2uOhDJZNH0fX9diMUgSgRePScRimfuyOeuWA5s/Aj3h5bodF5KK /JUV66TUQ9zMORqD0aA7Mkw4KGMxnuEOkyLWFT5xXf/kqUZrzp0fZKROuqJI37MoI8AI 39oNkesLYjjHMuRWDvX9KO68TxYm1nXUj/Q9xtVGMIAcLbzSu5q0pgF/EzRD8FIWT8fj H3AppxW4Z3m8rVgRvIL4b+mEIqILYiOH06wG0kbB4nrPf8PPvnMWR2acnOhitTj92sEW JFLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700162135; x=1700766935; 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=UJ59JXAT4S8TzjACMcbVJFVWJVTCoy1LWfuPZx0+EmQ=; b=DXiiTBFmwz30f8wcBYKXjte3FO8cQ9aKuTMtdECTDEgGF6GpKEC7I655SzkEbXM3ZQ dJKKPzSizcM3s2m4jXnV7UQg4LFZQvsSF5KVxtFJVKnexwm3COTBpK9ncYxCcrk32UEX se5mrrTdOfIfghNulTTt9Xhic/BY6DupKGd5MK1FDSKBbmzITI3Da7Z/LEcvRLRU/VPJ Sqa2u2/Zgm/Jy41vFnxsZ90YvfNrrWmOi+G/FHApSpnt5iRWMRQi8RfNdyPczu63feS7 mRlSt/aOvMZUzuKAsMiHSH7XCWi/QPV8PGCAD9/5EQuZX1O7jHlumXUmp2nJsy4CAmZV QFUA== X-Gm-Message-State: AOJu0Yyft19+Kz/R9nBesoWpvUkk3qjJNjLN6tWhbeNHv2T2A70cGsdA n9vy3MxFlmT1j5hrW/D2LaP/Yi3aFx4= X-Google-Smtp-Source: AGHT+IEBbAqdFSPxdPn3G+3lFrxtw3yochscYFXwFPRDeaACjy/QiaZz03ojCEHxD3iTLPOv5Kw6zw== X-Received: by 2002:a05:622a:1315:b0:419:5767:af55 with SMTP id v21-20020a05622a131500b004195767af55mr11075956qtk.16.1700162135438; Thu, 16 Nov 2023 11:15:35 -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 c14-20020ac8660e000000b004198d026be6sm4376qtp.35.2023.11.16.11.15.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 11:15:34 -0800 (PST) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v3 2/3] dpp: use the new config->ssid member Date: Thu, 16 Nov 2023 11:15:27 -0800 Message-Id: <20231116191528.364340-2-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231116191528.364340-1-prestwoj@gmail.com> References: <20231116191528.364340-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 36d5d62e..907f3bf5 100644 --- a/src/dpp.c +++ b/src/dpp.c @@ -809,16 +809,12 @@ 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 = l_settings_new(); _auto_(l_free) char *path; _auto_(l_free) uint8_t *psk = NULL; size_t psk_len; - 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 */ @@ -841,9 +837,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) @@ -932,8 +928,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; @@ -1062,17 +1056,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); @@ -1084,19 +1074,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 19:15:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13458187 Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) (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 3FC7C3A8E8 for ; Thu, 16 Nov 2023 19:15:38 +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="Yiu5BIfI" Received: by mail-qt1-f180.google.com with SMTP id d75a77b69052e-421bcd0b532so6966101cf.2 for ; Thu, 16 Nov 2023 11:15:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700162137; x=1700766937; 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=MEhNSsPteBp0+f9lTaP9Yww42aaSUth8c3O/YHkdmnQ=; b=Yiu5BIfIgc22VlB5U3jFr7QafB/WPwdGaD8naL98uWpXN8vEizFB0aILFN+8O+/0AV SeBjApRUBfEp3BCPYPgJ7as7HSRtdyd4UGBU6as3LQ8zz3bYsZVniwB2TuXxIScR43tt zTBIueblDdp7n+Hg7TstldXAvPh/a6oH1B9ZUMJAeFN2hzUZo1M6l3CVCJC5cbEiFhQb 1Ct8s6EVAukcKtvzi0OqXpbApog9yZKpzypLw9LX6A5+EspWmKDXh7rKJX0WngkjKHkf 4uWSArQRHjwrqgQeu1VxGaKSjpuOQpRm8eU9YgDUnBZjmluQNx5GvG3HZxfjaItn/O5k PaNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700162137; x=1700766937; 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=MEhNSsPteBp0+f9lTaP9Yww42aaSUth8c3O/YHkdmnQ=; b=Zi7korOvG1b2XByNJit01pnxlP8QfZI8EbrV0a50xvEEETHS5NzDItmtbxOf9uWjl8 EFq7YG/ngaRPx0j/QzYEw4A9UeQhxFxer3XW1+AwgeRn/6l1JhQi8OhIRmznJX58Pi1U P9Nv5Z3Rq+haBwZmXO13P1aYcGK9h9pS84zOokNUjHVIRpKToRQaBDsaaKXC9ABwUIUk CMhnyWHxfx41DlyYy0MFkFOm66fkYPoprQwKL9oBkH/Wf7Y/uou5J3pHRoIBwcYeUVO7 WAXjrVLuXRE6CPWmPyfY9P4ZxCt4qLSCN+dYD+QQlpGqF9lnVUpKe6xtM5lSRMeL4KwI Q6HA== X-Gm-Message-State: AOJu0Yyys8Ct3O/v1XfRHgkUlGfYgWhQxCLnjZjTL2G/196cwK74VBxm WGuJcF/l5g/iOCq9Pa6ucnPVMB1RS+s= X-Google-Smtp-Source: AGHT+IEQEsXlxefx4eTVWTEeqPegYzqxTDRXJAEGrCKRpwnKARt5bskCwM6fF8FLo3edEZXFRYPuEA== X-Received: by 2002:ac8:5d05:0:b0:417:bd2c:2683 with SMTP id f5-20020ac85d05000000b00417bd2c2683mr12880373qtx.19.1700162136960; Thu, 16 Nov 2023 11:15:36 -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 c14-20020ac8660e000000b004198d026be6sm4376qtp.35.2023.11.16.11.15.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 11:15:36 -0800 (PST) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v3 3/3] dpp: use the config's SSID to process scan results Date: Thu, 16 Nov 2023 11:15:28 -0800 Message-Id: <20231116191528.364340-3-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231116191528.364340-1-prestwoj@gmail.com> References: <20231116191528.364340-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 907f3bf5..f8d76805 100644 --- a/src/dpp.c +++ b/src/dpp.c @@ -856,7 +856,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) @@ -872,18 +871,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); @@ -1084,7 +1083,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; } }