3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-22 06:29:23 +01:00
iwd/src/diagnostic.c
Denis Kenzior 8cb61f9aae diagnostic: Fix crash with Open networks
It isn't safe to return a NULL from diagnostic_akm_suite_to_security()
since the value is used directly.  Also, if the AKM suite is 0, this
implies that the network is an Open network and not some unknown AKM.

==17982== Invalid read of size 1
==17982==    at 0x483BC92: strlen (vg_replace_strmem.c:459)
==17982==    by 0x47DE60: _dbus1_builder_append_basic (dbus-util.c:981)
==17982==    by 0x41ACB2: dbus_append_dict_basic (dbus.c:197)
==17982==    by 0x412050: station_get_diagnostic_cb (station.c:3614)
==17982==    by 0x405B19: netdev_get_station_cb (netdev.c:4801)
==17982==    by 0x47436E: process_unicast (genl.c:994)
==17982==    by 0x47436E: received_data (genl.c:1102)
==17982==    by 0x470FBB: io_callback (io.c:120)
==17982==    by 0x4701DC: l_main_iterate (main.c:478)
==17982==    by 0x4702AB: l_main_run (main.c:525)
==17982==    by 0x4702AB: l_main_run (main.c:507)
==17982==    by 0x4704BB: l_main_run_with_signal (main.c:647)
==17982==    by 0x403EDB: main (main.c:490)
==17982==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==17982==
Aborting (signal 11) [/home/denkenz/iwd/src/iwd]
++++++++ backtrace ++++++++
0  0x488a550 in /lib64/libc.so.6
1  0x483bc92 in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so
2  0x47de61 in _dbus1_builder_append_basic() at ell/dbus-util.c:983
3  0x41acb3 in dbus_append_dict_basic() at src/dbus.c:197
4  0x412051 in station_get_diagnostic_cb() at src/station.c:3618
5  0x405b1a in netdev_get_station_cb() at src/netdev.c:4801
2021-04-28 11:19:38 -05:00

156 lines
4.2 KiB
C

/*
*
* Wireless daemon for Linux
*
* Copyright (C) 2021 Intel Corporation. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <ell/ell.h>
#include "src/diagnostic.h"
#include "src/dbus.h"
#include "src/ie.h"
/*
* Appends values from diagnostic_station_info into a DBus dictionary. This
* assumes the DBus dictionary array has already been 'entered', and expects the
* caller to 'leave' once called. This does not append the station address
* since the dictionary key name may be different depending on the caller.
*/
bool diagnostic_info_to_dict(const struct diagnostic_station_info *info,
struct l_dbus_message_builder *builder)
{
int16_t rssi = (int16_t)info->cur_rssi;
int16_t avg_rssi = (int16_t)info->avg_rssi;
if (info->have_cur_rssi)
dbus_append_dict_basic(builder, "RSSI", 'n', &rssi);
if (info->have_avg_rssi)
dbus_append_dict_basic(builder, "AverageRSSI", 'n', &avg_rssi);
if (info->have_rx_mcs) {
switch (info->rx_mcs_type) {
case DIAGNOSTIC_MCS_TYPE_HT:
dbus_append_dict_basic(builder, "RxMode", 's',
"802.11n");
dbus_append_dict_basic(builder, "RxMCS", 'y',
&info->rx_mcs);
break;
case DIAGNOSTIC_MCS_TYPE_VHT:
dbus_append_dict_basic(builder, "RxMode", 's',
"802.11ac");
dbus_append_dict_basic(builder, "RxMCS", 'y',
&info->rx_mcs);
break;
case DIAGNOSTIC_MCS_TYPE_HE:
dbus_append_dict_basic(builder, "RxMode", 's',
"802.11ax");
dbus_append_dict_basic(builder, "RxMCS", 'y',
&info->rx_mcs);
break;
default:
break;
}
}
if (info->have_tx_mcs) {
switch (info->tx_mcs_type) {
case DIAGNOSTIC_MCS_TYPE_HT:
dbus_append_dict_basic(builder, "TxMode", 's',
"802.11n");
dbus_append_dict_basic(builder, "TxMCS", 'y',
&info->tx_mcs);
break;
case DIAGNOSTIC_MCS_TYPE_VHT:
dbus_append_dict_basic(builder, "TxMode", 's',
"802.11ac");
dbus_append_dict_basic(builder, "TxMCS", 'y',
&info->tx_mcs);
break;
case DIAGNOSTIC_MCS_TYPE_HE:
dbus_append_dict_basic(builder, "TxMode", 's',
"802.11ax");
dbus_append_dict_basic(builder, "TxMCS", 'y',
&info->tx_mcs);
break;
default:
break;
}
}
if (info->have_tx_bitrate)
dbus_append_dict_basic(builder, "TxBitrate", 'u',
&info->tx_bitrate);
if (info->have_rx_bitrate)
dbus_append_dict_basic(builder, "RxBitrate", 'u',
&info->rx_bitrate);
if (info->have_expected_throughput)
dbus_append_dict_basic(builder, "ExpectedThroughput", 'u',
&info->expected_throughput);
return true;
}
const char *diagnostic_akm_suite_to_security(enum ie_rsn_akm_suite akm,
bool wpa)
{
if (akm == 0)
return "Open";
switch (akm) {
case IE_RSN_AKM_SUITE_8021X:
case IE_RSN_AKM_SUITE_8021X_SHA256:
return "WPA2-Enterprise";
case IE_RSN_AKM_SUITE_PSK:
if (wpa)
return "WPA1-Personal";
/* Fall through */
case IE_RSN_AKM_SUITE_PSK_SHA256:
return "WPA2-Personal";
case IE_RSN_AKM_SUITE_FT_OVER_8021X:
case IE_RSN_AKM_SUITE_FT_OVER_8021X_SHA384:
return "WPA2-Enterprise + FT";
case IE_RSN_AKM_SUITE_FT_USING_PSK:
return "WPA2-Personal + FT";
case IE_RSN_AKM_SUITE_SAE_SHA256:
return "WPA3-Personal";
case IE_RSN_AKM_SUITE_FT_OVER_SAE_SHA256:
return "WPA3-Personal + FT";
case IE_RSN_AKM_SUITE_OWE:
return "OWE";
case IE_RSN_AKM_SUITE_FILS_SHA256:
case IE_RSN_AKM_SUITE_FILS_SHA384:
return "FILS";
case IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA256:
case IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA384:
return "FILS + FT";
case IE_RSN_AKM_SUITE_OSEN:
return "OSEN";
default:
return "Unknown";
}
}