Commit Graph

4131 Commits

Author SHA1 Message Date
Ed Smith da13aab419 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.
2024-03-28 17:41:07 -05:00
James Prestwood ccd702f7da netdev: use CMD_DEAUTHENTICATE when needed on disconnect
netdev_disconnect() was unconditionally sending CMD_DISCONNECT which
is not the right behavior when IWD has not associated. This means
that if a connection was started then immediately canceled with
the Disconnect() method the kernel would continue to authenticate.

Instead if IWD has not yet associated it should send a deauth
command which causes the kernel to correctly cleanup its state and
stop trying to authenticate.

Below are logs showing the behavior. Autoconnect is started followed
immediately by a DBus Disconnect call, yet the kernel continues
sending authenticate events.

event: state, old: autoconnect_quick, new: connecting (auto)
src/scan.c:scan_cancel() Trying to cancel scan id 1 for wdev 7d
src/wiphy.c:wiphy_radio_work_done() Work item 1 done
src/wiphy.c:wiphy_radio_work_next() Starting work item 2
src/netdev.c:netdev_mlme_notify() MLME notification New Station(19)
src/station.c:station_dbus_disconnect()
src/station.c:station_reset_connection_state() 85
src/station.c:station_roam_state_clear() 85
event: state, old: connecting (auto), new: disconnecting
src/wiphy.c:wiphy_radio_work_done() Work item 2 done
src/station.c:station_connect_cb() 85, result: 5
src/station.c:station_disconnect_cb() 85, success: 1
event: state, old: disconnecting, new: disconnected
src/netdev.c:netdev_mlme_notify() MLME notification Authenticate(37)
src/netdev.c:netdev_authenticate_event()
Unexpected connection related event -- is another supplicant running?
src/netdev.c:netdev_mlme_notify() MLME notification Authenticate(37)
src/netdev.c:netdev_authenticate_event()
Unexpected connection related event -- is another supplicant running?
src/netdev.c:netdev_mlme_notify() MLME notification Authenticate(37)
src/netdev.c:netdev_authenticate_event()
Unexpected connection related event -- is another supplicant running?
src/netdev.c:netdev_mlme_notify() MLME notification Del Station(20)
src/netdev.c:netdev_mlme_notify() MLME notification Authenticate(37)
src/netdev.c:netdev_authenticate_event()
Unexpected connection related event -- is another supplicant running?
2024-03-28 17:16:37 -05:00
James Prestwood 6365c1f6de wiphy: add better handling for rate estimation errors
In most cases any failure here is likely just due to the AP not
supporting the feature, whether its HE/VHT/HE. This should result
in the estimation returning -ENOTSUP in which case we move down
the list. Any other non-zero return we will now warn to make it
clear the IEs did exist, but were not properly formatted.

All length check failures were changed to continue instead of
fail. This will now treat invalid lengths as if the IE did not
exist.

In addition HE specifically has an extra validation function which,
if failed, was bailing out of the estimation function entirely.
Instead this is now treated as if there was no HE capabilities and
the logic can move down to VHT, HT, or basic rates.
2024-03-28 10:21:08 -05:00
James Prestwood 2f2b5740da band: make HE/no-HT rate estimators return more descriptive
If the IEs were not provided return -ENOTSUP rather than -EINVAL
or -EBADMSG since this just means the AP doesn't support those
capabilities.
2024-03-28 10:20:53 -05:00
James Prestwood eb3345b51b eap-mschapv2: Check Password-Hash exists when loading settings
Caught by static analysis, the Password-Hash was never validated so
it could end up memcpying from a NULL pointer.
2024-03-11 22:08:02 -05:00
James Prestwood 795f57e816 p2p: check connected peer before processing request
Caught by static analysis, the dev->conn_peer pointer was being
dereferenced very early on without a NULL check, but further it
was being NULL checked. If there is a possibility of it being NULL
the check should be done much earlier.
2024-03-11 22:07:37 -05:00
James Prestwood 71a7190ed2 eap-mschapv2: remove unneeded initialization 2024-03-04 13:48:08 -06:00
James Prestwood 405b897687 dpp: check wrapped data exists in authenticate response 2024-03-04 13:48:08 -06:00
James Prestwood 62e2a3535d files: remove unneeded initialization 2024-03-04 13:48:08 -06:00
James Prestwood d9aaf6c842 ie: remove unneeded initialization 2024-03-04 13:48:08 -06:00
James Prestwood c2ad0006eb ap: bail in ap_del_station if AP is going down
Caught by static analysis, if this condition is met the AP is going
down so we cannot continue further accessing the ap object.
2024-02-29 14:37:49 -06:00
James Prestwood 5fcfb430b2 ap: verify ATTR_MAC exists in NEW_STATION
Caught by static analysis, if ATTR_MAC was not in the message there
would be a memcpy with uninitialized bytes. In addition there is no
reason to memcpy twice. Instead 'mac' can be a const pointer which
both verifies it exists and removes the need for a second memcpy.
2024-02-29 14:37:42 -06:00
James Prestwood 3a17c8e3c5 nl80211util: check l_genl_attr_recurse return in extract_nested
Caught by static analysis, the recurse operation return was not being
checked.
2024-02-29 14:37:29 -06:00
James Prestwood 6febe5bed1 ap: allow va_end to get called in ap_handshake_event
Caught by static analysis, va_end was never being called since the
REKEY_COMPLETE event was returning early.
2024-02-29 14:37:19 -06:00
James Prestwood 338577bb3a ap: check that the last band_freq_attrs was set
Static analysis complains that 'last' could be NULL which is true.
This really could only happen if every frequency was disabled which
likely is impossible but in any case, check before dereferencing
the pointer.
2024-02-29 14:37:01 -06:00
James Prestwood 83c032a583 p2putil: check length of client info description
A length check was missing which could cause a out of bounds read.

