Skip to contentSkip to conversation

wifi: nl80211: reject ADD_LINK for an already valid link ID

PATCH New Xiang Mei 1 participant 1 message Nov 24

Subsystems (2)
lore
Share & tools
lore

Xiang Mei

author
#0 lore raw

PATCH 1/1 wifi: nl80211: reject ADD_LINK for an already valid link ID

nl80211_add_link() does not check whether the link ID is already in wdev->valid_links. Re-adding a live link overwrites its address behind mac80211's back, leaving two links with the same address. An AP_VLAN on that AP then fails to set up its links, and ieee80211_update_apvlan_links() dereferences the missing VLAN link:

  Oops: general protection fault, probably for non-canonical address ...
  KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007]
  RIP: 0010:ieee80211_link_vlan_copy_chanctx (net/mac80211/chan.c:2530)
  Call Trace:
   ieee80211_vif_update_links (net/mac80211/link.c:54 ...)
   ieee80211_vif_set_links (net/mac80211/link.c:473)
   nl80211_add_link (net/wireless/nl80211.c:19681)
   genl_family_rcv_msg_doit (net/netlink/genetlink.c:1114)
   genl_rcv_msg (net/netlink/genetlink.c:1194 net/netlink/genetlink.c:1209)
   netlink_rcv_skb (net/netlink/af_netlink.c:2585)
   genl_rcv (net/netlink/genetlink.c:1218)
   netlink_unicast (net/netlink/af_netlink.c:1362)
   netlink_sendmsg (net/netlink/af_netlink.c:1921)
   __sock_sendmsg (net/socket.c:800 net/socket.c:818)
   __sys_sendto (net/socket.c:2283)
   __x64_sys_sendto (net/socket.c:2290 net/socket.c:2286)
   do_syscall_64 (arch/x86/entry/syscall_64.c:89)
   entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121)
  Kernel panic - not syncing: Fatal exception

Reject adding a link that already exists.

Fixes 7b0a0e3c3a88 ("wifi: cfg80211: do some rework towards MLO link APIs")
Reported-by [email protected]
---
 net/wireless/nl80211.c | 3 +++
 1 file changed, 3 insertions(+)
net/wireless/nl80211.c +3 -0
index e7dd32880598..1059c4aa539f 100644
@@ -19670,6 +19670,9 @@ static int nl80211_add_link(struct sk_buff *skb, struct genl_info *info)
 		return -EINVAL;
 	}
 
+	if (wdev->valid_links & BIT(link_id))
+		return -EALREADY;
+
 	if (!info->attrs[NL80211_ATTR_MAC] ||
 	    !is_valid_ether_addr(nla_data(info->attrs[NL80211_ATTR_MAC])))
 		return -EINVAL;
Signature · 1 line
2.43.0