Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp311010rwe; Fri, 14 Apr 2023 03:16:14 -0700 (PDT) X-Google-Smtp-Source: AKy350aCqpNwI2lKUbEVZJ4n8xHuKPrnpdZL/5eA27YDFXaDIg8sB17suFMAS6qebdaD7hk+EsAp X-Received: by 2002:a17:902:f811:b0:19f:87b5:1873 with SMTP id ix17-20020a170902f81100b0019f87b51873mr2034000plb.62.1681467374136; Fri, 14 Apr 2023 03:16:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681467374; cv=none; d=google.com; s=arc-20160816; b=zZH0b37GjtjT9iCPCyZDxMo7Cr+tZNW8y18c9S0YXHrycUbOCwvKeUUANyAbXQmWd+ BveK7Z1O8+HVITKbvsmv/GjLFaRgDGFXThGRa/pu12U4/N3iYvT9CQbDDf+NwjEB27+W 9AVCB6qsKCRsbzZwjK4yvAALv6m3qzTM70PfHIQvq1NqC7St3odMKW/JU5B74wH01lPM Lr8oe1138vwIyD0zJpLSSPPEYKJ98E/0aN7y9t1xgeXTHaFNxt2on0qn2ctQu1ZJKMXI xMowYFg2FuftJbSZzEqSghJfr7EGSzCjD4ud9WFq47OkvMRRjMBd9QFQ59ZbfZu/dzFT C6fQ== 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=5jeukLZsQF0Ojt5NW3oxEZpplJpifuyQccimemVZ4+w=; b=xvccXbbbwMI0jDGCHdRd+wMunR7QCXeBUWbi9pU91CfoZnRBl52XkkVjosNWxLJrLp 9OJsY6U6hoFS8hoA2oSeg3BO0MDj6zsS9ZqEgBeA+Dy7PSrIwh2cYgzYcLEHp58lcv2x ZKTU2gR6uW4QgwYodGAd8LijDdL61YiFkvv1lDmHuko7C5YEd+F8DdRXt23k3yefw9IP Ts7SKCv9bbN5g6LI8vfZxvqtcpNYK+eHpexGPrSIN6dlmjDbcTUIMVpRXleAEPoDF5li 0IWWcCNGN2pGJ2YGKdvw9LBeUjOXoTBKzwzUDnV14u+uKJtq1CxEXJ05qI1CKjf0IEG1 No4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZbICIJ7P; 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=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u18-20020a170902e5d200b0019926d9c734si4586869plf.602.2023.04.14.03.16.05; Fri, 14 Apr 2023 03:16:14 -0700 (PDT) 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=@intel.com header.s=Intel header.b=ZbICIJ7P; 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=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229651AbjDNKPv (ORCPT + 62 others); Fri, 14 Apr 2023 06:15:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229540AbjDNKPt (ORCPT ); Fri, 14 Apr 2023 06:15:49 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB69D6E9F for ; Fri, 14 Apr 2023 03:15:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681467327; x=1713003327; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ydlu9PSLfzaJkzTfTeo2ZfRm5WFqoiTW3gR0bQ4SnTA=; b=ZbICIJ7PODV8ZEyaAx2yJFljBtIQLLZT68nBwyow5IRdwc+0TSXRkxeA t0We/s5+uRgVV6I/Be6RgonMa6zzzQKC7TyBZlC4r4NGL8clxvtGocGbz 8WR3MQ1m09ErMBcDsVJRNx+WaDYIOGSswLkbtsXjYqyyxWtRT5CCtSpEW jO/JHG/0EDLDlAyAI3mkl9FM44fk82qvflfZVyd51XDwNEllFmHcu0Y5T ucgwusCZTrcHbJVBpi+XczLXEf2cvwUJ8s3P8hUJkrRGmvhh4iNkdtoGE kGNK3ezF50BcKQ9B9zSrqnzPo8tToDsRmWshp8C0tQBOb/9IIcAOgNutR w==; X-IronPort-AV: E=McAfee;i="6600,9927,10679"; a="346263681" X-IronPort-AV: E=Sophos;i="5.99,195,1677571200"; d="scan'208";a="346263681" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Apr 2023 03:12:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10679"; a="692351815" X-IronPort-AV: E=Sophos;i="5.99,195,1677571200"; d="scan'208";a="692351815" Received: from yalankry-mobl.ger.corp.intel.com (HELO ggreenma-mobl2.lan) ([10.214.233.156]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Apr 2023 03:12:42 -0700 From: gregory.greenman@intel.com To: johannes@sipsolutions.net Cc: linux-wireless@vger.kernel.org, Johannes Berg , Gregory Greenman Subject: [PATCH 12/15] wifi: iwlwifi: mvm: set STA mask for keys in MLO Date: Fri, 14 Apr 2023 13:12:03 +0300 Message-Id: <20230414130637.cedae2f21829.Iae07b736c3109d085ad5b74ec8282ce45020da39@changeid> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230414101206.1170180-1-gregory.greenman@intel.com> References: <20230414101206.1170180-1-gregory.greenman@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE 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 From: Johannes Berg Implement the full STA mask and selecting the correct link for key installation. While at it, catch errors if this function returns a bad zero station mask, rather than waiting for the firmware to crash on it. Signed-off-by: Johannes Berg Signed-off-by: Gregory Greenman --- .../net/wireless/intel/iwlwifi/mvm/mld-key.c | 69 ++++++++++++++++--- 1 file changed, 60 insertions(+), 9 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/mld-key.c b/drivers/net/wireless/intel/iwlwifi/mvm/mld-key.c index 9ec1c505002f..7c417b39aca4 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/mld-key.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/mld-key.c @@ -14,23 +14,68 @@ static u32 iwl_mvm_get_sec_sta_mask(struct iwl_mvm *mvm, struct ieee80211_key_conf *keyconf) { struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); + struct iwl_mvm_vif_link_info *link_info = &mvmvif->deflink; + struct iwl_mvm_link_sta *link_sta; + struct iwl_mvm_sta *mvmsta; + u32 result = 0; + int link_id; + lockdep_assert_held(&mvm->mutex); + + if (keyconf->link_id >= 0) { + link_info = mvmvif->link[keyconf->link_id]; + if (!link_info) + return 0; + } + + /* AP group keys are per link and should be on the mcast STA */ if (vif->type == NL80211_IFTYPE_AP && !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE)) - return BIT(mvmvif->deflink.mcast_sta.sta_id); + return BIT(link_info->mcast_sta.sta_id); + + /* for client mode use the AP STA also for group keys */ + if (!sta && vif->type == NL80211_IFTYPE_STATION) + sta = mvmvif->ap_sta; + + /* During remove the STA was removed and the group keys come later + * (which sounds like a bad sequence, but remember that to mac80211 the + * group keys have no sta pointer), so we don't have a STA now. + * Since this happens for group keys only, just use the link_info as + * the group keys are per link; make sure that is the case by checking + * we do have a link_id or are not doing MLO. + * Of course the same can be done during add as well, but we must do + * it during remove, since we don't have the mvmvif->ap_sta pointer. + */ + if (!sta && (keyconf->link_id >= 0 || !vif->valid_links)) + return BIT(link_info->ap_sta_id); - if (sta) { - struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); + /* this shouldn't happen now */ + if (!sta) + return 0; + mvmsta = iwl_mvm_sta_from_mac80211(sta); + + /* it's easy when the STA is not an MLD */ + if (!sta->valid_links) return BIT(mvmsta->deflink.sta_id); - } - if (vif->type == NL80211_IFTYPE_STATION && - mvmvif->deflink.ap_sta_id != IWL_MVM_INVALID_STA) - return BIT(mvmvif->deflink.ap_sta_id); + /* but if it is an MLD, get the mask of all the FW STAs it has ... */ + for (link_id = 0; link_id < ARRAY_SIZE(mvmsta->link); link_id++) { + /* unless we have a specific link in mind (GTK on client) */ + if (keyconf->link_id >= 0 && + keyconf->link_id != link_id) + continue; + + link_sta = + rcu_dereference_protected(mvmsta->link[link_id], + lockdep_is_held(&mvm->mutex)); + if (!link_sta) + continue; + + result |= BIT(link_sta->sta_id); + } - /* invalid */ - return 0; + return result; } static u32 iwl_mvm_get_sec_flags(struct iwl_mvm *mvm, @@ -113,6 +158,9 @@ int iwl_mvm_sec_key_add(struct iwl_mvm *mvm, if (WARN_ON(keyconf->keylen > sizeof(cmd.u.add.key))) return -EINVAL; + if (WARN_ON(!sta_mask)) + return -EINVAL; + if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 || keyconf->cipher == WLAN_CIPHER_SUITE_WEP104) memcpy(cmd.u.add.key + IWL_SEC_WEP_KEY_OFFSET, keyconf->key, @@ -159,6 +207,9 @@ static int _iwl_mvm_sec_key_del(struct iwl_mvm *mvm, u32 key_flags = iwl_mvm_get_sec_flags(mvm, vif, sta, keyconf); int ret; + if (WARN_ON(!sta_mask)) + return -EINVAL; + ret = __iwl_mvm_sec_key_del(mvm, sta_mask, key_flags, keyconf->keyidx, flags); if (ret) -- 2.38.1