diff mbox series

[v2,2/3] wifi: mac80211: Add support to randomize TA of auth and deauth frames

Message ID 20230108071552.2646591-2-quic_vjakkam@quicinc.com
State Superseded
Headers show
Series [v2,1/3] wifi: nl80211: Add support for randomizing TA of auth and deauth frames | expand

Commit Message

Veerendranath Jakkam Jan. 8, 2023, 7:15 a.m. UTC
Cache the TA of the authentication and deauthentication frames
temporarily till the response waiting time offchannel period complete
and indicate the temporary address to driver when driver supports
randomizing TA of auth and deauth frames. Driver should allow TX and RX
of the frames when the temporary address is TA and RA respectively.
Allow the authentication and deauthentication frames with cached
address as RA in RX path.

Signed-off-by: Veerendranath Jakkam <quic_vjakkam@quicinc.com>
---
 include/net/mac80211.h    | 12 ++++++++++++
 net/mac80211/main.c       |  3 ++-
 net/mac80211/offchannel.c | 38 ++++++++++++++++++++++++++++++++++++++
 net/mac80211/rx.c         | 18 ++++++++++++++----
 net/mac80211/util.c       |  7 ++++++-
 5 files changed, 72 insertions(+), 6 deletions(-)

Comments

kernel test robot Jan. 8, 2023, 8:48 a.m. UTC | #1
Hi Veerendranath,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on wireless-next/main]
[also build test WARNING on wireless/main linus/master v6.2-rc2 next-20230106]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Veerendranath-Jakkam/wifi-mac80211-Add-support-to-randomize-TA-of-auth-and-deauth-frames/20230108-151808
base:   https://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless-next.git main
patch link:    https://lore.kernel.org/r/20230108071552.2646591-2-quic_vjakkam%40quicinc.com
patch subject: [PATCH v2 2/3] wifi: mac80211: Add support to randomize TA of auth and deauth frames
config: powerpc-allmodconfig
compiler: powerpc-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/3daf7fb3405bc97698082157c393328592de3b97
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Veerendranath-Jakkam/wifi-mac80211-Add-support-to-randomize-TA-of-auth-and-deauth-frames/20230108-151808
        git checkout 3daf7fb3405bc97698082157c393328592de3b97
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=powerpc olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=powerpc SHELL=/bin/bash net/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   In file included from net/mac80211/main.c:11:
>> include/net/mac80211.h:380:46: warning: left shift count >= width of type [-Wshift-count-overflow]
     380 |         BSS_CHANGED_TEMP_ADDR           = 1UL<<32,
         |                                              ^~
--
   In file included from net/mac80211/driver-ops.h:11,
                    from net/mac80211/trace.c:8:
>> include/net/mac80211.h:380:46: warning: left shift count >= width of type [-Wshift-count-overflow]
     380 |         BSS_CHANGED_TEMP_ADDR           = 1UL<<32,
         |                                              ^~
   In file included from net/mac80211/trace.h:3035,
                    from net/mac80211/trace.c:11:
   include/trace/define_trace.h:95:42: fatal error: ./trace.h: No such file or directory
      95 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
         |                                          ^
   compilation terminated.