Co-authored-by: Alex Radocea <alex@supernetworks.org>
2024-02-29 14:36:16 -06:00
James Prestwood d34b4e16e0 p2putil: initialize all parsing structures to zero
Since these are all stack variables they are not zero initialized.
If parsing fails there may be invalid pointers within the structures
which can get dereferenced by p2p_clear_*
2024-02-29 14:33:23 -06:00
James Prestwood 52a47c9fd4 p2putil: fix crash/remove side effect parsing adv service info
The input queue pointer was being initialized unconditionally so if
parsing fails the out pointer is still set after the queue is
destroyed. This causes a crash during cleanup.

Instead use a temporary pointer while parsing and only after parsing
has finished do we set the out pointer.

Reported-By: Alex Radocea <alex@supernetworks.org>
2024-02-29 14:32:53 -06:00
Denis Kenzior aef394895d netconfig: Fix copy-paste error
netconfig_domains_update() was setting dns_list instead of the domains
member.
2024-02-28 11:51:33 -06:00
Denis Kenzior 52c6a6b8ea eap-wsc: Zero authenticator bytes to fix static analysis warning
static analysis complains that authenticator is used uninitialized.
This isn't strictly true as memory region is reserved for the
authenticator using the contents of the passed in structure.  This
region is then overwritten once the authenticator is actually computed
by authenticator_put().  Silence this warning by explicitly setting
authenticator bytes to 0.

Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>
2024-02-28 09:13:30 -06:00
James Prestwood 42273fd122 station: warn on missing scan_bss in station_transition_start
This shouldn't be possible in theory since the roam_bss_list being
iterated is a subset of entire scan_bss list station/network has
but to be safe, and catch any issues due to future changes warn on
this condition.
2024-02-27 16:04:11 -06:00
James Prestwood 14aa333a39 crypto: fix uninitialized variable coverity warning
Same as for aes_siv_decrypt, check num_ads before calling memcpy.
2024-02-27 16:04:11 -06:00
James Prestwood ee52968043 crypto: fix uninitialized variable coverity warning
For some encrypt operations DPP passes no AD iovecs (both are
NULL/0). But since the iovec itself is on the stack 'ad' is a
valid pointer from within aes_siv_encrypt. This causes memcpy
to be called which coverity complains about. Since the copy
length is zero it was effectively a no-op, but check num_ad to
prevent the call.
2024-02-27 14:33:33 -06:00
James Prestwood fba4ee90d0 netdev: add NETDEV_EVENT_ECC_GROUP_RETRY, handle in station
In order to complete the learned default group behavior station needs
to be aware of when an SAE/OWE connection retried. This is all
handled within netdev/sae so add a new netdev event so station can
set the appropriate network flags to prevent trying the non-default
group again.
2024-02-27 13:55:37 -06:00
James Prestwood a559bd7c40 sae: remove sae_sm_set_force_group_19, use handshake
Use the flag set into the handshake to force the default ECC group
2024-02-27 13:55:37 -06:00
James Prestwood 988f68e916 network: set use default ECC group in handshake setup
If either the settings specify it, or the scan_bss is flagged, set
the use_default_ecc_group flag in the handshake.

This also renames the flag to cover both OWE and SAE
2024-02-27 13:55:37 -06:00
James Prestwood b38f71f221 network: retain default ECC group for OWE after setting
There is special handling for buggy OWE APs which set a network flag
to use the default OWE group. Utilize the more persistent setting
within known-networks as well as the network object (in case there
is no profile).

This also renames the get/set APIs to be generic to ECC groups rather
than only OWE.
2024-02-27 13:55:37 -06:00
James Prestwood 3f04bc427d knownnetworks: add option to force a default ECC group
This adds the option [Settings].UseDefaultEccGroup which allows a
network profile to specify the behavior when using an ECC-based
protocol. If unset (default) IWD will learn the behavior of the
network for the lifetime of its process.

