From da13aab4190dd0c8fd0bca0d49170bc3bd6fa43a Mon Sep 17 00:00:00 2001 From: Ed Smith Date: Thu, 28 Mar 2024 16:39:31 -0600 Subject: [PATCH] Register EAPOL frame listeners earlier If we register the main EAPOL frame listener as late as the associate event, it may not observe ptk_1_of_4. This defeats handling for early messages in eapol_rx_packet, which only sees messages once it has been registered. If we move registration to the authenticate event, then the EAPOL frame listeners should observe all messages, without any possible races. Note that the messages are not actually processed until eapol_start() is called, and we haven't moved that call site. All that's changing here is how early EAPOL messages can be observed. --- src/netdev.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/netdev.c b/src/netdev.c index 26e36081..af069724 100644 --- a/src/netdev.c +++ b/src/netdev.c @@ -2896,6 +2896,15 @@ static bool kernel_will_retry_auth(uint16_t status_code, return false; } +static void netdev_ensure_eapol_registered(struct netdev *netdev) +{ + if (L_WARN_ON(netdev->sm)) + return; + + netdev->sm = eapol_sm_new(netdev->handshake); + eapol_register(netdev->sm); +} + static void netdev_authenticate_event(struct l_genl_msg *msg, struct netdev *netdev) { @@ -2982,7 +2991,12 @@ static void netdev_authenticate_event(struct l_genl_msg *msg, NULL, netdev->user_data); /* We have sent another CMD_AUTHENTICATE / CMD_ASSOCIATE */ - if (ret == 0 || ret == -EAGAIN) + if (ret == 0) { + netdev_ensure_eapol_registered(netdev); + return; + } + + if (ret == -EAGAIN) return; retry = kernel_will_retry_auth(status_code, @@ -3099,9 +3113,6 @@ static void netdev_associate_event(struct l_genl_msg *msg, netdev->ap = NULL; } - netdev->sm = eapol_sm_new(netdev->handshake); - eapol_register(netdev->sm); - /* Just in case this was a retry */ netdev->ignore_connect_event = false; @@ -4292,6 +4303,8 @@ int netdev_ft_reassociate(struct netdev *netdev, if (netdev->sm) { eapol_sm_free(netdev->sm); netdev->sm = NULL; + + netdev_ensure_eapol_registered(netdev); } msg = netdev_build_cmd_associate_common(netdev);