vim +380 include/net/mac80211.h

   292	
   293	/**
   294	 * enum ieee80211_bss_change - BSS change notification flags
   295	 *
   296	 * These flags are used with the bss_info_changed(), link_info_changed()
   297	 * and vif_cfg_changed() callbacks to indicate which parameter(s) changed.
   298	 *
   299	 * @BSS_CHANGED_ASSOC: association status changed (associated/disassociated),
   300	 *	also implies a change in the AID.
   301	 * @BSS_CHANGED_ERP_CTS_PROT: CTS protection changed
   302	 * @BSS_CHANGED_ERP_PREAMBLE: preamble changed
   303	 * @BSS_CHANGED_ERP_SLOT: slot timing changed
   304	 * @BSS_CHANGED_HT: 802.11n parameters changed
   305	 * @BSS_CHANGED_BASIC_RATES: Basic rateset changed
   306	 * @BSS_CHANGED_BEACON_INT: Beacon interval changed
   307	 * @BSS_CHANGED_BSSID: BSSID changed, for whatever
   308	 *	reason (IBSS and managed mode)
   309	 * @BSS_CHANGED_BEACON: Beacon data changed, retrieve
   310	 *	new beacon (beaconing modes)
   311	 * @BSS_CHANGED_BEACON_ENABLED: Beaconing should be
   312	 *	enabled/disabled (beaconing modes)
   313	 * @BSS_CHANGED_CQM: Connection quality monitor config changed
   314	 * @BSS_CHANGED_IBSS: IBSS join status changed
   315	 * @BSS_CHANGED_ARP_FILTER: Hardware ARP filter address list or state changed.
   316	 * @BSS_CHANGED_QOS: QoS for this association was enabled/disabled. Note
   317	 *	that it is only ever disabled for station mode.
   318	 * @BSS_CHANGED_IDLE: Idle changed for this BSS/interface.
   319	 * @BSS_CHANGED_SSID: SSID changed for this BSS (AP and IBSS mode)
   320	 * @BSS_CHANGED_AP_PROBE_RESP: Probe Response changed for this BSS (AP mode)
   321	 * @BSS_CHANGED_PS: PS changed for this BSS (STA mode)
   322	 * @BSS_CHANGED_TXPOWER: TX power setting changed for this interface
   323	 * @BSS_CHANGED_P2P_PS: P2P powersave settings (CTWindow, opportunistic PS)
   324	 *	changed
   325	 * @BSS_CHANGED_BEACON_INFO: Data from the AP's beacon became available:
   326	 *	currently dtim_period only is under consideration.
   327	 * @BSS_CHANGED_BANDWIDTH: The bandwidth used by this interface changed,
   328	 *	note that this is only called when it changes after the channel
   329	 *	context had been assigned.
   330	 * @BSS_CHANGED_OCB: OCB join status changed
   331	 * @BSS_CHANGED_MU_GROUPS: VHT MU-MIMO group id or user position changed
   332	 * @BSS_CHANGED_KEEP_ALIVE: keep alive options (idle period or protected
   333	 *	keep alive) changed.
   334	 * @BSS_CHANGED_MCAST_RATE: Multicast Rate setting changed for this interface
   335	 * @BSS_CHANGED_FTM_RESPONDER: fine timing measurement request responder
   336	 *	functionality changed for this BSS (AP mode).
   337	 * @BSS_CHANGED_TWT: TWT status changed
   338	 * @BSS_CHANGED_HE_OBSS_PD: OBSS Packet Detection status changed.
   339	 * @BSS_CHANGED_HE_BSS_COLOR: BSS Color has changed
   340	 * @BSS_CHANGED_FILS_DISCOVERY: FILS discovery status changed.
   341	 * @BSS_CHANGED_UNSOL_BCAST_PROBE_RESP: Unsolicited broadcast probe response
   342	 *	status changed.
   343	 * @BSS_CHANGED_TEMP_ADDR: Temporary self address allowed for authentication and
   344	 *	deauthentication frames is changed.
   345	 *
   346	 */
   347	enum ieee80211_bss_change {
   348		BSS_CHANGED_ASSOC		= 1<<0,
   349		BSS_CHANGED_ERP_CTS_PROT	= 1<<1,
   350		BSS_CHANGED_ERP_PREAMBLE	= 1<<2,
   351		BSS_CHANGED_ERP_SLOT		= 1<<3,
   352		BSS_CHANGED_HT			= 1<<4,
   353		BSS_CHANGED_BASIC_RATES		= 1<<5,
   354		BSS_CHANGED_BEACON_INT		= 1<<6,
   355		BSS_CHANGED_BSSID		= 1<<7,
   356		BSS_CHANGED_BEACON		= 1<<8,
   357		BSS_CHANGED_BEACON_ENABLED	= 1<<9,
   358		BSS_CHANGED_CQM			= 1<<10,
   359		BSS_CHANGED_IBSS		= 1<<11,
   360		BSS_CHANGED_ARP_FILTER		= 1<<12,
   361		BSS_CHANGED_QOS			= 1<<13,
   362		BSS_CHANGED_IDLE		= 1<<14,
   363		BSS_CHANGED_SSID		= 1<<15,
   364		BSS_CHANGED_AP_PROBE_RESP	= 1<<16,
   365		BSS_CHANGED_PS			= 1<<17,
   366		BSS_CHANGED_TXPOWER		= 1<<18,
   367		BSS_CHANGED_P2P_PS		= 1<<19,
   368		BSS_CHANGED_BEACON_INFO		= 1<<20,
   369		BSS_CHANGED_BANDWIDTH		= 1<<21,
   370		BSS_CHANGED_OCB                 = 1<<22,
   371		BSS_CHANGED_MU_GROUPS		= 1<<23,
   372		BSS_CHANGED_KEEP_ALIVE		= 1<<24,
   373		BSS_CHANGED_MCAST_RATE		= 1<<25,
   374		BSS_CHANGED_FTM_RESPONDER	= 1<<26,
   375		BSS_CHANGED_TWT			= 1<<27,
   376		BSS_CHANGED_HE_OBSS_PD		= 1<<28,
   377		BSS_CHANGED_HE_BSS_COLOR	= 1<<29,
   378		BSS_CHANGED_FILS_DISCOVERY      = 1<<30,
   379		BSS_CHANGED_UNSOL_BCAST_PROBE_RESP = 1<<31,
 > 380		BSS_CHANGED_TEMP_ADDR		= 1UL<<32,
   381	
   382		/* when adding here, make sure to change ieee80211_reconfig */
   383	};
   384
