diff mbox series

[v2,08/11] nl80211: use and/or set socker owner where necessary

Message ID 20200411102527.154154-9-markus.theil@tu-ilmenau.de
State Superseded
Headers show
Series nl80211: rx path for control port frames (enabled only for wpa_supplicant) | expand

Commit Message

Markus Theil April 11, 2020, 10:25 a.m. UTC
Use methods which set or use the connection owner nl_sock*
where necessary. Initial operations need to register with the
SOCKET_OWNER attribute set (e.g. connect for STAs). Final operations
need to use the socket which holds the owner attribute (e.g. disconnect
for STAs).
---
 src/drivers/driver_nl80211.c | 52 ++++++++++++++++++++----------------
 1 file changed, 29 insertions(+), 23 deletions(-)

Comments

Jouni Malinen April 19, 2020, 1:48 p.m. UTC | #1
On Sat, Apr 11, 2020 at 12:25:24PM +0200, Markus Theil wrote:
> Use methods which set or use the connection owner nl_sock*
> where necessary. Initial operations need to register with the
> SOCKET_OWNER attribute set (e.g. connect for STAs). Final operations
> need to use the socket which holds the owner attribute (e.g. disconnect
> for STAs).

> diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
> @@ -6038,12 +6041,9 @@ skip_auth_type:
>  	if (ret)
>  		goto fail;
>  
> -	if (nl_connect_or_ctrl)
> -		ret = send_and_recv(drv->global, nl_connect_or_ctrl, msg,
> -				    NULL, (void *) -1);
> -	else
> -		ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1);
> -
> +	ret = send_and_recv_msgs_as_owner(drv, msg,
> +				  nl_connect_or_ctrl, 1,
> +				  NULL, NULL);

Why is this replacing (void *) -1 with NULL? That would result in not
clearing key material from memory with nl80211_nlmsg_clear() and the end
of send_and_recv().. I removed this undesired change to maintain the
current functionality.
diff mbox series

Patch

diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
index 9549d9b18..3da94fd69 100644
--- a/src/drivers/driver_nl80211.c
+++ b/src/drivers/driver_nl80211.c
@@ -3490,18 +3490,15 @@  static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss,
 		return nl80211_leave_ibss(drv, 1);
 	}
 	if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) {
-		struct nl_sock *nl_connect_or_ctrl = NULL;
-
-		if (bss->use_nl_connect)
-			nl_connect_or_ctrl = bss->nl_connect_or_ctrl;
 		return wpa_driver_nl80211_disconnect(drv, reason_code,
-						     nl_connect_or_ctrl);
+						     get_connect_or_ctrl_handle(bss));
 	}
 	wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)",
 		   __func__, MAC2STR(addr), reason_code);
 	nl80211_mark_disconnected(drv);
 	ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE,
-				      reason_code, 0, NULL);
+				      reason_code, 0,
+				      get_connect_or_ctrl_handle(bss));
 	/*
 	 * For locally generated deauthenticate, supplicant already generates a
 	 * DEAUTH event, so ignore the event from NL80211.
@@ -4485,7 +4482,9 @@  static int wpa_driver_nl80211_set_ap(void *priv,
 	}
 #endif /* CONFIG_IEEE80211AX */
 
-	ret = send_and_recv_msgs(drv, msg, NULL, NULL);
+	ret = send_and_recv_msgs_as_owner(drv, msg,
+					  get_connect_or_ctrl_handle(bss), 1,
+					  NULL, NULL);
 	if (ret) {
 		wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)",
 			   ret, strerror(-ret));
@@ -5505,7 +5504,9 @@  static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv,
 	int ret;
 
 	msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS);
-	ret = send_and_recv_msgs(drv, msg, NULL, NULL);
+	ret = send_and_recv_msgs_as_owner(drv, msg,
+				  get_connect_or_ctrl_handle(drv->first_bss), 1,
+				  NULL, NULL);
 	if (ret) {
 		wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d "
 			   "(%s)", ret, strerror(-ret));
