linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jouni Malinen <j@w1.fi>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Adrian Chadd <adrian@freebsd.org>,
	"Luis R. Rodriguez" <mcgrof@do-not-panic.com>,
	Kalle Valo <kvalo@codeaurora.org>,
	QCA ath9k Development <ath9k-devel@qca.qualcomm.com>,
	"ath9k-devel@lists.ath9k.org" <ath9k-devel@lists.ath9k.org>,
	Linux Wireless List <linux-wireless@vger.kernel.org>
Subject: Re: AR9462 problems connecting again..
Date: Mon, 23 Feb 2015 19:17:00 +0200	[thread overview]
Message-ID: <20150223171700.GA29730@w1.fi> (raw)
In-Reply-To: <CA+55aFwc6Uz7HOQ6S6SzSkWY39QBYWnURFjvQXC6QWNmoFB4=Q@mail.gmail.com>

On Sun, Feb 22, 2015 at 05:41:25PM -0800, Linus Torvalds wrote:
> Nope, everything else I have seems to be intel wireless. I think one
> of the kids machines is a Mac Mini with an ath5k thing, but I'm hoping
> the wpa_supplicant.log is sufficient to give somebody an idea.

It looks like there are two issues here: 1) EAPOL-Key message 4/4 (i.e.,
the second Data frame sent by the station during association) is somehow
not seen or accepted by the AP, 2) recovery from that msg 4/4 getting
lost does not work in the intended way.

For (1), one would likely need to see a wireless capture from a separate
WLAN radio to say something certain about what exactly happened.
ath5k-compatible radios would not be sufficient since this would need to
be able to see HT frames which ath9k is mostly like using here. I
haven't used iwlwifi as a sniffer, so I do not know whether that would
be a workable option for this.

In my tests, I can see the rate control algorithm (minstrel_ht) using a
pretty high rate (even MCS14 with 2-stream device, which is one short of
maximum) which is quite a bit higher than I would myself have selected
for an EAPOL frame (especially for EAPOL-Key 4/4 which has these lovely
issues with retransmissions) more or less immediately after association.
Anyway, that frame is supposed to get additional fall-back TX rates for
link layer retransmissions and those should make it much more likely for
this to be received by the AP. Sniffer trace would confirm that.


For (2), wpa_supplicant debug log gives a pretty clear idea on what is
happening and based on that, I can easily reproduce this part. In fact,
I now have a fully automated test script for verifying this with
mac80211_hwsim.

Some alternative means of improving this was discussed in this thread.
I'm not completely happy with this, but the following mac80211 changes
do fix this retransmission case and will likely make the issue you are
seeing disappear since it allows any of the four EAPOL-Key msg 4/4
transmissions to be received by the AP to avoid the disconnection. This
doesn't fix the initial trigger behind the issue, but with those EAPOL
retransmissions working, the likelihood of all four attempts failing
(with each getting multiple link-layer retransmissions) is quite small.


mac80211: Do not encrypt EAPOL frames before peer has used the key

The 4-way handshake design is a bit inconvenient for the case where msg
3/4 needs to be transmitted (e.g., AP not receiving first transmission
of 4/4). The supplicant side has already configured the pairwise key at
that point in time and while we allow unencrypted msg 3/4 to be
received, we were sending out 4/4 encrypted which will result in it
getting dropped. User space would be aware of when the EAPOL frame
should not be encrypted, but we do not have convenient means of telling
mac80211 that. For now, use a mac80211-specific hack to avoid EAPOL
frame encryption to allow retransmission of 4-way handshake messages 3/4
and 4/4 to work in a way that the authenticator side can process 4/4.

---
 net/mac80211/key.h |  2 ++
 net/mac80211/rx.c  | 11 +++++++++++
 net/mac80211/tx.c  | 13 +++++++++++++
 3 files changed, 26 insertions(+)

diff --git a/net/mac80211/key.h b/net/mac80211/key.h
index d57a9915..3e23276 100644
--- a/net/mac80211/key.h
+++ b/net/mac80211/key.h
@@ -120,6 +120,8 @@ struct ieee80211_key {
 
 	/* number of times this key has been used */
 	int tx_rx_count;
+	/* whether a valid RX decryption has happened with this key */
+	bool valid_rx_seen;
 
 #ifdef CONFIG_MAC80211_DEBUGFS
 	struct {
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index 1101563..8f3f86c 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -1691,6 +1691,16 @@ ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
 	return result;
 }
 
+static ieee80211_rx_result debug_noinline
+ieee80211_rx_h_check_key_use(struct ieee80211_rx_data *rx)
+{
+	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
+
+	if ((status->flag & RX_FLAG_DECRYPTED) && rx->key)
+		rx->key->valid_rx_seen = true;
+	return RX_CONTINUE;
+}
+
 static inline struct ieee80211_fragment_entry *
 ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
 			 unsigned int frag, unsigned int seq, int rx_queue,
@@ -3139,6 +3149,7 @@ static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx,
 		CALL_RXH(ieee80211_rx_h_uapsd_and_pspoll)
 		CALL_RXH(ieee80211_rx_h_sta_process)
 		CALL_RXH(ieee80211_rx_h_decrypt)
+		CALL_RXH(ieee80211_rx_h_check_key_use)
 		CALL_RXH(ieee80211_rx_h_defragment)
 		CALL_RXH(ieee80211_rx_h_michael_mic_verify)
 		/* must be after MMIC verify so header is counted in MPDU mic */
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index 88a18ff..c314c59 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -612,6 +612,19 @@ ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx)
 		return TX_DROP;
 	}
 