diff mbox series

Patch

diff --git a/include/net/mac80211.h b/include/net/mac80211.h
index 689da327ce2e..19e99f40f61c 100644
--- a/include/net/mac80211.h
+++ b/include/net/mac80211.h
@@ -340,6 +340,8 @@  struct ieee80211_vif_chanctx_switch {
  * @BSS_CHANGED_FILS_DISCOVERY: FILS discovery status changed.
  * @BSS_CHANGED_UNSOL_BCAST_PROBE_RESP: Unsolicited broadcast probe response
  *	status changed.
+ * @BSS_CHANGED_TEMP_ADDR: Temporary self address allowed for authentication and
+ *	deauthentication frames is changed.
  *
  */
 enum ieee80211_bss_change {
@@ -375,6 +377,7 @@  enum ieee80211_bss_change {
 	BSS_CHANGED_HE_BSS_COLOR	= 1<<29,
 	BSS_CHANGED_FILS_DISCOVERY      = 1<<30,
 	BSS_CHANGED_UNSOL_BCAST_PROBE_RESP = 1<<31,
+	BSS_CHANGED_TEMP_ADDR		= 1UL<<32,
 
 	/* when adding here, make sure to change ieee80211_reconfig */
 };
@@ -1771,6 +1774,14 @@  enum ieee80211_offload_flags {
  *	your driver/device needs to do.
  * @ap_addr: AP MLD address, or BSSID for non-MLO connections
  *	(station mode only)
+ * @temp_addr: Temporary self address allowed for the authentication and
+ *	deauthentication frames till the response waiting time offchannel period
+ *	complete. Driver should allow TX and RX of the frames with the temporary
+ *	address as TA and RA respectively when it is non zero. This will be set
+ *	to zero address when there is no temporary self address is active.
+ *	Change in the value of this will be indicated with
+ *	@BSS_CHANGED_TEMP_ADDR. This will be indicated only when driver supports
+ *	%NL80211_EXT_FEATURE_AUTH_AND_DEAUTH_RANDOM_TA.
  */
 struct ieee80211_vif_cfg {
 	/* association related data */
@@ -1786,6 +1797,7 @@  struct ieee80211_vif_cfg {
 	bool s1g;
 	bool idle;
 	u8 ap_addr[ETH_ALEN] __aligned(2);
+	u8 temp_addr[ETH_ALEN] __aligned(2);
 };
 
 /**
diff --git a/net/mac80211/main.c b/net/mac80211/main.c
index 846528850612..238cbf05d08d 100644
--- a/net/mac80211/main.c
+++ b/net/mac80211/main.c
@@ -205,7 +205,8 @@  int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
 				   BSS_CHANGED_PS |\
 				   BSS_CHANGED_IBSS |\
 				   BSS_CHANGED_ARP_FILTER |\
-				   BSS_CHANGED_SSID)
+				   BSS_CHANGED_SSID |\
+				   BSS_CHANGED_TEMP_ADDR)
 
 void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
 				      u64 changed)
diff --git a/net/mac80211/offchannel.c b/net/mac80211/offchannel.c
index d78c82d6b696..54233be31e9b 100644
--- a/net/mac80211/offchannel.c
+++ b/net/mac80211/offchannel.c
@@ -187,6 +187,12 @@  static void ieee80211_roc_notify_destroy(struct ieee80211_roc_work *roc)
 					 roc->mgmt_tx_cookie,
 					 roc->chan, GFP_KERNEL);
 
+	if (!is_zero_ether_addr(roc->sdata->vif.cfg.temp_addr)) {
+		eth_zero_addr(roc->sdata->vif.cfg.temp_addr);
+		ieee80211_vif_cfg_change_notify(roc->sdata,
+						BSS_CHANGED_TEMP_ADDR);
+	}
+
 	list_del(&roc->list);
 	kfree(roc);
 }
@@ -234,6 +240,36 @@  static bool ieee80211_recalc_sw_work(struct ieee80211_local *local,
 	return true;
 }
 
+static void ieee80211_config_temp_addr(struct ieee80211_sub_if_data *sdata,
+				       const struct ieee80211_hdr *hdr)
+{
+	unsigned int link;
+
+	if (!wiphy_ext_feature_isset(sdata->local->hw.wiphy,
+			NL80211_EXT_FEATURE_AUTH_AND_DEAUTH_RANDOM_TA))
+		return;
+
+	if (memcmp(sdata->vif.addr, hdr->addr2, ETH_ALEN) == 0 ||
+	    memcmp(sdata->vif.cfg.temp_addr, hdr->addr2, ETH_ALEN) == 0) {
+		return;
+	} else if (sdata->vif.valid_links) {
+		rcu_read_lock();
+		for (link = 0; link < ARRAY_SIZE(sdata->vif.link_conf); link++) {
+			struct ieee80211_bss_conf *link_conf;
+
+			link_conf = rcu_dereference(sdata->vif.link_conf[link]);
+			if (!link_conf)
+				continue;
+			if (memcmp(link_conf->addr, hdr->addr2, ETH_ALEN) == 0)
+				return;
+		}
+		rcu_read_unlock();
+	}
+
+	memcpy(sdata->vif.cfg.temp_addr, hdr->addr2, ETH_ALEN);
+	ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_TEMP_ADDR);
+}
+
 static void ieee80211_handle_roc_started(struct ieee80211_roc_work *roc,
 					 unsigned long start_time)
 {
@@ -245,6 +281,8 @@  static void ieee80211_handle_roc_started(struct ieee80211_roc_work *roc,
 
 	if (roc->mgmt_tx_cookie) {
 		if (!WARN_ON(!roc->frame)) {
+			ieee80211_config_temp_addr(roc->sdata,
+						   (void *) roc->frame->data);
 			ieee80211_tx_skb_tid_band(roc->sdata, roc->frame, 7,
 						  roc->chan->band);
 			roc->frame = NULL;
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index 7e3ab6e1b28f..a611697cecd0 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -4192,6 +4192,12 @@  static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx)
 	u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
 	bool multicast = is_multicast_ether_addr(hdr->addr1) ||
 			 ieee80211_is_s1g_beacon(hdr->frame_control);
+	bool skip_addr1_check = false;
+
+	if ((ieee80211_is_auth(hdr->frame_control) ||
+	     ieee80211_is_deauth(hdr->frame_control)) &&
+	    ether_addr_equal(sdata->vif.cfg.temp_addr, hdr->addr1))
+		skip_addr1_check = true;
 
 	switch (sdata->vif.type) {
 	case NL80211_IFTYPE_STATION:
@@ -4201,6 +4207,8 @@  static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx)
 			return false;
 		if (multicast)
 			return true;
+		if (skip_addr1_check)
+			return true;
 		return ieee80211_is_our_addr(sdata, hdr->addr1, &rx->link_id);
 	case NL80211_IFTYPE_ADHOC:
 		if (!bssid)
@@ -4213,7 +4221,7 @@  static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx)
 			return true;
 		if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid))
 			return false;
-		if (!multicast &&
+		if (!multicast && !skip_addr1_check &&
 		    !ether_addr_equal(sdata->vif.addr, hdr->addr1))
 			return false;
 		if (!rx->sta) {
@@ -4233,7 +4241,7 @@  static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx)
 			return false;
 		if (!is_broadcast_ether_addr(bssid))
 			return false;
-		if (!multicast &&
+		if (!multicast && !skip_addr1_check &&
 		    !ether_addr_equal(sdata->dev->dev_addr, hdr->addr1))
 			return false;
 		if (!rx->sta) {
@@ -4251,10 +4259,12 @@  static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx)
 			return false;
 		if (multicast)
 			return true;
+		if (skip_addr1_check)
+			return true;
 		return ether_addr_equal(sdata->vif.addr, hdr->addr1);
 	case NL80211_IFTYPE_AP_VLAN:
 	case NL80211_IFTYPE_AP:
-		if (!bssid)
+		if (!bssid && !skip_addr1_check)
 			return ieee80211_is_our_addr(sdata, hdr->addr1,
 						     &rx->link_id);
 
@@ -4266,7 +4276,7 @@  static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx)
 			 * and location updates. Note that mac80211
 			 * itself never looks at these frames.
 			 */
-			if (!multicast &&
+			if (!multicast && !skip_addr1_check &&
 			    !ieee80211_is_our_addr(sdata, hdr->addr1,
 						   &rx->link_id))
 				return false;
diff --git a/net/mac80211/util.c b/net/mac80211/util.c
index 6f5407038459..fd7e77938023 100644
--- a/net/mac80211/util.c
+++ b/net/mac80211/util.c
@@ -2663,7 +2663,7 @@  int ieee80211_reconfig(struct ieee80211_local *local)
 	/* Finally also reconfigure all the BSS information */
 	list_for_each_entry(sdata, &local->interfaces, list) {
 		unsigned int link_id;
-		u32 changed;
+		u64 changed;
 
 		if (!ieee80211_sdata_running(sdata))
 			continue;
@@ -2712,6 +2712,11 @@  int ieee80211_reconfig(struct ieee80211_local *local)
 			  BSS_CHANGED_TXPOWER |
 			  BSS_CHANGED_MCAST_RATE;
 
+		if (!is_zero_ether_addr(sdata->vif.cfg.temp_addr)) {
+			eth_zero_addr(sdata->vif.cfg.temp_addr);
+			changed |= BSS_CHANGED_TEMP_ADDR;
+		}
+
 		if (sdata->vif.bss_conf.mu_mimo_owner)
 			changed |= BSS_CHANGED_MU_GROUPS;