linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Berg <johannes@sipsolutions.net>
To: Alexander Wetzel <alexander@wetzel-home.de>
Cc: linux-wireless@vger.kernel.org
Subject: Re: [RFC PATCH v3 03/12] mac80211: IEEE 802.11 Extended Key ID support
Date: Fri, 15 Feb 2019 12:06:46 +0100	[thread overview]
Message-ID: <f4d8db23bc3804fdc98f2ce7a702215bd82fd4e3.camel@sipsolutions.net> (raw)
In-Reply-To: <20190210210620.31181-4-alexander@wetzel-home.de>

On Sun, 2019-02-10 at 22:06 +0100, Alexander Wetzel wrote:
> 
>  - Enforce cipher does not change when replacing a key.

is that actually required somehow?

> + * @EXT_SET_KEY: a new key must be set but is only valid for decryption
> + * @EXT_KEY_RX_TX: a key installed with @EXT_SET_KEY is becoming the
> + *	designated Rx/Tx key for the station

Not sure I like the EXT_SET_KEY. There's also no "designated Rx key", is
there? It's always selected by key ID.

How about SET_KEY_RXONLY and SET_KEY_TX or something like that?

> +static int ieee80211_set_tx_key(struct ieee80211_sub_if_data *sdata,
> +				const u8 *mac_addr, u8 key_idx)
> +{
> +	struct ieee80211_local *local = sdata->local;
> +	struct ieee80211_key *key;
> +	struct sta_info *sta;
> +	int ret;
> +
> +	if (!wiphy_ext_feature_isset(local->hw.wiphy,
> +				     NL80211_EXT_FEATURE_EXT_KEY_ID))
> +		return -EINVAL;

You set this, wouldn't it make more sense to check EXT_KEY_ID_NATIVE?

Or maybe this is because of the next patch?

> +	sta = sta_info_get_bss(sdata, mac_addr);
> +
> +	if (!sta)
> +		return -EINVAL;
> +
> +	if (sta->ptk_idx == key_idx)
> +		return 0;
> +
> +	mutex_lock(&local->key_mtx);
> +	key = key_mtx_dereference(local, sta->ptk[key_idx]);
> +
> +	if (key && key->flags & KEY_FLAG_RX_ONLY)

do you even need the flag? Isn't it equivalent to checking
	sta->ptk_idx != key->idx
or so?

Less data to maintain would be better.

> +	bool ext_native = ieee80211_hw_check(&local->hw, EXT_KEY_ID_NATIVE);

you sort of only need this in the next patch, but I guess it doesn't
matter that much

> +int ieee80211_key_activate_tx(struct ieee80211_key *key)
> +{
> +	struct ieee80211_sub_if_data *sdata = key->sdata;
> +	struct sta_info *sta = key->sta;
> +	struct ieee80211_local *local = key->local;
> +	struct ieee80211_key *old;
> +	int ret;
> +
> +	assert_key_lock(local);
> +
> +	key->flags &= ~KEY_FLAG_RX_ONLY;
> +
> +	if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) ||
> +	    key->conf.flags & (IEEE80211_KEY_FLAG_GENERATE_MMIC |
> +			       IEEE80211_KEY_FLAG_PUT_MIC_SPACE |
> +			       IEEE80211_KEY_FLAG_RESERVE_TAILROOM))
> +		increment_tailroom_need_count(sdata);
> +
> +	if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) {
> +		ret = drv_set_key(local, EXT_KEY_RX_TX, sdata,
> +				  &sta->sta, &key->conf);
> +		if (ret) {
> +			sdata_err(sdata,
> +				  "failed to activate key for Tx (%d, %pM)\n",
> +				  key->conf.keyidx, sta->sta.addr);
> +			return ret;

You've already cleared the RX_ONLY flag, which gets you inconsistent
data now.

> +		}
> +	}
> +
> +	old = key_mtx_dereference(local, sta->ptk[sta->ptk_idx]);
> +	sta->ptk_idx = key->conf.keyidx;

but you set this only here.

> -		/* Stop TX till we are on the new key */
> +		/* Stop Tx till we are on the new key */

Uh, I had to read that three times ... please don't make changes like
that? :)

>  		old_key->flags |= KEY_FLAG_TAINTED;
>  		ieee80211_clear_fast_xmit(sta);
>  
> -		/* Aggregation sessions during rekey are complicated due to the
> +		/* Aggregation sessions during rekey are complicated by the

similarly here, please don't make drive-by comment wording issues (also,
I'm not sure I agree - the old version just treats "complicated" as an
adjective, you treat it as a verb, but ultimately doesn't really matter?

>  #define NUM_DEFAULT_KEYS 4
>  #define NUM_DEFAULT_MGMT_KEYS 2
> +#define INVALID_PTK_KEYIDX 2 /* Existing key slot never used by PTK keys */

We could also use something obviously wrong like 0xff?