Many APs do not support group 20 which IWD tries first by default.
This leads to an initial failure followed by a retry using group 19.
This option will allow the user to configure IWD to use group 19
first or learn the network capabilities, if the authentication fails
with group 20 IWD will always use group 19 for the process lifetime.
2024-02-27 13:55:37 -06:00
James Prestwood 3ab09e0ae2 doc: Document UseDefaultEccGroup 2024-02-27 13:55:37 -06:00
Ram Subramanian 793228028d station: add channel number to diagnostics message
As a small convenience to the user.
2024-02-26 09:44:12 -06:00
James Prestwood d4c68d7d83 netdev: add notice events for connection timeouts
The information specific to auth/assoc/connect timeouts isn't
communicated to station so emit the notice events within netdev.
We could communicate this to station by adding separate netdev
events, but this does not seem worth it for this use case as
these notice events aren't strictly limited to station.
2024-02-22 10:15:07 -06:00
James Prestwood 77cdbd186b station: use iwd_notice for state/event information
For anyone debugging or trying to identify network infrastructure
problems the IWD DBus API isn't all that useful and ultimately
requires going through debug logs to figure out exactly what
happened. Having a concise set of debug logs containing only
relavent information would be very useful. In addition, having
some kind of syntax for these logs to be parsed by tooling could
automate these tasks.

This is being done, starting with station, by using iwd_notice
which internally uses l_notice. The use of the notice log level
(5) in IWD will be strictly for the type of messages described
above.
2024-02-22 10:15:04 -06:00
James Prestwood d8a6fb86c1 iwd: add iwd_notice for special event/state type of logging
iwd_notice is being added so modules can communicate internal
state or event information via the NOTICE log level. This log
level will be reserved in IWD for only these type of messages.

The iwd_notice macro aims to help enforce some formatting
requirements for these type of log messages. The messages
should be one or more comma-separated "key: value" pairs starting
with "event: <name>" and followed by any additional info that
pertains to that event.

iwd_notice only enforces the initial event key/value format and
additional arguments are left to the caller to be formatted
correctly.
2024-02-22 10:14:59 -06:00
James Prestwood 32f3745745 main: add runtime flag for setting the logger
The --logger,-l flag can now be used to specify the logger type.
Unset (default) will set log output to stderr as it is today. The
other valid options are "syslog" and "journal".
2024-02-22 10:14:41 -06:00
Denis Kenzior ba5a6df2d1 wiphy: Remove basename() use
basename use is considered harmful.  There are two versions of
basename (see man 3 basename for details).  The more intuitive version,
which is currently being used inside wiphy.c, is not supported by musl
libc implementation.  Use of the libgen version is not preferred, so
drop use of basename entirely.  Since wiphy.c is the only call site of
basename() inside iwd, open code the required logic.
2024-02-14 14:50:06 -06:00
James Prestwood 6315b42861 netdev: use reason code from netdev_deauthenticate_event
The reason code was not being passed to netdev_connect_failed as
it should have been.
2024-02-13 17:00:39 -06:00
James Prestwood aa0a439856 netconfig: limit DHCPv4 attempts to avoid extended netconfig times
ELL now has a setting to limit the number of DHCP attempts. This
will now be set in IWD and if reached will result in a failure
event, and in turn a disconnect.

IWD will set a maximum of 4 retries which should keep the maximum
DHCP time to ~60 seconds roughly.
2024-01-30 13:59:22 -06:00
James Prestwood 1fe68aef0b station: reverse roam scan results for sorted known frequencies
The known frequency list is now a sorted list and the roam scan
results were not complying with this new requirement. The fix is
easy though since the iteration order of the scan results does
not matter (the roam candidates are inserted by rank). To fix
the known frequencies order we can simply reverse the scan results
list before iterating it.
2024-01-30 13:58:45 -06:00
James Prestwood 643503eeea netdev: make unprotected disconnect debug log more clear
The debug log was just saying "disconnect event" but we should
distinguish between unprotected and protected events.
2024-01-30 13:58:45 -06:00
James Prestwood 085a2511f6 netdev: fix setting a uint8_t with l_get_le16 2024-01-30 13:58:45 -06:00
Mathy Vanhoef 6415420f1c ap: only accept ptk 4/4 after receiving ptk 2/4
When operating as an AP, drop message 4 of the 4-way handshake if the AP
has not yet received message 2. Otherwise an attacker can skip message 2
and immediately send message 4 to bypass authentication (the AP would be
using an all-zero ptk to verify the authenticity of message 4).
2024-01-29 21:00:00 -06:00
James Prestwood f52180d41c station: knownnetworks: limit quick scans to 5 freqs per network
In very large network deployments there could be a vast amount of APs
which could create a large known frequency list after some time once
all the APs are seen in scan results. This then increases the quick
scan time significantly, in the very worst case (but unlikely) just
as long as a full scan.

