Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3941369pxj; Mon, 21 Jun 2021 09:50:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyy8nVjNCqb/PoVpdb8VX2IywQi9q54J2hhJkCPpewUOo2mI5OyOf+iPO6tUq2u/cdi1RHa X-Received: by 2002:a92:b74b:: with SMTP id c11mr10767498ilm.246.1624294253799; Mon, 21 Jun 2021 09:50:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624294253; cv=none; d=google.com; s=arc-20160816; b=sEGAXe9FSn69SoNSIW4jGsBNCXkX3okufwKCDta6nN4KgQnCIcLI8Tt1mzDev0dNWt WT4oSHtd4sfJxaD6IfnNqY5wRVBZqfxle6K2sKpJpd/kwXmD1N83tk+yJYra8VwI+Elq 0dnAkeVcOOQxBS1nykPTJV5nHH81TV21axq/J5FB5+rHdE/oRw8AZ75cPzdSeDAyK2CE 2jQkgc5cW8Z27AybYfYTJZA/PcLr8Qcf5dxu3fDog9UHXd+Dkxhxrj6DKxnPDOMv5tuH zDjd01ixMnsjv5ilfjpopMqJkRPG+S/x2D8Tb8xhliktMBylg+GH3Z8F/wKzs4fq/raW cenA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=BQAFvXOeZLEgOos8T0BJMVzvWYtBdJQ6kxUlJLu4eiQ=; b=BZWCDtwK0AWwYYRT8Gpilxo/2ucLxDq9cQoEJnww34VMGeTWPVf/gTs32xbUGOYxbv FTZl+9H/6DPLCGeKJZjBER7pt+5pTNPd47Pq5gjfFG1HpMKWqxUhPAvtGLHxgubByNH1 Fi/gTOy46f37eO6YGt4JbUNYshMUW0UW4gi17F+m9lwp+nHmSkQP4bcxlkfKmSQQy5Y/ qXTkRIDtoLBDarYgGSi0sQBaQcNMMQS2JlqgLFGTJ8EDsXIInOIsGM/A7boeL7aDa/Ha RkMnHGfJBmNlsgy7fbMDcT1teJBmYwLBow0IAuXFm00rFxIuWw7g7oMO5mRvfBhne5vo oKOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mxtFyY+j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u18si12788212ilg.79.2021.06.21.09.50.41; Mon, 21 Jun 2021 09:50:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mxtFyY+j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233199AbhFUQw1 (ORCPT + 99 others); Mon, 21 Jun 2021 12:52:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:37576 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232760AbhFUQsB (ORCPT ); Mon, 21 Jun 2021 12:48:01 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F33F161361; Mon, 21 Jun 2021 16:34:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1624293243; bh=YXCuLwSz2ejN/KjrJmX7mM1K9SRerSB1sOYShyduPC0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mxtFyY+j82TfFF3v+JphOsIPUSys4u3NlxfOqu9Zj7MPJZPGqgi/qrPcoS7gBtwnE qdLDACWPN3CfP+U22j/Kdrz8kAtatPWkMzL2t3Wo6DlCHJ8sOGXX8YAP9FNDaODIn9 Bb4yJyNl0B0Tvkc4O4oIQFDqNmzB0AlMoFW8RiUU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+452ea4fbbef700ff0a56@syzkaller.appspotmail.com, Johannes Berg Subject: [PATCH 5.12 151/178] mac80211: fix deadlock in AP/VLAN handling Date: Mon, 21 Jun 2021 18:16:05 +0200 Message-Id: <20210621154927.904510289@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210621154921.212599475@linuxfoundation.org> References: <20210621154921.212599475@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Johannes Berg commit d5befb224edbe53056c2c18999d630dafb4a08b9 upstream. 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") Link: https://lore.kernel.org/r/20210517160322.9b8f356c0222.I392cb0e2fa5a1a94cf2e637555d702c7e512c1ff@changeid Signed-off-by: Johannes Berg Signed-off-by: Greg Kroah-Hartman --- net/mac80211/iface.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) --- a/net/mac80211/iface.c +++ b/net/mac80211/iface.c @@ -475,14 +475,7 @@ static void ieee80211_do_stop(struct iee 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 */ @@ -640,6 +633,15 @@ static int ieee80211_stop(struct net_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); @@ -1589,6 +1591,9 @@ static int ieee80211_runtime_change_ifty 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: