Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp4387870rwl; Sat, 7 Jan 2023 17:35:43 -0800 (PST) X-Google-Smtp-Source: AMrXdXt7Pq/DV9zkevcFIgUfBAPkDhGBwLYeF6lgHB1ruJxC7De4B5a+JKvLyKILaMkGuxa1jtHf X-Received: by 2002:a17:907:8e87:b0:84c:a863:ebe6 with SMTP id tx7-20020a1709078e8700b0084ca863ebe6mr26971683ejc.43.1673141743716; Sat, 07 Jan 2023 17:35:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673141743; cv=none; d=google.com; s=arc-20160816; b=hrE91XJ1uiuidwnIj0cNhkJTqjnQTVpDg99Erxn1aBIpSPYOjdfIdIUmUEVZKDP0x/ 11/qCCpIEBjlRDVPXthInqJRrf2T/E3FSS7dkMqT56TLzH0PbbvSZ0kw03t8tGEDk+KI FR/IVOngwNMnKy9YRDlr2LLYiOUeEpnN2zKKsy2i8ESGDaNs9TJplg1ygmrpwfxMfyPP HG3DZ5djE4GB30vqoT4dSYzWXWZ1xSwEXSZFexTOc+AwcLsSLl+HEjSu4MxnzH2w2tqR INOSsZT1qLryFPoViv8HQ40n5A6I0E5dNw/E+wu4XP4ruQ8s2YhBcRoiiavXUFgYnp+x +m8w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gZnUzt96M2CHw2T17VotljT7ugAqa2z/W5TDXEKxdek=; b=thczhCpiD3LiOklmyUrVp+piUocdDKw6ctYWoFYMdBYaBBIe4ymqJ6yUILSUlT0K15 EeVUu0HbDBMknUieqVUA12LT4Cthw4Utmr5Ydr6MKZPONb6rnZR7p3YrNfZXvcQtSzoi jJBK9ahrTv7rkFNeOMRfNW8SFEFgk1Bl4x/kBcelQJY1/nej7xYbr5KxfS0VxiYGVUPm Q+qbGTfbgOww2Mb7NDnqmZnGkiU/VAVt0gaLbKrVu9IzY/ONOfU2Yvh8DCv6zjvSRucW j85X9CsyZ6Lk4ytrKsv4Tuxdk1B0jSfeDSe5fgrStk5k8eWzG4kee+bremOg2pPLU8kY 6yMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@schmorgal.com header.s=google header.b=a8Aw21md; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=schmorgal.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e21-20020a17090658d500b007adaedb2f14si6062329ejs.866.2023.01.07.17.35.27; Sat, 07 Jan 2023 17:35:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless-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=@schmorgal.com header.s=google header.b=a8Aw21md; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=schmorgal.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232110AbjAHBbD (ORCPT + 65 others); Sat, 7 Jan 2023 20:31:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232106AbjAHBbA (ORCPT ); Sat, 7 Jan 2023 20:31:00 -0500 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EB473633E for ; Sat, 7 Jan 2023 17:30:59 -0800 (PST) Received: by mail-pg1-x535.google.com with SMTP id 78so3649329pgb.8 for ; Sat, 07 Jan 2023 17:30:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=schmorgal.com; s=google; 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=gZnUzt96M2CHw2T17VotljT7ugAqa2z/W5TDXEKxdek=; b=a8Aw21mdqnBwiNQAC6YlwGKZTGrHdKVqz7GMHC9WUOUEApaCqM9bbx4CS0jeBEldiO 3EbAzVDuDCdpzpp4FLt15YdjwnY7FuBVjvKBr6HMWCbkMH6r73KxFhqJH0611ipJ9njb ZFFIyOAUDrNACu+h+usurCdIeGQ07p40ATepQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=gZnUzt96M2CHw2T17VotljT7ugAqa2z/W5TDXEKxdek=; b=lbPBNHBBYJAzFPX6PXalOCfU3IdL7IQ3reE/9iZtdaTF6z0XAf9yAPKMtI5mPumbfZ kGl5MIuUukL2LaL65U+yNsGba/624mQ5xiRQYm3RY4XDbUSXT3FVagYWCF0b2OAHwTE4 TAm9qN0Ns5uoUEweRZ24zD0QVBxlAQCl/BujW2fEYcxK/GWZEC4fdN81gnwzZZMHLbpI u+FcGNUnbJxyFhdXs+XMKvbiuH+Y8ahGdrK8IAiIkDlQoVQWKsZJ9zfByst5Q6IiTOE0 NgRYf4zhbo1K7NLByRQyzDJsT3htm1h5QpRTlaL/C2bVTksXFkt/pA9yYctqAMLF0xtH jGAA== X-Gm-Message-State: AFqh2kr2ujJ66MM0JrUIBSTfLpXKat4MWFjRYadgCx4nUa0ewpBTaVt2 38lc27VcrCt+gEytdIaH1SObAg== X-Received: by 2002:a05:6a00:1485:b0:574:251b:c5fe with SMTP id v5-20020a056a00148500b00574251bc5femr71889826pfu.20.1673141458702; Sat, 07 Jan 2023 17:30:58 -0800 (PST) Received: from doug-ryzen-5700G.. ([192.183.212.197]) by smtp.gmail.com with ESMTPSA id x14-20020aa79a4e000000b005811c421e6csm3323714pfj.162.2023.01.07.17.30.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Jan 2023 17:30:58 -0800 (PST) From: Doug Brown To: Dan Williams , Kalle Valo , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: libertas-dev@lists.infradead.org, linux-wireless@vger.kernel.org, netdev@vger.kernel.org, Doug Brown Subject: [PATCH v2 2/4] wifi: libertas: only add RSN/WPA IE in lbs_add_wpa_tlv Date: Sat, 7 Jan 2023 17:30:14 -0800 Message-Id: <20230108013016.222494-3-doug@schmorgal.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230108013016.222494-1-doug@schmorgal.com> References: <20230108013016.222494-1-doug@schmorgal.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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-wireless@vger.kernel.org The existing code only converts the first IE to a TLV, but it returns a value that takes the length of all IEs into account. When there is more than one IE (which happens with modern wpa_supplicant versions for example), the returned length is too long and extra junk TLVs get sent to the firmware, resulting in an association failure. Fix this by finding the first RSN or WPA IE and only adding that. This has the extra benefit of working properly if the RSN/WPA IE isn't the first one in the IE buffer. While we're at it, clean up the code to use the available structs like the other lbs_add_* functions instead of directly manipulating the TLV buffer. Signed-off-by: Doug Brown --- drivers/net/wireless/marvell/libertas/cfg.c | 28 +++++++++++++-------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/drivers/net/wireless/marvell/libertas/cfg.c b/drivers/net/wireless/marvell/libertas/cfg.c index 3e065cbb0af9..5cd78fefbe4c 100644 --- a/drivers/net/wireless/marvell/libertas/cfg.c +++ b/drivers/net/wireless/marvell/libertas/cfg.c @@ -416,10 +416,20 @@ static int lbs_add_cf_param_tlv(u8 *tlv) static int lbs_add_wpa_tlv(u8 *tlv, const u8 *ie, u8 ie_len) { - size_t tlv_len; + struct mrvl_ie_data *wpatlv = (struct mrvl_ie_data *)tlv; + const struct element *wpaie; + + /* Find the first RSN or WPA IE to use */ + wpaie = cfg80211_find_elem(WLAN_EID_RSN, ie, ie_len); + if (!wpaie) + wpaie = cfg80211_find_vendor_elem(WLAN_OUI_MICROSOFT, + WLAN_OUI_TYPE_MICROSOFT_WPA, + ie, ie_len); + if (!wpaie || wpaie->datalen > 128) + return 0; /* - * We need just convert an IE to an TLV. IEs use u8 for the header, + * Convert the found IE to a TLV. IEs use u8 for the header, * u8 type * u8 len * u8[] data @@ -428,14 +438,12 @@ static int lbs_add_wpa_tlv(u8 *tlv, const u8 *ie, u8 ie_len) * __le16 len * u8[] data */ - *tlv++ = *ie++; - *tlv++ = 0; - tlv_len = *tlv++ = *ie++; - *tlv++ = 0; - while (tlv_len--) - *tlv++ = *ie++; - /* the TLV is two bytes larger than the IE */ - return ie_len + 2; + wpatlv->header.type = wpaie->id; + wpatlv->header.len = wpaie->datalen; + memcpy(wpatlv->data, wpaie->data, wpaie->datalen); + + /* Return the total number of bytes added to the TLV buffer */ + return sizeof(struct mrvl_ie_header) + wpaie->datalen; } /* -- 2.34.1