Skip to contentSkip to conversation

netdev: fix asymmetry in handshake events

PATCH In review James Prestwood 2 participants 3 messages Jan 4, 2021 – Jan 5, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netdev: fix asymmetry in handshake events

A failed/timed out handshake can sometimes result in no HANDSHAKE_EVENT_FAILED event. This is because if IWD receives a deauth before the eapol timeout expires the handshake is cleaned up without any error being signaled. This ends up being ok because netdev has its own handshake failed event associated with the connect attempt which station/others handle appropriately.

The issue lies more with what a handshake event consumer would expect. Not receiving a failed event in the case of a failure is unexpected. Future changes will rely on symmetry of these events so it is being fixed now.

This case can be detected inside the netdev death event handler by checking if last_code was ever set. If last_code is zero, and netdev is not operational we have hit this situation and netdev needs to manually trigger HANDSHAKE_EVENT_FAILED.

---
 src/netdev.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
src/netdev.c +18 -0
index bf35b1ee..ebbcbbbc 100644
@@ -869,6 +869,24 @@ static void netdev_disconnect_event(struct l_genl_msg *msg,
 	l_info("Received Deauthentication event, reason: %hu, from_ap: %s",
 			reason_code, disconnect_by_ap ? "true" : "false");
 
+	/*
+	 * In some cases of a failed handshake the AP will send a deauth before
+	 * IWD's eapol timer expires. This causes asymmetry in the handshake
+	 * started/failed events because the eapol timer would get cleaned up by
+	 * netdev_connect_free below and no failed event would be sent. We can
+	 * detect this because last_code is only set via netdev_handshake_failed
+	 * which indicates the handshake failed event DID fire. If no failed
+	 * event fired, and netdev is not operational, something went wrong in
+	 * the handshake and this deauth event is the AP rejecting it. In this
+	 * case signal the failed event which will ultimately clean up the
+	 * connection via netdev_handshake_failed.
+	 */
+	if (!netdev->operational && !netdev->last_code) {
+		handshake_event(netdev->handshake, HANDSHAKE_EVENT_FAILED,
+				reason_code);
+		return;
+	}
+
 	event_filter = netdev->event_filter;
 	event_data = netdev->user_data;
 	netdev_connect_free(netdev);
Signature · 1 line
2.26.2
#1 lore raw

Hi James,

Quoted 26 lines · James Prestwood

A failed/timed out handshake can sometimes result in no HANDSHAKE_EVENT_FAILED event. This is because if IWD receives a deauth before the eapol timeout expires the handshake is cleaned up without any error being signaled. This ends up being ok because netdev has its own handshake failed event associated with the connect attempt which station/others handle appropriately.

The issue lies more with what a handshake event consumer would expect. Not receiving a failed event in the case of a failure is unexpected. Future changes will rely on symmetry of these events so it is being fixed now.

This case can be detected inside the netdev death event handler by checking if last_code was ever set. If last_code is zero, and netdev is not operational we have hit this situation and netdev needs to manually trigger HANDSHAKE_EVENT_FAILED.

---
  src/netdev.c | 18 ++++++++++++++++++
  1 file changed, 18 insertions(+)
src/netdev.c +0 -0
index bf35b1ee..ebbcbbbc 100644

src/netdev.c static void netdev_disconnect_event(struct l_genl_msg *msg, · line 876

Quoted 8 lines
src/netdev.c +5 -0
@@ -869,6 +869,24 @@ static void netdev_disconnect_event(struct l_genl_msg *msg,
  	l_info("Received Deauthentication event, reason: %hu, from_ap: %s",
  			reason_code, disconnect_by_ap ? "true" : "false");
 
+	/*
+	 * In some cases of a failed handshake the AP will send a deauth before
+	 * IWD's eapol timer expires. This causes asymmetry in the handshake
+	 * started/failed events because the eapol timer would get cleaned up by
+	 * netdev_connect_free below and no failed event would be sent. We can

Yes, this can happen. As you point out, we rely on station.c detecting this case and resolving it the same way as a failed handshake result.

src/netdev.c static void netdev_disconnect_event(struct l_genl_msg *msg, · line 882

Quoted 6 lines
src/netdev.c +6 -0
+	 * detect this because last_code is only set via netdev_handshake_failed
+	 * which indicates the handshake failed event DID fire. If no failed
+	 * event fired, and netdev is not operational, something went wrong in
+	 * the handshake and this deauth event is the AP rejecting it. In this
+	 * case signal the failed event which will ultimately clean up the
+	 * connection via netdev_handshake_failed.

Well sort of. We do not really know why the AP disconnected us (unless we look at the reason code, and that is never reliable). So, in some respect, this isn't really a handshake failure. Abort maybe?

src/netdev.c static void netdev_disconnect_event(struct l_genl_msg *msg, · line 886

Quoted 4 lines
src/netdev.c +4 -0
+	 */
+	if (!netdev->operational && !netdev->last_code) {
+		handshake_event(netdev->handshake, HANDSHAKE_EVENT_FAILED,
+				reason_code);

Wouldn't this cause us to issue another Disconnect? Sort of useless to do that if we know we're disconnected already. The kernel just told us.

Perhaps this should be treated as another handshake event. Like HANDSHAKE_EVENT_ABORTED.

src/netdev.c static void netdev_disconnect_event(struct l_genl_msg *msg, · line 892

Quoted 7 lines
src/netdev.c +3 -0
+		return;
+	}
+
  	event_filter = netdev->event_filter;
  	event_data = netdev->user_data;
  	netdev_connect_free(netdev);

Regards,
-Denis

#2 lore raw

Hi,

Quoted 4 lines

Wouldn't this cause us to issue another Disconnect? Sort of useless to do that
if we know we're disconnected already. The kernel just told us.

Yes, your right.

Quoted 2 lines

Perhaps this should be treated as another handshake event. Like HANDSHAKE_EVENT_ABORTED.

Well basically I wanted this symmetry for the diagnostic interface, for purposes of timing auth/assoc/handshake etc. as well as obtaining the status/reason code. This was a quick hack but there were unforseen consequences.

I was planning on this eventually but instead maybe I could just make the netdev result events subscribeable with a watchlist. This would get me the auth/assoc timings, status/reason code, as well as handle this case as station already does without the need for a special purpose event.

Thanks,
James