@@ -5637,7 +5638,9 @@  retry:
 	if (ret < 0)
 		goto fail;
 
-	ret = send_and_recv_msgs(drv, msg, NULL, NULL);
+	ret = send_and_recv_msgs_as_owner(drv, msg,
+				  get_connect_or_ctrl_handle(drv->first_bss), 1,
+				  NULL, NULL);
 	msg = NULL;
 	if (ret) {
 		wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)",
@@ -6038,12 +6041,9 @@  skip_auth_type:
 	if (ret)
 		goto fail;
 
-	if (nl_connect_or_ctrl)
-		ret = send_and_recv(drv->global, nl_connect_or_ctrl, msg,
-				    NULL, (void *) -1);
-	else
-		ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1);
-
+	ret = send_and_recv_msgs_as_owner(drv, msg,
+				  nl_connect_or_ctrl, 1,
+				  NULL, NULL);
 	msg = NULL;
 	if (ret) {
 		wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d "
@@ -6112,19 +6112,17 @@  static int wpa_driver_nl80211_associate(
 	if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) {
 		enum nl80211_iftype nlmode = params->p2p ?
 			NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION;
-		struct nl_sock *nl_connect_or_ctrl = NULL;
-
 		if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0)
 			return -1;
 		if (params->key_mgmt_suite == WPA_KEY_MGMT_SAE ||
 		    params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE) {
-			nl_connect_or_ctrl = bss->nl_connect_or_ctrl;
 			bss->use_nl_connect = 1;
 		} else {
 			bss->use_nl_connect = 0;
 		}
 
-		return wpa_driver_nl80211_connect(drv, params, nl_connect_or_ctrl);
+		return wpa_driver_nl80211_connect(drv, params, 
+						  get_connect_or_ctrl_handle(bss));
 	}
 
 	nl80211_mark_disconnected(drv);
@@ -6159,7 +6157,9 @@  static int wpa_driver_nl80211_associate(
 			goto fail;
 	}
 
-	ret = send_and_recv_msgs(drv, msg, NULL, NULL);
+	ret = send_and_recv_msgs_as_owner(drv, msg,
+					  get_connect_or_ctrl_handle(drv->first_bss), 1,
+					  NULL, NULL);
 	msg = NULL;
 	if (ret) {
 		wpa_dbg(drv->ctx, MSG_DEBUG,
@@ -9553,7 +9553,9 @@  static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id,
 		if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) <
 		    0)
 			goto fail;
-		ret = send_and_recv_msgs(drv, msg, cmd_reply_handler, buf);
+		ret = send_and_recv_msgs_as_owner(drv, msg, 
+						  get_connect_or_ctrl_handle(bss), 0,
+						  cmd_reply_handler, buf);
 		if (ret)
 			wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d",
 				   ret);
@@ -10008,7 +10010,9 @@  static int nl80211_join_mesh(struct i802_bss *bss,
 	if (nl80211_put_mesh_config(msg, &params->conf) < 0)
 		goto fail;
 
-	ret = send_and_recv_msgs(drv, msg, NULL, NULL);
+	ret = send_and_recv_msgs_as_owner(drv, msg,
+					  get_connect_or_ctrl_handle(bss), 1,
+					  NULL, NULL);
 	msg = NULL;
 	if (ret) {
 		wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)",
@@ -10065,7 +10069,9 @@  static int wpa_driver_nl80211_leave_mesh(void *priv)
 
 	wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex);
 	msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH);
-	ret = send_and_recv_msgs(drv, msg, NULL, NULL);
+	ret = send_and_recv_msgs_as_owner(drv, msg,
+					  get_connect_or_ctrl_handle(bss), 0,
+					  NULL, NULL);
 	if (ret) {
 		wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)",
 			   ret, strerror(-ret));