Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp4742575pxv; Tue, 29 Jun 2021 14:36:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzR7AY45073UAB9iPJzLboqRPMEBIaQ2A0rmEqUqmS1DBUIoiNFGshrYX4b/6Z405plapWl X-Received: by 2002:a05:6402:6ca:: with SMTP id n10mr24929332edy.122.1625002613708; Tue, 29 Jun 2021 14:36:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625002613; cv=none; d=google.com; s=arc-20160816; b=PZFCN8U7VS7TO8rdZvqz42URSmgkkNChwSE7fanCAPhP0W1aDyYWFVLDkiS0cDtksf nEw2yq7MykBDEVysF53R5oRPq0Qu5UuFSn1qKbIVYP4VTmfjBmcRXdKkeb8MahXFLbiy evpms2goBKMQbeF/Z0jCsGkt4DmpnmdodXlAAF7zyO4mg83/bAYxjrxLGGiesFReTMHb ozKDdYS4SQ765vXXVjPXuvk3AvElLagXOq0tiMuieaIfspxLM5cBYEXxZNHha5MENIFy bSbTQ15Yffx3w4MoMZpsMHAp+WXnYJ2JkYZSEQnDgtDlHCsgJ3GIbt7yyNgwctTtMB3f JyEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=4tmtR9JeyKBlVR3sziV4pEHdzkCxtFSx09yjUE4r1DM=; b=yVqB6gVKST8CPRKoTDrZcHY4rbi9k2xyDmL5FCZrNUImaAhcLErw8dWjCFoJY6EvX7 N/qiB5kWrRaolsWMBo+bJ0z1zZvSK03rJn63sljYWT1usaIM6DBntaRoKID1hGDX/NMM b9UGXw5jDvueEZCAeZA1vf/U453EsOn6PunPCARsQQ/CCsfC84wttnsNVrb8T+wUF3MQ FShSso3NApsRgABrYiK8qJTHA824VJ26FtBILWWB/92CKj4KM37VnL13TVYHlvkm9LkO EfeKcU14dkKPbnxAd3E57m+qOtF78x6sW9p9SiQJKU59qhN8m6g4zNlD4/ML5yplOprL 1bwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SFUeVkBg; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j15si18711599edq.273.2021.06.29.14.36.22; Tue, 29 Jun 2021 14:36:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SFUeVkBg; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235246AbhF2Veo (ORCPT + 99 others); Tue, 29 Jun 2021 17:34:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:34752 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232997AbhF2Veo (ORCPT ); Tue, 29 Jun 2021 17:34:44 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 765AE61D9E; Tue, 29 Jun 2021 21:32:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625002336; bh=EMiFmObauTBFjIn01Av+zLtfvMYd+HseuPo9yGQNfQA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=SFUeVkBgXF5f7LegA6lufe3ZDOD5WCnxIVsYrx0ohf1+jyg/52MRXaPZ7ldR/niza zaaEZX+dEKARd3SjRnawImGUzXGQx4QytoHtMpJxX12Jl4uXKG8egm1fuW8pIEd7mz /Y8lHdCTHLlI6IPVcr7hThwxQ9+z49IdtMANHfMwa83swuafVE/G31lpFPKtDVeoXQ QkVQefngiKTz8CvfJCV4mEZg+d2iCWU5727l8qXBu8M5ldh2zJnaPkJ+39c3/WvzFh RpDd1w+WyGOQgCANKhbwdpOztswBs9gD4vWf118sFFi1/bg7C+Xn/o9Vr5jo/RLrTp UpAKKdY/MvwLw== Received: by pali.im (Postfix) id 414E6AA8; Tue, 29 Jun 2021 23:32:14 +0200 (CEST) Date: Tue, 29 Jun 2021 23:32:14 +0200 From: Pali =?utf-8?B?Um9ow6Fy?= To: Johannes Berg Cc: Sasha Levin , Luca Coelho , linux-wireless@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v2 11/12] mac80211: drop data frames without key on encrypted links Message-ID: <20210629213214.wgypgbxor7mhutni@pali> References: <20200327150342.252AF20748@mail.kernel.org> <20210611101046.zej2t2oc6hsc67yv@pali> <804462f2381df5fb30fba7e186e62375352b8adc.camel@sipsolutions.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <804462f2381df5fb30fba7e186e62375352b8adc.camel@sipsolutions.net> User-Agent: NeoMutt/20180716 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org On Wednesday 23 June 2021 14:16:12 Johannes Berg wrote: > On Fri, 2021-06-11 at 12:10 +0200, Pali Rohár wrote: > > > > @@ -341,8 +341,11 @@ static void ieee80211_key_replace(struct ieee80211_sub_if_data *sdata, > >   if (sta) { > >   if (pairwise) { > >   rcu_assign_pointer(sta->ptk[idx], new); > > - sta->ptk_idx = idx; > > - ieee80211_check_fast_xmit(sta); > > + if (new) { > > + set_sta_flag(new->sta, WLAN_STA_USES_ENCRYPTION); > > + new->sta->ptk_idx = new->conf.keyidx; > > I'm not entirely sure moving that assignment under the guard is correct. > > > + ieee80211_check_fast_xmit(new->sta); > > and I'm pretty sure that moving call under the guard is incorrect, > although in the end it probably doesn't even matter if we will drop all > frames anyway (due to this patch). > > So all you need under the assignment is the flag, but also only > theoretically, because the function cannot be called with old==NULL && > new==NULL, the first time around it's called we must have old==NULL (no > key was ever installed), and so the first time it's called it must be > old==NULL && new!=NULL, and then the flag gets set and we never want to > clear it again, so I believe you don't need the "if (new)" condition at > all. > > In the code as it was in (and before) my patch the condition is > necessary because we use 'new' to obtain the 'sta' and 'local' pointers, > but otherwise we don't really need it even in the current version. > > johannes Now I see, thank you for explanation. So the code should be like this: if (pairwise) { rcu_assign_pointer(sta->ptk[idx], new); + set_sta_flag(sta, WLAN_STA_USES_ENCRYPTION); sta->ptk_idx = idx; ieee80211_check_fast_xmit(sta); } else { Right?