Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2679608pxj; Mon, 17 May 2021 07:22:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytdGN2OpTt8HlguaBmoAi1XU9U+EMlR0Bw8e2UAOgs7QsWePc1makrew5aSTmDp8NUzNl+ X-Received: by 2002:a17:906:2ed0:: with SMTP id s16mr126647eji.543.1621261324603; Mon, 17 May 2021 07:22:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621261324; cv=none; d=google.com; s=arc-20160816; b=ibbhXUZFLqhLH5XcParld1oShQ7VaoGjjm6mEnwPzMxFBOsMPd09AY2aw0OlzMT9Nu W1LZKWq++MxTD+Or399eHsumbZXYb6wAjNCj2CZNFcjsd0DpPC/X44KwdjyIKp8m3qxb msWXuCHlG4zKGOtQ9pOqMwH13br6c3qRC7/DPttoDEetoxXwpFte4hzlcM07lv76Dn1r rR6B6hqmqPPt3Y9OoRFs3xBYd2htWieIolW5lBsiw3HaUTcFbf1cg8/yr584bA0Rz2sn 6JyzAGpGkWX9Hga5PxISwUVszkvs4Tc1RY4gb20rN2mJzmKfMplGouralbgUUV8NrEM+ zpIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=PbYcM5fcLU6SF1HvpJwW0T7gC1t8IOwAgYrqkPiydL0=; b=ezoSOoJw0ChUu5rQeLlF+V52RIn7XEC2VRUsLItMC7m/q58OFfThhOxz1Xx27WvDWB GrpTNLe1qVAIWLQ0J9f2SS7Qeub9tHWd8vnGdH4yETFYl8PDkmKwjQVkRL6CygY6Ei1f PYhuMNSD2H4F27HLqJNOtrtM5oVVwZiLCDxcjDqHLxRv2MXcP/NPptXwtb+C5wjIC4RC PSiguBtVKqkvqnyNBIYbs1ytzNQRo/OODdjjh7dP9dImbp+gSnOnIn4XkVVA9LJdApc7 nTJJbaAnnedEXnb5t6pDSVGJfQITsPgv9s7UbRSuMoG47nZUcZ/16WMfW1Vy8qF8Eiyj HiYA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o18si2772751edt.176.2021.05.17.07.21.40; Mon, 17 May 2021 07:22:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237733AbhEQOFB (ORCPT + 99 others); Mon, 17 May 2021 10:05:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237696AbhEQOEy (ORCPT ); Mon, 17 May 2021 10:04:54 -0400 Received: from sipsolutions.net (s3.sipsolutions.net [IPv6:2a01:4f8:191:4433::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9E6AC06138D; Mon, 17 May 2021 07:03:32 -0700 (PDT) Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.94.2) (envelope-from ) id 1lidqA-00AMO0-Ln; Mon, 17 May 2021 16:03:26 +0200 From: Johannes Berg To: linux-wireless@vger.kernel.org Cc: Johannes Berg , stable@vger.kernel.org, syzbot+452ea4fbbef700ff0a56@syzkaller.appspotmail.com Subject: [PATCH] mac80211: fix deadlock in AP/VLAN handling Date: Mon, 17 May 2021 16:03:23 +0200 Message-Id: <20210517160322.9b8f356c0222.I392cb0e2fa5a1a94cf2e637555d702c7e512c1ff@changeid> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Johannes Berg Syzbot reports that when you have AP_VLAN interfaces that are up and close the AP interface they belong to, we get a deadlock. No surprise - since we dev_close() them with the wiphy mutex held, which goes back into the netdev notifier in cfg80211 and tries to acquire the wiphy mutex there. To fix this, we need to do two things: 1) prevent changing iftype while AP_VLANs are up, we can't easily fix this case since cfg80211 already calls us with the wiphy mutex held, but change_interface() is relatively rare in drivers anyway, so changing iftype isn't used much (and userspace has to fall back to down/change/up anyway) 2) pull the dev_close() loop over VLANs out of the wiphy mutex section in the normal stop case Cc: stable@vger.kernel.org Reported-by: syzbot+452ea4fbbef700ff0a56@syzkaller.appspotmail.com Fixes: a05829a7222e ("cfg80211: avoid holding the RTNL when calling the driver") Signed-off-by: Johannes Berg --- net/mac80211/iface.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c index 2e2f73a4aa73..137fa4c50e07 100644 --- a/net/mac80211/iface.c +++ b/net/mac80211/iface.c @@ -476,14 +476,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata, bool going_do GFP_KERNEL); } - /* APs need special treatment */ if (sdata->vif.type == NL80211_IFTYPE_AP) { - struct ieee80211_sub_if_data *vlan, *tmpsdata; - - /* down all dependent devices, that is VLANs */ - list_for_each_entry_safe(vlan, tmpsdata, &sdata->u.ap.vlans, - u.vlan.list) - dev_close(vlan->dev); WARN_ON(!list_empty(&sdata->u.ap.vlans)); } else if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) { /* remove all packets in parent bc_buf pointing to this dev */ @@ -641,6 +634,15 @@ static int ieee80211_stop(struct net_device *dev) { struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); + /* close all dependent VLAN interfaces before locking wiphy */ + if (sdata->vif.type == NL80211_IFTYPE_AP) { + struct ieee80211_sub_if_data *vlan, *tmpsdata; + + list_for_each_entry_safe(vlan, tmpsdata, &sdata->u.ap.vlans, + u.vlan.list) + dev_close(vlan->dev); + } + wiphy_lock(sdata->local->hw.wiphy); ieee80211_do_stop(sdata, true); wiphy_unlock(sdata->local->hw.wiphy); @@ -1591,6 +1593,9 @@ static int ieee80211_runtime_change_iftype(struct ieee80211_sub_if_data *sdata, switch (sdata->vif.type) { case NL80211_IFTYPE_AP: + if (!list_empty(&sdata->u.ap.vlans)) + return -EBUSY; + break; case NL80211_IFTYPE_STATION: case NL80211_IFTYPE_ADHOC: case NL80211_IFTYPE_OCB: -- 2.31.1