[PATCH] dbus: Enforce unique address for AP and pass in MAC address in CreateInterface method

Jintao Lin jintaolin at chromium.org
Mon Dec 5 16:37:04 PST 2022


CreateInterface can be used to create an AP interface. However Some WiFi
SoC does not ensure unique MAC address for the new virtual interface.
Enforce unique address is used for the created AP interface.

chromeOS uses random generated MAC address for AP interface so that the
device could remain anonymous and untrackable. Add an address parameter
for CreateInterface method to pass in OS managed MAC address.

This change also fix one potential memory leak in CreateInterface
method.

Signed-off-by: Jintao Lin <jintaolin at chromium.org>
---
 doc/dbus.doxygen                        |  1 +
 src/drivers/driver_nl80211.c            |  2 +-
 wpa_supplicant/dbus/dbus_new_handlers.c | 17 ++++++++++++++++-
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/doc/dbus.doxygen b/doc/dbus.doxygen
index a23817983..ab6f17a0b 100644
--- a/doc/dbus.doxygen
+++ b/doc/dbus.doxygen
@@ -43,6 +43,7 @@ registered in the bus with fi.w1.wpa_supplicant1 name.
 	      <tr><td>ConfigFile</td><td>s</td><td>Configuration file path</td><td>No</td>
 	      <tr><td>Create</td><td>b</td><td>Whether to create a new interface in the kernel</td><td>No</td>
 	      <tr><td>Type</td><td>s</td><td>Interface type to create (sta or ap)</td><td>No</td>
+	      <tr><td>Address</td><td>s</td><td>MAC address in colon-delimited format to be used in the created interface</td><td>No</td>
 	    </table>
 	  </dd>
 	</dl>
diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
index ecf166571..f899a85fa 100644
--- a/src/drivers/driver_nl80211.c
+++ b/src/drivers/driver_nl80211.c
@@ -7900,7 +7900,7 @@ static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type,
 	if (!addr &&
 	    (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP ||
 	     type == WPA_IF_P2P_GO || type == WPA_IF_MESH ||
-	     type == WPA_IF_STATION)) {
+	     type == WPA_IF_STATION || type == WPA_IF_AP_BSS)) {
 		/* Enforce unique address */
 		u8 new_addr[ETH_ALEN];
 
diff --git a/wpa_supplicant/dbus/dbus_new_handlers.c b/wpa_supplicant/dbus/dbus_new_handlers.c
index 6e940b633..4728d821f 100644
--- a/wpa_supplicant/dbus/dbus_new_handlers.c
+++ b/wpa_supplicant/dbus/dbus_new_handlers.c
@@ -756,6 +756,7 @@ DBusMessage * wpas_dbus_handler_create_interface(DBusMessage *message,
 	char *confname = NULL;
 	char *bridge_ifname = NULL;
 	bool create_iface = false;
+	u8 *if_addr = NULL;
 	enum wpa_driver_if_type if_type = WPA_IF_STATION;
 
 	dbus_message_iter_init(message, &iter);
@@ -804,6 +805,19 @@ DBusMessage * wpas_dbus_handler_create_interface(DBusMessage *message,
 			} else if (os_strcmp(entry.str_value, "ap") == 0) {
 				if_type = WPA_IF_AP_BSS;
 			} else {
+				wpa_dbus_dict_entry_clear(&entry);
+				goto error;
+			}
+			wpa_dbus_dict_entry_clear(&entry);
+		} else if (os_strcmp(entry.key, "Address") == 0 &&
+			   entry.type == DBUS_TYPE_STRING) {
+			if_addr = os_malloc(ETH_ALEN);
+			if (if_addr == NULL) {
+				wpa_dbus_dict_entry_clear(&entry);
+				goto oom;
+			}
+			if (hwaddr_aton(entry.str_value, if_addr)) {
+				wpa_dbus_dict_entry_clear(&entry);
 				goto error;
 			}
 			wpa_dbus_dict_entry_clear(&entry);
@@ -836,7 +850,7 @@ DBusMessage * wpas_dbus_handler_create_interface(DBusMessage *message,
 				    __func__, ifname);
 			if (!global->ifaces ||
 			    wpa_drv_if_add(global->ifaces, if_type, ifname,
-					   NULL, NULL, NULL, mac_addr,
+					   if_addr, NULL, NULL, mac_addr,
 					   NULL) < 0) {
 				reply = wpas_dbus_error_unknown_error(
 					message,
@@ -877,6 +891,7 @@ out:
 	os_free(ifname);
 	os_free(confname);
 	os_free(bridge_ifname);
+	os_free(if_addr);
 	return reply;
 
 error:
-- 
2.39.0.rc0.267.gcb52ba06e7-goog




More information about the Hostap mailing list