> +++ b/net/mac80211/tx.c
> @@ -3000,23 +3000,15 @@ void ieee80211_check_fast_xmit(struct sta_info *sta)
>  		switch (build.key->conf.cipher) {
>  		case WLAN_CIPHER_SUITE_CCMP:
>  		case WLAN_CIPHER_SUITE_CCMP_256:
> -			/* add fixed key ID */
> -			if (gen_iv) {
> -				(build.hdr + build.hdr_len)[3] =
> -					0x20 | (build.key->conf.keyidx << 6);
> +			if (gen_iv)
>  				build.pn_offs = build.hdr_len;
> -			}
>  			if (gen_iv || iv_spc)
>  				build.hdr_len += IEEE80211_CCMP_HDR_LEN;
>  			break;
>  		case WLAN_CIPHER_SUITE_GCMP:
>  		case WLAN_CIPHER_SUITE_GCMP_256:
> -			/* add fixed key ID */
> -			if (gen_iv) {
> -				(build.hdr + build.hdr_len)[3] =
> -					0x20 | (build.key->conf.keyidx << 6);
> +			if (gen_iv)
>  				build.pn_offs = build.hdr_len;
> -			}
>  			if (gen_iv || iv_spc)
>  				build.hdr_len += IEEE80211_GCMP_HDR_LEN;
>  			break;
> @@ -3383,6 +3375,7 @@ static void ieee80211_xmit_fast_finish(struct ieee80211_sub_if_data *sdata,
>  			pn = atomic64_inc_return(&key->conf.tx_pn);
>  			crypto_hdr[0] = pn;
>  			crypto_hdr[1] = pn >> 8;
> +			crypto_hdr[3] = 0x20 | (key->conf.keyidx << 6);
>  			crypto_hdr[4] = pn >> 16;
>  			crypto_hdr[5] = pn >> 24;
>  			crypto_hdr[6] = pn >> 32;

This shouldn't be needed, you do update the fast TX cache when changing
the key?

johannes


  reply	other threads:[~2019-02-15 11:06 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-10 21:06 [RFC PATCH v3 00/12] Draft for Extended Key ID support Alexander Wetzel
2019-02-10 21:06 ` [RFC PATCH v3 01/12] mac80211: Optimize tailroom_needed update checks Alexander Wetzel
2019-02-10 21:06 ` [RFC PATCH v3 02/12] nl80211/cfg80211: Extended Key ID support Alexander Wetzel
2019-02-15 10:52   ` Johannes Berg
2019-02-17 19:19     ` Alexander Wetzel
2019-02-22  8:30       ` Johannes Berg
2019-02-22 23:04         ` Alexander Wetzel
2019-02-10 21:06 ` [RFC PATCH v3 03/12] mac80211: IEEE 802.11 " Alexander Wetzel
2019-02-15 11:06   ` Johannes Berg [this message]
2019-02-19 20:58     ` Alexander Wetzel
2019-02-21 19:47       ` Alexander Wetzel
2019-02-22  8:41         ` Johannes Berg
2019-02-23 21:02           ` Alexander Wetzel
2019-03-01 20:43           ` Alexander Wetzel
2019-02-23 17:26         ` Alexander Wetzel
2019-02-10 21:06 ` [RFC PATCH v3 04/12] mac80211: Compatibility " Alexander Wetzel
2019-02-15 11:09   ` Johannes Berg
2019-02-21 20:07     ` Alexander Wetzel
2019-02-22  8:53       ` Johannes Berg
2019-02-23 22:50         ` Alexander Wetzel
2019-02-10 21:06 ` [RFC PATCH v3 05/12] mac80211: Mark A-MPDU keyid borders for drivers Alexander Wetzel
2019-02-15 11:50   ` Johannes Berg
2019-02-21 21:20     ` Alexander Wetzel
2019-02-22  8:51       ` Johannes Berg
2019-02-23 21:47         ` Alexander Wetzel
2019-02-10 21:06 ` [RFC PATCH v3 06/12] mac80211_hwsim: Ext Key ID support (NATIVE) Alexander Wetzel
2019-02-10 21:06 ` [RFC PATCH v3 07/12] iwlwifi: Extended " Alexander Wetzel
2019-02-15 11:52   ` Johannes Berg
2019-02-22 20:50     ` Alexander Wetzel
2019-02-22 21:06       ` Johannes Berg
2019-02-24 13:04         ` Alexander Wetzel
2019-04-08 20:10           ` Johannes Berg
2019-04-10 20:46             ` Alexander Wetzel
2019-04-12  9:51               ` Johannes Berg
2019-04-14 16:12                 ` Alexander Wetzel
2019-04-15  8:44                   ` Johannes Berg
2019-04-15 20:09                     ` Alexander Wetzel
2019-04-16  9:31                       ` Johannes Berg
2019-04-16 18:28                         ` Alexander Wetzel
2019-04-16 19:11                           ` Johannes Berg
2019-04-16 21:32                             ` Alexander Wetzel
2019-04-12 11:19               ` Johannes Berg
2019-02-10 21:06 ` [RFC PATCH v3 08/12] iwlwifi: dvm - EXT_KEY_ID A-MPDU API update Alexander Wetzel
2019-02-15 11:54   ` Johannes Berg
2019-02-22 21:15     ` Alexander Wetzel
2019-02-22 21:20       ` Johannes Berg
2019-02-10 21:06 ` [RFC PATCH v3 09/12] ath: Basic Extended Key ID support (COMPAT+NATIVE) Alexander Wetzel
2019-02-13 11:05   ` Kalle Valo
2019-02-13 23:15     ` Alexander Wetzel
2019-02-10 21:06 ` [RFC PATCH v3 10/12] ath5k: ath_key_config() API compatibility update Alexander Wetzel
2019-02-10 21:06 ` [RFC PATCH v3 11/12] ath9k: Extended Key ID support (COMPAT) Alexander Wetzel
2019-02-10 21:06 ` [RFC PATCH v3 12/12] ath9k: EXT_KEY_ID A-MPDU API update Alexander Wetzel
2019-02-15 11:10 ` [RFC PATCH v3 00/12] Draft for Extended Key ID support Johannes Berg
2019-02-21 20:44   ` Alexander Wetzel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f4d8db23bc3804fdc98f2ce7a702215bd82fd4e3.camel@sipsolutions.net \
    --to=johannes@sipsolutions.net \
    --cc=alexander@wetzel-home.de \
    --cc=linux-wireless@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).