Jouni Malinen [Wed, 7 Jan 2015 14:29:19 +0000 (16:29 +0200)]
tests: Make scan_random_mac more robust
There is a race condition between wlantest having received and written
the sniffer log and this test case using tshark to process it. Wait one
second before running tshark to make it less likely to get truncated
results that can result in the test case failing.
Jouni Malinen [Mon, 5 Jan 2015 18:30:28 +0000 (20:30 +0200)]
Add support for testing memory allocation failures
The new control interface command TEST_ALLOC_FAIL and GET_ALLOC_FAIL can
now be used to trigger memory allocation failures for testing purposes.
TEST_ALLOC_FAIL sets a failure conditions with
<count>:func[;func][;func]... string and GET_ALLOC_FAIL returns the
current state using the same format. Whenever an allocation is made with
a matching backtrace of calling functions, the count is decremented by
one and once zero is reached, the allocation is forced to fail.
Function names can be prefixed with either '=' or '?' to get different
matching behavior. '=' requires this specific function to be the next
one in the backtrace (i.e., do not skip any other functions in the list
which is the default behavior). '?' allows the function to be optionally
present in the backtrace.
Jouni Malinen [Tue, 6 Jan 2015 20:54:52 +0000 (22:54 +0200)]
TDLS: Fix an interface addition error path
It is possible for wpa_tdls_teardown_peers() to be called with sm ==
NULL in case interface addition fails before the WPA state machine is
initialized.
Jouni Malinen [Tue, 6 Jan 2015 15:04:24 +0000 (17:04 +0200)]
D-Bus: Fix string array dict entry parser in out-of-memory case
entry->strarray_value was left to point to freed memory in case
os_realloc_array() failed. This resulted in the following
wpa_dbus_dict_entry_clear() trying to free an already freed memory area.
In addition, the separately allocated strings in the array would have
been leaked in such a case. Furthermore, wpa_dbus_dict_entry_clear() was
not prepared for the possibility of the initial os_calloc() call failing
and entry->strarray_value being NULL without array_len being cleared to
zero. That would have resulted in reading uninitialized memory and NULL
pointer dereference.
Jouni Malinen [Tue, 6 Jan 2015 14:45:16 +0000 (16:45 +0200)]
D-Bus: Fix byte array dict entry parser in out-of-memory case
entry->bytearray_value was left to point to freed memory in case
os_realloc_array() failed. This resulted in the following
wpa_dbus_dict_entry_clear() trying to free an already freed memory area.
Jouni Malinen [Tue, 6 Jan 2015 11:22:06 +0000 (13:22 +0200)]
D-Bus (old): Fix message handler error paths
The error reply needs to be sent out as a response. The "out" label was
in incorrect place to allow that to happen; instead, it ended up leaking
memory for the generated reply message.
Jouni Malinen [Tue, 6 Jan 2015 09:46:46 +0000 (11:46 +0200)]
trace: Fix compiler warning on 32-bit builds with bfd support
With CONFIG_WPA_TRACE_BFD, the type cast from void* to integer was
generating a compiler warning due to the target integer being larger in
size in case of 32-bit builds. Type case to bfd_hostptr_t instead of
directly to bfd_vma to avoid this.
Jouni Malinen [Mon, 5 Jan 2015 19:57:15 +0000 (21:57 +0200)]
Fix hostapd initialization error path on allocation failure
If hostapd_alloc_bss_data() failed to allocate the struct hostapd_data
instance, dynamic interface addition path ended up trying to dereference
freed memory due to incorrect cleanup steps. Fix this by decrementing
the interface count when the newly added interface is removed. In
addition, make the setup more robust by clearing all changes within
hostapd_data_alloc() if any of the allocations fails.
Jouni Malinen [Tue, 6 Jan 2015 16:27:06 +0000 (18:27 +0200)]
nl80211: Fix compilation with libnl 1.1 and 2.0
Unfortunately, libnl 3.0 has changed the API in a way that is not
backwards compatible by renaming nlmsg_len() to nlmsg_datalen() without
leaving the older nlmsg_len() defined. As such, there does not seem to
be any clean way of using this function without breaking the build with
some libnl versions. For now, replace this call with direct calculation
of the data length since it can be done with a simple one-liner that
compiles with all libnl versions.
Jouni Malinen [Mon, 5 Jan 2015 15:27:08 +0000 (17:27 +0200)]
OpenSSL: Fix pbkdf2_sha1() wrapper
This was supposed to use the iterations parameter from the caller
instead of the hardcoded 4096. In practice, this did not have problems
for normal uses since that 4096 value was used in all cases.
Jouni Malinen [Mon, 5 Jan 2015 13:48:17 +0000 (15:48 +0200)]
tests: Add module tests for AES-SIV
This moves the AES-SIV test case from tests/test-aes.c to be part of
wpa_supplicant module testing framework with a new
src/crypto/crypto_module_tests.c component. In addition, the second test
vector from RFC 5297 is also included for additional coverage.
Jouni Malinen [Mon, 5 Jan 2015 11:40:07 +0000 (13:40 +0200)]
nl80211: Simplify event processing error paths
These are practically unreachable code since cfg80211 fills in the
required attributes or does not send the event. Keep the checks in
place, but minimize the extra code in wpa_supplicant/hostapd.
Jouni Malinen [Mon, 5 Jan 2015 10:21:12 +0000 (12:21 +0200)]
nl80211: Remove cfg80211 state mismatch workaround for authentication
cfg80211 dropped support for tracking BSS authentication state and
setting NL80211_BSS_STATUS_AUTHENTICATED in 'cfg80211: stop tracking
authenticated state' three years ago (starting in Linux 3.4). As such,
this workaround code in wpa_supplicant cannot be reached anymore. There
is no real need for maintaining it for older kernels either, since there
are other ways of detecting and working around state mismatches with the
actual authentication operations failing.
Jouni Malinen [Mon, 5 Jan 2015 10:00:09 +0000 (12:00 +0200)]
nl80211: Check support for rekey offload on first use
While there is no explicit driver capability advertisement for this in
nl80211, the EOPNOTSUPP response can be interpreted as a clear
indication of NL80211_CMD_SET_REKEY_OFFLOAD not being supported. Check
for that and don't try to offload keys again if the driver has not use
for them.
Ilan Peer [Mon, 29 Dec 2014 06:41:06 +0000 (01:41 -0500)]
scan: Add MAC address randomization in scan handling
1. Supported MAC address randomization for scan.
2. Supported MAC address randomization for scheduled scan.
2. Supported MAC address randomization for pno.
4. Add functions to set and clear the MAC address randomization
state variables.
Ilan Peer [Mon, 29 Dec 2014 06:41:04 +0000 (01:41 -0500)]
driver: Add definitions for MAC address randomization in scan
1. Add parameters to the scan command to allow MAC address
randomization during scan and scheduled scan.
2. Add capability bits to publish MAC address randomization support
in scan and scheduled scan.
Jouni Malinen [Sun, 4 Jan 2015 19:45:18 +0000 (21:45 +0200)]
tests: TDLS channel switching
Verify correct behavior with invalid commands. In addition, allow minor
mac80211_hwsim modifications to be used to enable testing of the driver
interface to enable and disable channel switching.
For the start operation, this includes appropriate parameters for
specifying channel and peer information. The cancel operation includes
peer information.
Arik Nemtsov [Mon, 29 Dec 2014 03:35:20 +0000 (22:35 -0500)]
nl80211: Pass TDLS channel-switch start/stop params to kernel
The kernel-driver/firmware are responsible for performing periodic
switches to the target channel with the given peer. Propagate all TDLS
channel switching related information to kernel.
Arik Nemtsov [Mon, 29 Dec 2014 05:20:51 +0000 (00:20 -0500)]
TDLS: Propagate enable/disable channel-switch commands to driver
The supplicant code does not try to control the actual channel of the
radio at any point. It simply passes the target peer and channel
parameters to the driver. It's the driver's responsibility to
periodically initiate TDLS channel-switch operations when TDLS
channel-switching is enabled.
Allow enable/disable operations to be invoked via the control interface.
Eliad Peller [Mon, 29 Dec 2014 02:15:02 +0000 (21:15 -0500)]
tests: wmm_ac_status and roaming case with WMM-AC
Make sure the wmm_ac_status command reflects correctly the existing
tspecs after add_ts/del_ts commands. Add a new test to verify all tspecs
are removed on roaming (while FT is not used).
Eliad Peller [Mon, 29 Dec 2014 02:15:01 +0000 (21:15 -0500)]
WMM AC: Reconfigure tspecs on reassociation to the same BSS
The specification requires the tspecs to be kept upon reassociation to
the same BSS. Save the last tspecs before such reassociation, and
reconfigure on the association notification.
Note that the current flow is not transparent to the user
(it is notified about deauth/reassoc and tspec removal/addition).
Eliad Peller [Mon, 29 Dec 2014 02:15:00 +0000 (21:15 -0500)]
WMM AC: Do not fail on unknown IEs in Association Response
Some APs add their custom (vendor-specific) IEs to the Association
Response frame. Fail WMM AC initialization only if Association Response
frame IE parsing actually failed, i.e., ignore all unknown IEs.
If registering WMM-AC ADDTS response action frame or WMM-AC DELTS
action frame fails, the management frame handler is not being
registered. This results with a segmentation fault when trying to
unsubscribe the handler when the interface is removed.
Fix it by always registering the handler and just returning a negative
value to note that the action frame could not be registered.
Jouni Malinen [Sat, 3 Jan 2015 13:57:41 +0000 (15:57 +0200)]
doc: Add rule for generating _wpa_supplicant.eps
Commit 7c4e92115a795dd2ee2135cf49d7e9e172fb5851 ('Update Doxygen
documentation for new version') rename the PNG version of the image, but
forgot the EPS version for Latex.
Jouni Malinen [Sat, 3 Jan 2015 13:44:35 +0000 (15:44 +0200)]
doc: Disable Doxygen autolink support
The way autolink support is implementing in Doxygen is a bit
inconvenient with wpa_supplicant being recognized as something that
would always be linked to struct wpa_supplicant. In addition, number of
links were not really noticed automatically. To get this working more
robustly and without having to use the %wpa_supplicant workaround (which
had its own issues, e.g., with titles), disable autolinking and use
explicit \ref commands instead.
This is also updating some of the obsolete notes to point to correct
file names, etc. changes in the source code tree.
Jouni Malinen [Fri, 2 Jan 2015 23:01:42 +0000 (01:01 +0200)]
nl80211: Clear nlmsg payload with keys before freeing
This reduces the time possible keys could remain in heap memory. Couple
of the nl80211 messages include keys (TK for normal ciphers and
KCK/KEK/PMK for various offloading cases).
Jouni Malinen [Fri, 2 Jan 2015 20:54:30 +0000 (22:54 +0200)]
nl80211: Note linux_set_iface_flags() failure in debug log
There was one final remaining linux_set_iface_flags() call that did not
check the result. This specific one does not really matter much, but
anyway, be more consistent by checking the result and log any error in
debug log. (CID 74146)
Jouni Malinen [Fri, 2 Jan 2015 20:12:38 +0000 (22:12 +0200)]
tests: Make wpas_mesh_max_peering more robust
The previous version was enabling all three stations at the same time
and left dev[1] and dev[2] competing on getting connected with dev[0]
that allowed only one pairing. This was not exactly robust and the pass
criteria depended on an extra event from either dev[1] or dev[2]. Fix
that by first connecting dev[0] and dev[1] and only after that, start
dev[2]. This allows proper validation of both the peering limit on
dev[0] and no extra event on dev[2].
Jouni Malinen [Fri, 2 Jan 2015 16:21:25 +0000 (18:21 +0200)]
tests: Make scan_hidden more robust under heavy CPU load
It is possible for the Probe Response frame wait to time out when active
scanning is used under heavy CPU load. Make this test case more robust
by trying multiple times before declaring the scan for a hidden SSID to
have failed.
Jouni Malinen [Fri, 26 Dec 2014 15:44:24 +0000 (17:44 +0200)]
tests: Enable wpa_supplicant D-Bus support for hwsim tests
This allows automated testing of the wpa_supplicant D-Bus interface. The
instance controlling wlan0 registers with D-Bus if dbus-daemon was
started successfully. This is only used in VM testing, i.e., not when
run-tests.sh is used on the host system with D-Bus running for normal
system purposes.
Jouni Malinen [Wed, 31 Dec 2014 10:18:43 +0000 (12:18 +0200)]
doc: Document the D-Bus P2P extensions
P2P support was added to the wpa_supplicant D-Bus interface long time
ago, but there has been no attempt of documenting that interface so far.
This commit adds at least a list of new interfaces, methods, properties,
and signals. Some of the incorrect and/or strange parts of the interface
are also identified with bug/todo comments.
Jouni Malinen [Fri, 2 Jan 2015 15:11:15 +0000 (17:11 +0200)]
D-Bus: Fix WPS.Start method in AP/P2P GO mode
Previously, role="enrollee" was required to be used to allow the AP mode
WPS operation to be started. This is incorrect since the AP/GO will
operate in Registrar role. Fix this by ignoring the role parameter when
AP (including P2P GO) mode is enabled.
Jouni Malinen [Fri, 2 Jan 2015 15:09:38 +0000 (17:09 +0200)]
WPS: Reject station-mode WPS operations when AP mode is enabled
Start of station-mode WPS PBC/PIN/Registrar/NFC operation would result
in the AP mode getting disabled. This can be particularly confusing for
the P2P GO case where the group would need to be stopped cleanly. As
such, it is better to reject these invalid operations rather than trying
to handle all corner cases needed to allow this to work robustly.
Jouni Malinen [Fri, 2 Jan 2015 10:25:32 +0000 (12:25 +0200)]
D-Bus: Make P2P Group Passphrase property getter available for P2P Client
There is no need to limit this property based on the role of the device
in the group, so return the passphrase if it is available. It will be
available in GO role and it may be available in P2P Client role based on
whether the peer GO provided it during the WPS provisioning step.
Jouni Malinen [Fri, 2 Jan 2015 10:20:44 +0000 (12:20 +0200)]
D-Bus: Fix P2P Group PSK property getter
This was returning a byte array of the pointer to the PSK, not the
actual PSK, due to incorrect use of
wpas_dbus_simple_array_property_getter(). In addition, there is no need
to limit this property based on the role of the device in the group, so
return the PSK if it is available (which it will be for both GO and P2P
Client roles).
Jouni Malinen [Thu, 1 Jan 2015 20:36:52 +0000 (22:36 +0200)]
D-Bus: Simplify out-of-memory reporting
There is no need to have separate wpa_printf() and different error
message strings for the unlikely out-of-error messages. Use a helper
function, wpas_dbus_error_no_memory(), to get consistent behavior with a
one-line call.
Jouni Malinen [Thu, 1 Jan 2015 20:16:34 +0000 (22:16 +0200)]
D-Bus: Remove the obsolete notes from wpas_dbus_error_unknown_error()
Commit 6aeeb6fa21bc072ba92ce9423ba5c0417e8c0bf5 ('dbus: clean up new
D-Bus interface getters and setters') redesigned the property
getter/setter calls in a way that made the
wpas_dbus_error_unknown_error() note about message being NULL in some
cases obsolete. All the remaining callers are from method handler
functions that must have a valid message. Remove the obsolete notes and
unnecessary messsage == NULL check.
Jouni Malinen [Wed, 31 Dec 2014 11:57:48 +0000 (13:57 +0200)]
D-Bus: Simplify message building error paths
There is no need to have multiple separate return statements for error
cases in a sequence of operations. In addition, there is not much point
in "converting" boolean return values with "if (!res) return FALSE;
return TRUE;" style constructions.
net_id_str can be NULL and that must be checked for to avoid NULL
pointer dereference if an invalid persistent_group_object path is used
with these methods.
Jouni Malinen [Thu, 1 Jan 2015 09:42:32 +0000 (11:42 +0200)]
D-Bus: Clean up wpas_dbus_new_decompose_object_path()
None of the new D-Bus interface cases use the bssid_part in
decompose_object_path (while the old interface ones do). As such, this
is dead code and can be removed. In addition, the P2P addition here was
pretty ugly extension. Replace these with a cleaner way of passing the
separating string (e.g., "Networks") from the caller and returning the
requested item.
In addition, there is no need to allocate the returned item separately,
so use a single allocation and a pointer to that allocated memory. This
will make it easier for callers to have to free only a single
allocation. This is also fixing a memory leak in P2P invitation
persistent group case where the caller had missed the need to free the
returned values.
Jouni Malinen [Thu, 1 Jan 2015 13:24:08 +0000 (15:24 +0200)]
D-Bus: Clean up parse_peer_object_path() uses
This helper function does not modify peer_path, so mark it const. In
addition, there is no point in callers to check separately whether
peer_path is NULL since that is taken care of by this helper function.
Jouni Malinen [Thu, 1 Jan 2015 00:10:37 +0000 (02:10 +0200)]
D-Bus: Remove useless wpa_s->conf checks
This cannot be NULL when an interface is in use. There is not much point
in couple of functions checking this while large number of other places
do not.
Jouni Malinen [Wed, 31 Dec 2014 14:54:48 +0000 (16:54 +0200)]
D-Bus (old): Fix removeNetwork method to not use freed memory
wpa_supplicant_deauthenticate() call needs to happen before
wpa_config_remove_network(). Freed memory could be dereferenced if
removeNetwork method was issued on the currently connected network.
Jouni Malinen [Wed, 31 Dec 2014 14:40:14 +0000 (16:40 +0200)]
D-Bus: Avoid valgrind warning due to compiler optimization
It looks like both gcc and clang optimize the (entry.type != foo ||
entry.array_type != bar) in a way that ends up evaluating the second
condition even when the first one results in 0. While this is not really
what the C language requirements on short-circuit evaluation require,
the compiler likely assumes this can have no side effects and with both
type and array_type being comparable in a single 64-bit operation, this
can clearly be a bit more efficient. While the code behaves same in both
cases, valgrind does warn about use of uninitialized memory when the
second condition is evaluated (entry.array_type is not initialized if
entry.type != DBUS_TYPE_ARRAY).
To keep valgrind logs cleaner, initialize entry.array_type to
DBUS_TYPE_INVALID so that these compiler optimizations do not result in
reading uninitialized memory.
Jouni Malinen [Wed, 31 Dec 2014 14:33:35 +0000 (16:33 +0200)]
D-Bus: Avoid compiler warning on sometimes uninitialized variable
The logic in wpas_dbus_signal_p2p_provision_discovery() seemed to imply
that there could be a case where _signal would be used uninitized. While
that is not the case since either (request || !status) or (!request &&
status) would always be true, some compilers do not seem to be clever
enough to figure that out to avoid the warning. Make this easier for
such compilers by removing the (!request && status) condition since it
is identical to !(request || !status).