|
|
651fae |
From b2ad4e6b24ed0271ca76cb27856def0a701fb778 Mon Sep 17 00:00:00 2001
|
|
|
651fae |
Message-Id: <b2ad4e6b24ed0271ca76cb27856def0a701fb778.1572271835.git.davide.caratti@gmail.com>
|
|
|
651fae |
From: Davide Caratti <davide.caratti@gmail.com>
|
|
|
651fae |
Date: Wed, 2 Oct 2019 14:08:41 +0200
|
|
|
651fae |
Subject: [PATCH] D-Bus: Fix P2P NULL dereference after interface removal
|
|
|
651fae |
|
|
|
651fae |
When the P2P management interface is deleted, P2P is then disabled and
|
|
|
651fae |
global->p2p_init_wpa_s is set to NULL. After that, other interfaces can
|
|
|
651fae |
still trigger P2P functions (like wpas_p2p_find()) using D-Bus. This
|
|
|
651fae |
makes wpa_supplicant terminate with SIGSEGV, because it dereferences a
|
|
|
651fae |
NULL pointer. Fix this by adding proper checks, like it's done with
|
|
|
651fae |
wpa_cli.
|
|
|
651fae |
|
|
|
651fae |
CC: Beniamino Galvani <bgalvani@redhat.com>
|
|
|
651fae |
CC: Benjamin Berg <benjamin@sipsolutions.net>
|
|
|
651fae |
Reported-by: Vladimir Benes <vbenes@redhat.com>
|
|
|
651fae |
Signed-off-by: Davide Caratti <davide.caratti@gmail.com>
|
|
|
651fae |
---
|
|
|
651fae |
wpa_supplicant/dbus/dbus_new_handlers_p2p.c | 69 ++++++++++++++++++++-
|
|
|
651fae |
1 file changed, 67 insertions(+), 2 deletions(-)
|
|
|
651fae |
|
|
|
651fae |
diff --git a/wpa_supplicant/dbus/dbus_new_handlers_p2p.c b/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
|
|
|
651fae |
index 8cdd88564..19715eb4c 100644
|
|
|
651fae |
--- a/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
|
|
|
651fae |
+++ b/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
|
|
|
651fae |
@@ -40,6 +40,14 @@ static int wpas_dbus_validate_dbus_ipaddr(struct wpa_dbus_dict_entry entry)
|
|
|
651fae |
}
|
|
|
651fae |
|
|
|
651fae |
|
|
|
651fae |
+static dbus_bool_t no_p2p_mgmt_interface(DBusError *error)
|
|
|
651fae |
+{
|
|
|
651fae |
+ dbus_set_error_const(error, WPAS_DBUS_ERROR_IFACE_UNKNOWN,
|
|
|
651fae |
+ "Could not find P2P mgmt interface");
|
|
|
651fae |
+ return FALSE;
|
|
|
651fae |
+}
|
|
|
651fae |
+
|
|
|
651fae |
+
|
|
|
651fae |
/**
|
|
|
651fae |
* Parses out the mac address from the peer object path.
|
|
|
651fae |
* @peer_path - object path of the form
|
|
|
651fae |
@@ -78,6 +86,22 @@ wpas_dbus_error_persistent_group_unknown(DBusMessage *message)
|
|
|
651fae |
}
|
|
|
651fae |
|
|
|
651fae |
|
|
|
651fae |
+/**
|
|
|
651fae |
+ * wpas_dbus_error_no_p2p_mgmt_iface - Return a new InterfaceUnknown error
|
|
|
651fae |
+ * message
|
|
|
651fae |
+ * @message: Pointer to incoming dbus message this error refers to
|
|
|
651fae |
+ * Returns: a dbus error message
|
|
|
651fae |
+ *
|
|
|
651fae |
+ * Convenience function to create and return an unknown interface error.
|
|
|
651fae |
+ */
|
|
|
651fae |
+static DBusMessage * wpas_dbus_error_no_p2p_mgmt_iface(DBusMessage *message)
|
|
|
651fae |
+{
|
|
|
651fae |
+ wpa_printf(MSG_DEBUG, "dbus: Could not find P2P mgmt interface");
|
|
|
651fae |
+ return dbus_message_new_error(message, WPAS_DBUS_ERROR_IFACE_UNKNOWN,
|
|
|
651fae |
+ "Could not find P2P mgmt interface");
|
|
|
651fae |
+}
|
|
|
651fae |
+
|
|
|
651fae |
+
|
|
|
651fae |
DBusMessage * wpas_dbus_handler_p2p_find(DBusMessage *message,
|
|
|
651fae |
struct wpa_supplicant *wpa_s)
|
|
|
651fae |
{
|
|
|
651fae |
@@ -145,6 +169,10 @@ DBusMessage * wpas_dbus_handler_p2p_find(DBusMessage *message,
|
|
|
651fae |
}
|
|
|
651fae |
|
|
|
651fae |
wpa_s = wpa_s->global->p2p_init_wpa_s;
|
|
|
651fae |
+ if (!wpa_s) {
|
|
|
651fae |
+ reply = wpas_dbus_error_no_p2p_mgmt_iface(message);
|
|
|
651fae |
+ goto error_nop2p;
|
|
|
651fae |
+ }
|
|
|
651fae |
|
|
|
651fae |
if (wpas_p2p_find(wpa_s, timeout, type, num_req_dev_types,
|
|
|
651fae |
req_dev_types, NULL, 0, 0, NULL, freq))
|
|
|
651fae |
@@ -157,8 +185,9 @@ DBusMessage * wpas_dbus_handler_p2p_find(DBusMessage *message,
|
|
|
651fae |
error_clear:
|
|
|
651fae |
wpa_dbus_dict_entry_clear(&entry);
|
|
|
651fae |
error:
|
|
|
651fae |
- os_free(req_dev_types);
|
|
|
651fae |
reply = wpas_dbus_error_invalid_args(message, entry.key);
|
|
|
651fae |
+error_nop2p:
|
|
|
651fae |
+ os_free(req_dev_types);
|
|
|
651fae |
return reply;
|
|
|
651fae |
}
|
|
|
651fae |
|
|
|
651fae |
@@ -166,7 +195,9 @@ error:
|
|
|
651fae |
DBusMessage * wpas_dbus_handler_p2p_stop_find(DBusMessage *message,
|
|
|
651fae |
struct wpa_supplicant *wpa_s)
|
|
|
651fae |
{
|
|
|
651fae |
- wpas_p2p_stop_find(wpa_s->global->p2p_init_wpa_s);
|
|
|
651fae |
+ wpa_s = wpa_s->global->p2p_init_wpa_s;
|
|
|
651fae |
+ if (wpa_s)
|
|
|
651fae |
+ wpas_p2p_stop_find(wpa_s);
|
|
|
651fae |
return NULL;
|
|
|
651fae |
}
|
|
|
651fae |
|
|
|
651fae |
@@ -185,6 +216,8 @@ DBusMessage * wpas_dbus_handler_p2p_rejectpeer(DBusMessage *message,
|
|
|
651fae |
return wpas_dbus_error_invalid_args(message, NULL);
|
|
|
651fae |
|
|
|
651fae |
wpa_s = wpa_s->global->p2p_init_wpa_s;
|
|
|
651fae |
+ if (!wpa_s)
|
|
|
651fae |
+ return wpas_dbus_error_no_p2p_mgmt_iface(message);
|
|
|
651fae |
|
|
|
651fae |
if (wpas_p2p_reject(wpa_s, peer_addr) < 0)
|
|
|
651fae |
return wpas_dbus_error_unknown_error(message,
|
|
|
651fae |
@@ -204,6 +237,8 @@ DBusMessage * wpas_dbus_handler_p2p_listen(DBusMessage *message,
|
|
|
651fae |
return wpas_dbus_error_no_memory(message);
|
|
|
651fae |
|
|
|
651fae |
wpa_s = wpa_s->global->p2p_init_wpa_s;
|
|
|
651fae |
+ if (!wpa_s)
|
|
|
651fae |
+ return wpas_dbus_error_no_p2p_mgmt_iface(message);
|
|
|
651fae |
|
|
|
651fae |
if (wpas_p2p_listen(wpa_s, (unsigned int) timeout)) {
|
|
|
651fae |
return dbus_message_new_error(message,
|
|
|
651fae |
@@ -245,6 +280,8 @@ DBusMessage * wpas_dbus_handler_p2p_extendedlisten(
|
|
|
651fae |
}
|
|
|
651fae |
|
|
|
651fae |
wpa_s = wpa_s->global->p2p_init_wpa_s;
|
|
|
651fae |
+ if (!wpa_s)
|
|
|
651fae |
+ return wpas_dbus_error_no_p2p_mgmt_iface(message);
|
|
|
651fae |
|
|
|
651fae |
if (wpas_p2p_ext_listen(wpa_s, period, interval))
|
|
|
651fae |
return wpas_dbus_error_unknown_error(
|
|
|
651fae |
@@ -350,6 +387,10 @@ DBusMessage * wpas_dbus_handler_p2p_group_add(DBusMessage *message,
|
|
|
651fae |
}
|
|
|
651fae |
|
|
|
651fae |
wpa_s = wpa_s->global->p2p_init_wpa_s;
|
|
|
651fae |
+ if (!wpa_s) {
|
|
|
651fae |
+ reply = wpas_dbus_error_no_p2p_mgmt_iface(message);
|
|
|
651fae |
+ goto out;
|
|
|
651fae |
+ }
|
|
|
651fae |
|
|
|
651fae |
if (pg_object_path != NULL) {
|
|
|
651fae |
char *net_id_str;
|
|
|
651fae |
@@ -433,6 +474,12 @@ static dbus_bool_t wpa_dbus_p2p_check_enabled(struct wpa_supplicant *wpa_s,
|
|
|
651fae |
"P2P is not available for this interface");
|
|
|
651fae |
return FALSE;
|
|
|
651fae |
}
|
|
|
651fae |
+ if (!wpa_s->global->p2p_init_wpa_s) {
|
|
|
651fae |
+ if (out_reply)
|
|
|
651fae |
+ *out_reply = wpas_dbus_error_no_p2p_mgmt_iface(
|
|
|
651fae |
+ message);
|
|
|
651fae |
+ return no_p2p_mgmt_interface(error);
|
|
|
651fae |
+ }
|
|
|
651fae |
return TRUE;
|
|
|
651fae |
}
|
|
|
651fae |
|
|
|
651fae |
@@ -822,6 +869,8 @@ DBusMessage * wpas_dbus_handler_p2p_prov_disc_req(DBusMessage *message,
|
|
|
651fae |
return wpas_dbus_error_invalid_args(message, NULL);
|
|
|
651fae |
|
|
|
651fae |
wpa_s = wpa_s->global->p2p_init_wpa_s;
|
|
|
651fae |
+ if (!wpa_s)
|
|
|
651fae |
+ return wpas_dbus_error_no_p2p_mgmt_iface(message);
|
|
|
651fae |
|
|
|
651fae |
if (wpas_p2p_prov_disc(wpa_s, peer_addr, config_method,
|
|
|
651fae |
WPAS_P2P_PD_FOR_GO_NEG, NULL) < 0)
|
|
|
651fae |
@@ -1882,6 +1931,8 @@ dbus_bool_t wpas_dbus_getter_p2p_peer_groups(
|
|
|
651fae |
|
|
|
651fae |
wpa_s = peer_args->wpa_s;
|
|
|
651fae |
wpa_s = wpa_s->global->p2p_init_wpa_s;
|
|
|
651fae |
+ if (!wpa_s)
|
|
|
651fae |
+ return no_p2p_mgmt_interface(error);
|
|
|
651fae |
|
|
|
651fae |
wpa_s_go = wpas_get_p2p_client_iface(wpa_s, info->p2p_device_addr);
|
|
|
651fae |
if (wpa_s_go) {
|
|
|
651fae |
@@ -1963,6 +2014,9 @@ dbus_bool_t wpas_dbus_getter_persistent_groups(
|
|
|
651fae |
dbus_bool_t success = FALSE;
|
|
|
651fae |
|
|
|
651fae |
wpa_s = wpa_s->global->p2p_init_wpa_s;
|
|
|
651fae |
+ if (!wpa_s)
|
|
|
651fae |
+ return no_p2p_mgmt_interface(error);
|
|
|
651fae |
+
|
|
|
651fae |
if (!wpa_s->parent->dbus_new_path)
|
|
|
651fae |
return FALSE;
|
|
|
651fae |
|
|
|
651fae |
@@ -2077,6 +2131,11 @@ DBusMessage * wpas_dbus_handler_add_persistent_group(
|
|
|
651fae |
dbus_message_iter_init(message, &iter);
|
|
|
651fae |
|
|
|
651fae |
wpa_s = wpa_s->global->p2p_init_wpa_s;
|
|
|
651fae |
+ if (!wpa_s) {
|
|
|
651fae |
+ reply = wpas_dbus_error_no_p2p_mgmt_iface(message);
|
|
|
651fae |
+ goto err;
|
|
|
651fae |
+ }
|
|
|
651fae |
+
|
|
|
651fae |
if (wpa_s->parent->dbus_new_path)
|
|
|
651fae |
ssid = wpa_config_add_network(wpa_s->conf);
|
|
|
651fae |
if (ssid == NULL) {
|
|
|
651fae |
@@ -2159,6 +2218,10 @@ DBusMessage * wpas_dbus_handler_remove_persistent_group(
|
|
|
651fae |
DBUS_TYPE_INVALID);
|
|
|
651fae |
|
|
|
651fae |
wpa_s = wpa_s->global->p2p_init_wpa_s;
|
|
|
651fae |
+ if (!wpa_s) {
|
|
|
651fae |
+ reply = wpas_dbus_error_no_p2p_mgmt_iface(message);
|
|
|
651fae |
+ goto out;
|
|
|
651fae |
+ }
|
|
|
651fae |
|
|
|
651fae |
/*
|
|
|
651fae |
* Extract the network ID and ensure the network is actually a child of
|
|
|
651fae |
@@ -2235,6 +2298,8 @@ DBusMessage * wpas_dbus_handler_remove_all_persistent_groups(
|
|
|
651fae |
struct wpa_config *config;
|
|
|
651fae |
|
|
|
651fae |
wpa_s = wpa_s->global->p2p_init_wpa_s;
|
|
|
651fae |
+ if (!wpa_s)
|
|
|
651fae |
+ return wpas_dbus_error_no_p2p_mgmt_iface(message);
|
|
|
651fae |
|
|
|
651fae |
config = wpa_s->conf;
|
|
|
651fae |
ssid = config->ssid;
|
|
|
651fae |
--
|
|
|
651fae |
2.21.0
|
|
|
651fae |
|