+	if (tx->key &&
+	    unlikely(info->control.flags & IEEE80211_TX_CTRL_PORT_CTRL_PROTO) &&
+	    !tx->key->valid_rx_seen) {
+		/* Do not encrypt EAPOL frames before peer has used the key */
+		/* FIX: This is not really complete.. It would be at least
+		 * theoretically possible for the peer to never send a Data
+		 * frame and if we were to initiate reauthentication or
+		 * rekeying, we might need to encrypt the initiating EAPOL
+		 * frame.
+		 */
+		tx->key = NULL;
+	}
+
 	if (tx->key) {
 		bool skip_hw = false;
 
-- 
Jouni Malinen                                            PGP id EFC895FA

  parent reply	other threads:[~2015-02-23 17:17 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-21 23:34 AR9462 problems connecting again Linus Torvalds
2015-02-22  6:50 ` Sujith Manoharan
2015-02-22 17:55   ` Linus Torvalds
2015-02-22 18:24 ` Adrian Chadd
2015-02-22 18:30   ` Linus Torvalds
2015-02-22 18:58     ` [ath9k-devel] " Dave Taht
2015-02-22 21:45       ` Linus Torvalds
     [not found]         ` <CAM9PttgYK3e75c2XZ6G2nPXw=UR95-xVwO0LBqrXRPFcABkgTA@mail.gmail.com>
2015-02-22 21:56           ` Kyle Bassett
2015-02-22 19:39     ` Adrian Chadd
2015-02-22 21:50       ` Linus Torvalds
2015-02-22 23:00         ` Linus Torvalds
2015-02-23  0:54           ` Adrian Chadd
2015-02-23  1:41             ` Linus Torvalds
2015-02-23  1:55               ` Adrian Chadd
2015-02-23  1:59                 ` Linus Torvalds
2015-02-23  2:05                 ` Adrian Chadd
2015-02-23  5:46               ` [ath9k-devel] " Sujith Manoharan
2015-02-23  6:01                 ` Sujith Manoharan
2015-02-23 10:37               ` Jouni Malinen
2015-02-23 10:55                 ` wim torfs
2015-02-23 11:05                   ` Jouni Malinen
2015-02-23 17:17               ` Jouni Malinen [this message]
2015-02-23 18:00                 ` Emmanuel Grumbach
2015-02-23 20:06                 ` Linus Torvalds
2015-02-23 20:11                   ` Linus Torvalds
2015-02-23 21:30                   ` Jouni Malinen
2015-02-23 21:53                     ` Linus Torvalds
2015-02-23 22:22                       ` Adrian Chadd
2015-02-23 22:43                         ` Jouni Malinen
2015-02-23 23:00                           ` Linus Torvalds
2015-02-23 23:13                             ` Jouni Malinen
2015-02-24  0:29                           ` Sujith Manoharan
     [not found]                             ` <CAA_e5Z4zuDMS+CJvFbw4F5M9OZxgS-NZzL2E3d3GSvpRr_TbQw@mail.gmail.com>
2015-02-24  2:29                               ` Andrew McGregor
2015-02-24 10:26                                 ` Jouni Malinen
2015-02-24 16:58                                   ` [ath9k-devel] " Dave Taht
2015-02-24 17:54                                   ` Thomas Hühn
2015-02-24 18:14                                     ` Jouni Malinen
2015-02-24 22:38                                       ` Thomas Hühn
2015-02-24 22:50                                         ` Adrian Chadd
2015-02-25 14:53                                         ` Jouni Malinen
2015-02-25 20:52                                           ` Thomas Hühn
2015-02-25  5:00                                       ` Felix Fietkau
2015-02-25 14:47                                         ` Jouni Malinen
2015-02-25 18:14                                           ` Linus Torvalds
2015-02-25 18:25                                             ` Peter Stuge
2015-02-25 20:22                                             ` Adrian Chadd
2015-02-26  5:02                                               ` Andrew McGregor
2015-02-26  5:55                                             ` Linus Torvalds
2015-02-26 10:01                                               ` Arend van Spriel
2015-02-26 10:20                                             ` Jouni Malinen
2015-02-26 16:04                                               ` Peter Stuge
2015-02-26 19:03                                               ` Adrian Chadd
2015-02-23  1:24           ` Sujith Manoharan

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=20150223171700.GA29730@w1.fi \
    --to=j@w1.fi \
    --cc=adrian@freebsd.org \
    --cc=ath9k-devel@lists.ath9k.org \
    --cc=ath9k-devel@qca.qualcomm.com \
    --cc=kvalo@codeaurora.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=mcgrof@do-not-panic.com \
    --cc=torvalds@linux-foundation.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).