Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87672C11F69 for ; Wed, 30 Jun 2021 06:49:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 65A1361C9C for ; Wed, 30 Jun 2021 06:49:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232445AbhF3Gvz (ORCPT ); Wed, 30 Jun 2021 02:51:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232370AbhF3Gvy (ORCPT ); Wed, 30 Jun 2021 02:51:54 -0400 Received: from sipsolutions.net (s3.sipsolutions.net [IPv6:2a01:4f8:191:4433::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE6C1C061766; Tue, 29 Jun 2021 23:49:25 -0700 (PDT) Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.94.2) (envelope-from ) id 1lyU29-00Dfk2-PY; Wed, 30 Jun 2021 08:49:17 +0200 Message-ID: <33878426ded4c2b5af3e0cd5b36fbc2e475e2f43.camel@sipsolutions.net> Subject: Re: [PATCH v2 11/12] mac80211: drop data frames without key on encrypted links From: Johannes Berg To: Pali =?ISO-8859-1?Q?Roh=E1r?= Cc: Sasha Levin , Luca Coelho , linux-wireless@vger.kernel.org, stable@vger.kernel.org Date: Wed, 30 Jun 2021 08:49:16 +0200 In-Reply-To: <20210629213214.wgypgbxor7mhutni@pali> References: <20200327150342.252AF20748@mail.kernel.org> <20210611101046.zej2t2oc6hsc67yv@pali> <804462f2381df5fb30fba7e186e62375352b8adc.camel@sipsolutions.net> <20210629213214.wgypgbxor7mhutni@pali> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.38.4 (3.38.4-1.fc33) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-malware-bazaar: not-scanned Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org On Tue, 2021-06-29 at 23:32 +0200, Pali Rohár wrote: > 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? Yes, I think so. johannes