From patchwork Mon Dec 12 00:29:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Zaborowski X-Patchwork-Id: 9469931 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 70A4D607D3 for ; Mon, 12 Dec 2016 00:29:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 58C28283C2 for ; Mon, 12 Dec 2016 00:29:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4BC172840F; Mon, 12 Dec 2016 00:29:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7457D283C2 for ; Mon, 12 Dec 2016 00:29:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753949AbcLLA33 (ORCPT ); Sun, 11 Dec 2016 19:29:29 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:35048 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751471AbcLLA32 (ORCPT ); Sun, 11 Dec 2016 19:29:28 -0500 Received: by mail-wm0-f68.google.com with SMTP id a20so7826545wme.2 for ; Sun, 11 Dec 2016 16:29:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=9tQrpMcSNiTUtUxeJc68SBy8+6I8ohHfF/vOqBgm6VQ=; b=hMxcdylX64enu0Dd0YqaY+AfDFNcB6Lgyvy5u9ulTZZqE66zWrUhK9B1RJwh9XbokM WNSwEaT5LyxH1JLgZAVTqNc4+6sGFhk4pCJSxz1/I0i5ETh95XcT946QkfZW6uLI0Eqj j1ps6ToOTLH722p0fVBGY791DM8dKdJZipzLrtXCk4LgyQzVAcCXas1ytqfHKy8XlS2R 3zuDTQBFDOK3dpu6y3SN9fAYrlkUKTWLQ1lOJbX3z7J/AOZfHLq3wy8EQtIxFafErGBs k3DjWvL5rxPiX2bbkX1fwaMK39foa9Db/9jKm+crecoZew2knZZslEC0Z2JtuiubFQ1a /KpA== X-Gm-Message-State: AKaTC01gyGZ75wOXI6uCWV5S/mHrq3QopTjSz80WHn5GO/idigiYbRi/VYzSQxNc45J5UQ== X-Received: by 10.28.27.133 with SMTP id b127mr7485718wmb.59.1481502566025; Sun, 11 Dec 2016 16:29:26 -0800 (PST) Received: from localhost.localdomain ([92.185.195.211]) by smtp.gmail.com with ESMTPSA id kp5sm54516374wjb.8.2016.12.11.16.29.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Dec 2016 16:29:25 -0800 (PST) From: Andrew Zaborowski To: linux-wireless@vger.kernel.org Subject: [PATCH] cfg80211: NL80211_ATTR_SOCKET_OWNER support for CMD_CONNECT Date: Mon, 12 Dec 2016 01:29:11 +0100 Message-Id: <20161212002911.5541-1-andrew.zaborowski@intel.com> X-Mailer: git-send-email 2.9.3 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Disconnect or deauthenticate when the owning socket is closed if this flag is supplied to CMD_CONNECT or CMD_AUTHENTICATE. This may be used to ensure userspace daemon doesn't leave an unmanaged connection behind. In some situations it would be possible to account for that, to some degree, in the deamon restart code, or in the up/down scripts without the use of this attribute. But there will be systems where the daemon can go away for varying periods without a warning due to local resource management. Signed-off-by: Andrew Zaborowski --- include/net/cfg80211.h | 7 +++++++ include/uapi/linux/nl80211.h | 2 ++ net/wireless/core.c | 33 +++++++++++++++++++++++++++++++++ net/wireless/mlme.c | 2 ++ net/wireless/nl80211.c | 28 +++++++++++++++++++++++++++- net/wireless/sme.c | 4 ++++ 6 files changed, 75 insertions(+), 1 deletion(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index bd19faa..ca2e252 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -3764,6 +3764,9 @@ struct cfg80211_cached_keys; * @conn: (private) cfg80211 software SME connection state machine data * @connect_keys: (private) keys to set after connection is established * @conn_bss_type: connecting/connected BSS type + * @conn_owner_nlportid: (private) connection owner socket port ID + * @disconnect_wk: (private) auto-disconnect work + * @disconnect_bssid: (private) the BSSID to use for auto-disconnect * @ibss_fixed: (private) IBSS is using fixed BSSID * @ibss_dfs_possible: (private) IBSS may change to a DFS channel * @event_list: (private) list for internal event processing @@ -3795,6 +3798,10 @@ struct wireless_dev { struct cfg80211_conn *conn; struct cfg80211_cached_keys *connect_keys; enum ieee80211_bss_type conn_bss_type; + u32 conn_owner_nlportid; + + struct work_struct disconnect_wk; + u8 disconnect_bssid[ETH_ALEN]; struct list_head event_list; spinlock_t event_lock; diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index 56368e9..84db1f0 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -1788,6 +1788,8 @@ enum nl80211_commands { * and remove functions. NAN notifications will be sent in unicast to that * socket. Without this attribute, any socket can add functions and the * notifications will be sent to the %NL80211_MCGRP_NAN multicast group. + * If set during %NL80211_CMD_ASSOCIATE or %NL80211_CMD_CONNECT the + * station will deauthenticate when the socket is closed. * * @NL80211_ATTR_TDLS_INITIATOR: flag attribute indicating the current end is * the TDLS link initiator. diff --git a/net/wireless/core.c b/net/wireless/core.c index 8201e6d..6b8fd68 100644 --- a/net/wireless/core.c +++ b/net/wireless/core.c @@ -357,6 +357,36 @@ static void cfg80211_sched_scan_stop_wk(struct work_struct *work) rtnl_unlock(); } +static void cfg80211_disconnect_wk(struct work_struct *work) +{ + struct cfg80211_registered_device *rdev; + struct wireless_dev *wdev; + + wdev = container_of(work, struct wireless_dev, disconnect_wk); + rdev = wiphy_to_rdev(wdev->wiphy); + + if (!wdev->netdev) + return; + + wdev_lock(wdev); + + if (wdev->conn_owner_nlportid) { + /* + * Use disconnect_bssid if still connecting and ops->disconnect + * not implemented. Otherwise we can use cfg80211_disconnect. + */ + if (rdev->ops->disconnect || wdev->current_bss) + cfg80211_disconnect(rdev, wdev->netdev, + WLAN_REASON_DEAUTH_LEAVING, true); + else + cfg80211_mlme_deauth(rdev, wdev->netdev, + wdev->disconnect_bssid, NULL, 0, + WLAN_REASON_DEAUTH_LEAVING, false); + } + + wdev_unlock(wdev); +} + /* exported functions */ struct wiphy *wiphy_new_nm(const struct cfg80211_ops *ops, int sizeof_priv, @@ -1117,6 +1147,8 @@ static int cfg80211_netdev_notifier_call(struct notifier_block *nb, wdev->iftype == NL80211_IFTYPE_ADHOC) && !wdev->use_4addr) dev->priv_flags |= IFF_DONT_BRIDGE; + INIT_WORK(&wdev->disconnect_wk, cfg80211_disconnect_wk); + nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE); break; case NETDEV_GOING_DOWN: @@ -1205,6 +1237,7 @@ static int cfg80211_netdev_notifier_call(struct notifier_block *nb, #ifdef CONFIG_CFG80211_WEXT kzfree(wdev->wext.keys); #endif + flush_work(&wdev->disconnect_wk); } /* * synchronise (so that we won't find this netdev diff --git a/net/wireless/mlme.c b/net/wireless/mlme.c index cbb48e2..9923244 100644 --- a/net/wireless/mlme.c +++ b/net/wireless/mlme.c @@ -328,6 +328,8 @@ int cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev, ASSERT_WDEV_LOCK(wdev); + wdev->conn_owner_nlportid = 0; + if (local_state_change && (!wdev->current_bss || !ether_addr_equal(wdev->current_bss->pub.bssid, bssid))) diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index c510810..502ae92 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -8003,6 +8003,12 @@ static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) wdev_unlock(dev->ieee80211_ptr); } + if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { + dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; + + memcpy(dev->ieee80211_ptr->disconnect_bssid, bssid, ETH_ALEN); + } + return err; } @@ -8050,6 +8056,10 @@ static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, local_state_change); wdev_unlock(dev->ieee80211_ptr); + + if (!err) + dev->ieee80211_ptr->conn_owner_nlportid = 0; + return err; } @@ -8097,6 +8107,10 @@ static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, local_state_change); wdev_unlock(dev->ieee80211_ptr); + + if (!err) + dev->ieee80211_ptr->conn_owner_nlportid = 0; + return err; } @@ -8723,6 +8737,10 @@ static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) wdev_unlock(dev->ieee80211_ptr); if (err) kzfree(connkeys); + + if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) + dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; + return err; } @@ -14425,13 +14443,21 @@ static int nl80211_netlink_notify(struct notifier_block * nb, spin_unlock(&rdev->destroy_list_lock); schedule_work(&rdev->destroy_work); } - } else if (schedule_scan_stop) { + + continue; + } + + if (schedule_scan_stop) { sched_scan_req->owner_nlportid = 0; if (rdev->ops->sched_scan_stop && rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) schedule_work(&rdev->sched_scan_stop_wk); } + + list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) + if (wdev->conn_owner_nlportid == notify->portid) + schedule_work(&wdev->disconnect_wk); } rcu_read_unlock(); diff --git a/net/wireless/sme.c b/net/wireless/sme.c index a77db33..f5cc067 100644 --- a/net/wireless/sme.c +++ b/net/wireless/sme.c @@ -713,6 +713,7 @@ void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid, kzfree(wdev->connect_keys); wdev->connect_keys = NULL; wdev->ssid_len = 0; + wdev->conn_owner_nlportid = 0; if (bss) { cfg80211_unhold_bss(bss_from_pub(bss)); cfg80211_put_bss(wdev->wiphy, bss); @@ -941,6 +942,7 @@ void __cfg80211_disconnected(struct net_device *dev, const u8 *ie, wdev->current_bss = NULL; wdev->ssid_len = 0; + wdev->conn_owner_nlportid = 0; nl80211_send_disconnected(rdev, dev, reason, ie, ie_len, from_ap); @@ -1084,6 +1086,8 @@ int cfg80211_disconnect(struct cfg80211_registered_device *rdev, kzfree(wdev->connect_keys); wdev->connect_keys = NULL; + wdev->conn_owner_nlportid = 0; + if (wdev->conn) err = cfg80211_sme_disconnect(wdev, reason); else if (!rdev->ops->disconnect)