Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp1699161rwb; Fri, 13 Jan 2023 16:33:04 -0800 (PST) X-Google-Smtp-Source: AMrXdXv/UCTuyqITTy7KqNjTAJbzVg1uTvDb74qkrbe1Rd5SkqZ8vOOcNZ36pow97DYGZB21177g X-Received: by 2002:a17:906:f282:b0:84d:16d0:717 with SMTP id gu2-20020a170906f28200b0084d16d00717mr25085754ejb.65.1673656384746; Fri, 13 Jan 2023 16:33:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673656384; cv=none; d=google.com; s=arc-20160816; b=YfFBjh5U4lKZMUrTWNOpLbjGMoiCumwJ8Of7wWwkVOzJ7Gxx7UUWpVQ79CGvLB531D K133eodsOtyjGL1AmsQxh3JhVfU3KUzS30Z5MO48gQEYYR8IvGRpdESj3jkFkhqkicym SNXxkXQVReLXn0qKYblVO4S/iDaN8NBH8A+ggu2lJXxRXa9DZQHsq0nw0waSpZzd1mQm ukOhC4ssriesP0eYGrqetUn1NFBj4Qga8MmEAzYt5XKy4rmMQFFaubPV212j/UQhzPxb QFI1iqKA1b6sEfzk6y/dSgD30BespK9ZJEuwlXRW0cBWzCGWGRJGa+dwOCZX6yJPaWs6 biVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:subject :from:references:cc:to:content-language:user-agent:mime-version:date :message-id:dkim-signature; bh=73NRCJrLD416/Hi20U2Q4TjapbewKZUuWd9n2Q1rdXo=; b=s+/cC/xZob1JEisVw5x3GBrTlOUytuT71JjvNUHK8m6WoAZ9e1wfR65Nb79LIKxwXq Sg4SXPu37Y6IRZemLLC0qx8Jf+d73rINRcC4z4ilOyOKI8DHtzLZLXdwprVd3Zzyij75 hhO6xgbXpDvoP/Gl/LvYJukUt7q7NqIFADlpjF/yrnxEIwalodPOsQBdby4GgU9M49/r rCKxdnSCXY50AcnZf/Yits7OPZbELefdtOCMy40YfrFqPDgoVl0EXAVK3Dh0gowy9NU3 5Mtw7hNcTbll1uup1zxWUriS4IndBN/8UTBWlr5ppx5RJanXyp97xcWxqrlA5kZEnM8A s9DA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@schmorgal.com header.s=google header.b=J+pc8BWI; 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 xh9-20020a170906da8900b008552e7765afsi14256168ejb.936.2023.01.13.16.32.43; Fri, 13 Jan 2023 16:33:04 -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=J+pc8BWI; 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 S229797AbjANAZQ (ORCPT + 65 others); Fri, 13 Jan 2023 19:25:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229980AbjANAZO (ORCPT ); Fri, 13 Jan 2023 19:25:14 -0500 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CC4B72D2F for ; Fri, 13 Jan 2023 16:25:13 -0800 (PST) Received: by mail-pj1-x102c.google.com with SMTP id s13-20020a17090a6e4d00b0022900843652so7014569pjm.1 for ; Fri, 13 Jan 2023 16:25:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=schmorgal.com; s=google; h=content-transfer-encoding:in-reply-to:subject:from:references:cc:to :content-language:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=73NRCJrLD416/Hi20U2Q4TjapbewKZUuWd9n2Q1rdXo=; b=J+pc8BWI++mjIkGf9+Ufg4UetjhEkq6RJDj7NAgmsx6bqLqKsU9dzLJpPEGyR1cAPT 8X1ttEZyOwdX126X9LfSk2NhDYEQghA06o+a3x0qXzC7Lv04CbtXhBPeWh3VXm5/LB6F Dp4qDsSSLsnIaiKeJR9NcZvDiCdZLccZ8zlyc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:subject:from:references:cc:to :content-language:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=73NRCJrLD416/Hi20U2Q4TjapbewKZUuWd9n2Q1rdXo=; b=IwPWIdTpR6gpMKwBBexW6Hn4DEYzTJsHqnybp6g3SUUbE8SY+7rD+Q9NErHpYkW0hh p3v5u0QR+QV1tRPXdrHI2ThvC21VHB40fA4e5x3FZpMEVx52kfxksFXBJRxIwAj2RHTw 5Prn3Kup+5ergh9JyyNUgzOWLt6RDMtLgEg38bQB/Bgfbewj7jXnjgomuc12e+NZM2U5 +LWWLG9am5hPtmnbhPLoKsdLWqqbrYSGH9VXv/yQYTVB0sto4jYZUUG8s15yAtWq9/LY Nyf/HoWo03QcJTSCdB3cz52KOt1MTdoKn6NL7a2yhyBB0UYy6s/S5ooNXcs6IYr4rJyE JIvA== X-Gm-Message-State: AFqh2krOSJFFWFr1CMaPJ1QIY1j0oLbjF2HpcO1WOyD0whs/h2T5XAYP HP8FSzRQw7vCLg87D0wVo0xSAQ== X-Received: by 2002:a05:6a20:a887:b0:b8:2e75:c973 with SMTP id ca7-20020a056a20a88700b000b82e75c973mr1324301pzb.49.1673655912701; Fri, 13 Jan 2023 16:25:12 -0800 (PST) Received: from [192.168.1.33] ([192.183.212.197]) by smtp.googlemail.com with ESMTPSA id u13-20020a63f64d000000b00499bc49fb9csm12195367pgj.41.2023.01.13.16.25.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 13 Jan 2023 16:25:11 -0800 (PST) Message-ID: <1d917ac3-4bc7-2f1d-a0af-1148417c0565@schmorgal.com> Date: Fri, 13 Jan 2023 16:25:09 -0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Content-Language: en-US To: Simon Horman Cc: Dan Williams , Kalle Valo , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , libertas-dev@lists.infradead.org, linux-wireless@vger.kernel.org, netdev@vger.kernel.org References: <20230108013016.222494-1-doug@schmorgal.com> <20230108013016.222494-3-doug@schmorgal.com> From: Doug Brown Subject: Re: [PATCH v2 2/4] wifi: libertas: only add RSN/WPA IE in lbs_add_wpa_tlv In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 Hi Simon, On 1/13/2023 1:52 AM, Simon Horman wrote: > On Sat, Jan 07, 2023 at 05:30:14PM -0800, Doug Brown wrote: >> 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; > > Hi Doug, > > For correctness should type and len be converted to little endian, > f.e. using cpu_to_le16() ? > > Likewise in patch 4/4. Thank you for reviewing my changes. You are absolutely right -- this would be broken on big-endian systems. That was a major oversight on my part. Not sure how I missed it because all of the other functions do it correctly. Nice catch! I'll fix it in the next version of the series. > >> + 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 >>