All of lore.kernel.org
 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, 22 Feb 2019 09:41:56 +0100	[thread overview]
Message-ID: <767ada740d984e180d0ac799487722293a50367c.camel@sipsolutions.net> (raw)
In-Reply-To: <171d2db4-7639-4738-2a6d-c899f0247aee@wetzel-home.de>

On Thu, 2019-02-21 at 20:47 +0100, Alexander Wetzel wrote:
> > > > 
> > > >   - Enforce cipher does not change when replacing a key.
> > > 
> > > is that actually required somehow?
> > 
> > The code is silently assuming a rekey is using the same cipher. Someone 
> > e.g. switching from WEP to CCMP with a rekey would pass all sanity 
> > checks and allow to use the code in a way never intended or tested.
> > With the current handling the userspace e.g. should be able to install a 
> > WEB key using keyid 3 and then rekey it with a CCMP key, claiming keyid 
> > 0 bit mac80211 will copy the keyid from the old and use keyid 3. 
> > Something not possible otherwise.
> > 
> > That said I do not see how this could be exploited, I simply try to 
> > enforce all assumptions to be on the safe side. (I did not dig deeper 
> > into potential exploits after finding out how keyids are used during 
> > rekey.)

Ok. That's fair, but it'd be good to add that reasoning to the commit
log or even a comment where the validation happens.


> > Second, I spend quite some time finding good names for the calls and one 
> > of the last tweaks to this patch was replacing SET_KEY_RX_ONLY to 
> > EXT_SET_KEY...

:)

> > So here the reasoning for why I named them as they are and why I  prefer 
> > the names used in the patch.
> > First, many drivers will handle SET_KEY and SET_KEY_RX_ONLY with the 
> > same code and not differentiate between those at all. Using EXT_as a 
> > prefix for the "normal" command is therefore a nice way to imply the 
> > command can only be used with Extended Key ID and still link it to the 
> > original command.
> > But more important for me was the clash between what the command spells 
> > and what it does in the COMPAT mode: SET_KEY_RX_ONLY would then be used 
> > to install a TX only key which never can be used by the card for Rx.
> > So I decided to rename it to EXT_SET_KEY, just indicating that this 
> > command adds a new key to the card for Extended Key ID and drop the 
> > confusing reference to Rx.

Wait, what? In compat mode SET_KEY_RX_ONLY installs a TX-only key? Ah,
you mean before you changed this.

Why don't we split out compat mode then?

But I see where you're coming from with the EXT_ now. I need to think of
it less as an "extension" now, but as "extended key ID". I'm not really
entirely sure that makes sense - even what we think of as "extended key
ID" now might be the new normal soon? But then again the spec does the
same thing.

> > Long story short: Using SET_KEY_RXONLY and SET_KEY_TX is not wrong, but 
> > I would rate them more confusing.

Fair enough.

> > > > +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?

> Exactly. With COMPAT we would have to check for EXT_KEY_ID_NATIVE and 
> EXT_KEY_ID_COMPAT. Since we have already done that and set 
> NL80211_EXT_FEATURE_EXT_KEY_ID I check that here.
> Assuming we merge NATIVE and drop COMPAT it may make sense to keep the 
> check here and drop EXT_KEY_ID_NATIVE altogether.
> The drivers than can set NL80211_EXT_FEATURE_EXT_KEY_ID directly.

Yes, I think I get it. I don't think we need to drop compat, it seems
somewhat useful for some drivers - I think I mostly just got confused
here because compat support only comes later, and I wasn't really
thinking about it yet in the context of this patch.

> > I have to look at that again. It will change some assumptions for sure 
> > but still could work out with some slight differences. I'll have to look 
> > deeper into that since I remember two moments where I was sure needing 
> > the flag. That may well be outdated, but at a first glance it would at 
> > least open the door to first install two key in legacy mode and then 
> > switch between them. (Which should be no problem, of course)
> > I'll follow up on that separately, but that may take some time. When it 
> > works you'll get a new RFC.

No worries :-)
I don't really mind the flag, but much of the use I've seen now here
seemed equivalent, and then it doesn't seem necessary.

> > > > +    key->flags &= ~KEY_FLAG_RX_ONLY;
[snip]
> > > > +    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.
> > > 
> > 
> > I don't think so, it looks ok for me. But the delay_tailroom logic took 
> > a surprisingly large chunk of time and I should explain how the updated 
> > logic is intended to work. Maybe I've messed it up somehow and just do 
> > not see it:

My comment wasn't related to tailroom accounting at all. I've snipped
more code above to hopefully make it clearer.

If you fail to activate the key in the driver, then the key is not
actually enabled for TX, and thus you should not have cleared the
KEY_FLAG_RX_ONLY? You'll be returning this error all the way to
userspace, I assume.

(Maybe, btw, the driver should be allowed to return something like
"oops, I now want to use TX software crypto" like it can do for other
operations?)

> > > >   #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?
> > 
> > No, not without some undesired modifications. We actually fetch the 
> > referenced key and the key slot must exist and be NULL. We (mostly) 
> > discussed that in the previous RFC, I just decided to use a define 
> > instead the numeric value. (Mostly due the fact that A-MPDU also needs 
> > an "invalid" ID and using the same looks like a good idea.

Hm, yeah, I vaguely remember. OK.

> > That's only right for the push path but can send out wrong packets when 
> > the driver is using the pull path:
> > 
> > 1) ieee80211_xmit_fast() will use fast_tx structure to fill in the 
> > "cached" keyid and queue the packet. (let's say 0)
> > 
> > 2) ieee80211_check_fast_xmit is called due to a rekey (and keyid change 
> > from 0 -> 1)
> > 
> > 3) ieee80211_tx_dequeue() will then dequeue the prepared skb from 1), 
> > refresh the key information but keep keyid 0 in the skb and instruct the 
> > driver to encrypt it for keyid 1 -> WRONG
> > 
> > 4) The remote sta tries to decrypt the packet using the key 0, as 
> > referenced by the keyid. Which will of course not work.
> > 
> > With Extended Key ID (and some debugging) I added a simple rule: When 
> > you assign the pn you also set the matching keyid.

OK.

johannes


  reply	other threads:[~2019-02-22  8:42 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
2019-02-19 20:58     ` Alexander Wetzel
2019-02-21 19:47       ` Alexander Wetzel
2019-02-22  8:41         ` Johannes Berg [this message]
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=767ada740d984e180d0ac799487722293a50367c.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.