To help with this support in knownnetworks was added to limit the
number of frequencies per network. Station will now only get 5
recent frequencies per network making the maximum frequencies 25
in the worst case (~2.5s scan).

The magic values are now defines, and the recent roam frequencies
was also changed to use this define as well.
2024-01-29 20:43:33 -06:00
James Prestwood 197087d081 station: use network_update_known_frequencies
Updates each network with its new, most current, set of BSS's
for the different types of scans: dbus/autoconnect, hidden, and
OWE.
2024-01-29 20:43:21 -06:00
James Prestwood d03b06db85 network: add network_update_known_frequencies
In order to support an ordered list of known frequencies the list
should be in order of last seen BSS frequencies with the highest
ranked ones first. To accomplish this without adding a lot of
complexity the frequencies can be pushed into the list as long as
they are pushed in reverse rank order (lowest rank first, highest
last). This ensures that very high ranked BSS's will always get
superseded by subsequent scans if not seen.

This adds a new network API to update the known frequency list
based on the current newtork->bss_list. This assumes that station
always wipes the BSS list on scans and populates with only fresh
BSS entries. After the scan this API can be called and it will
reverse the list, then add each frequency.
2024-01-29 20:43:02 -06:00
Fiona Klute a6638513d4 Log falling back from SAE to WPA2
I've had connections to a WPA3-Personal only network fail with no log
message from iwd, and eventually figured out to was because the driver
would've required using CMD_EXTERNAL_AUTH. With the added log messages
the reason becomes obvious.

Additionally the fallback may happen even if the user explicitly
configured WPA3 in NetworkManager, I believe a warning is appropriate
there.
2024-01-09 21:32:28 -06:00
James Prestwood 7080a4453e station: add handling for new NETCONFIG state
There was an unhandled corner case if netconfig was running and
multiple roam conditions happened in sequence, all before netconfig
had completed. A single roam before netconfig was already handled
(23f0f5717c) but this did not take into account any additional roam
conditions.

If IWD is in this state, having started netconfig, then roamed, and
again restarted netconfig it is still in a roaming state which will
prevent any further roams. IWD will remain "stuck" on the current
BSS until netconfig completes or gets disconnected.

In addition the general state logic is wrong here. If IWD roams
prior to netconfig it should stay in a connecting state (from the
perspective of DBus).

To fix this a new internal station state was added (no changes to
the DBus API) to distinguish between a purely WiFi connecting state
(STATION_STATE_CONNECTING/AUTO) and netconfig
(STATION_STATE_NETCONFIG). This allows IWD roam as needed if
netconfig is still running. Also, some special handling was added so
the station state property remains in a "connected" state until
netconfig actually completes, regardless of roams.

For some background this scenario happens if the DHCP server goes
down for an extended period, e.g. if its being upgraded/serviced.
2024-01-08 22:04:53 -06:00
James Prestwood 8f7443b0b3 station: add additional internal state, STATION_STATE_NETCONFIG
This is still treated as "connecting" from a DBus perspective but
will allow for better handling internally for some roaming corner
cases.
2024-01-08 22:04:41 -06:00
James Prestwood 77e5c94dc6 station: add debug events for internal states
This gives the tests a lot more fine-tune control to wait for
specific state transitions rather than only what is exposed over
DBus.

The additional events for "ft-roam" and "reassoc-roam" were removed
since these are now covered by the more generic state change events
("ft-roaming" and "roaming" respectively).
2024-01-04 11:57:28 -06:00
James Prestwood 593fad5260 station: handle netconfig after roaming for FW roams
This was not taken into account for FW roams and would result in the
station state being set to connected regardless of netconfig's result.
2024-01-04 11:46:39 -06:00
James Prestwood 8f5109c439 dpp: fix extra settings not being used when connecting
Before this change DPP was writing the credentials both to disk
and into the network object directly. This allowed the connection
to work fine but additional settings were not picked up due to
network_set_passphrase/psk loading the settings before they were
written.

Instead DPP can avoid setting the credentials to the network
object entirely and just write them to disk. Then, wait for
known networks to notify that the profile was either created
or updated then DPP can proceed to connecting. network_autoconnect()
will take care of loading the profile that DPP wrote and remove the
need for DPP to touch the network object at all.

One thing to note is that an idle callback is still needed from
within the known networks callback. This is because a new profile
requires network.c to set the network_info which is done in the
known networks callback. Rather than assume that network.c will be
called into before dpp.c an l_idle was added.
2023-12-19 12:41:50 -06:00