Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4425670pxb; Mon, 21 Feb 2022 21:13:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJyzJFWhV2dj6Qnoa7IXSVdhZ1HbaP4eezaZlQKIztTaFTescq4OgjKjnlTJw0MnNxR8CH7Y X-Received: by 2002:a63:70b:0:b0:373:9e98:d8f9 with SMTP id 11-20020a63070b000000b003739e98d8f9mr18294103pgh.242.1645506829609; Mon, 21 Feb 2022 21:13:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645506829; cv=none; d=google.com; s=arc-20160816; b=LaXw7u+DszRsL6up/okG3FZyOuJFLe6NsgcKrmnmPOoshRW7qtgodCc88/lafK8meW GoEy5rJTzRZiPDnoaYpLw8obOGdKhfKCdS+//yMfnDjD6SFqwCXLMhF11ubdC81jhI9v O/2yV7QTIsWRkgF2PX6XPSuBuKUBtXnB+MJAUs8KT5P9tbE2Ltmps7V+QvmjMaju8gi4 E/Bv3DDGGRu3JIFlJssqpUJOqRfVQKv+Ok1hz/Wownzdhjisdg/xChv6t8iXEgprpxLG AFhGsqx/+VNRXQcwwFz/rGL30KNalzCYwO7S4PfTVRKZqwy9qF8GUCQNQEzX0NQXSv8X EguQ== 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=F0tD+r8no47GBF1UjE2IOQPoRFi6G9d1bQL522ayuR0=; b=i1npy6ZRPAWjTuvifgQbTq6V+6rdyEAmvzj30R5gq1Yh2jfWSwLwEKYWSBD0m3bo5r A9GcCnjM4CaxO8DdEaCndlJ+h8Mjw+GIISqzqIfJm7Tf8F2uBZvknfCctnRv1cy9yPmz MBB97huqG0cE84iogbcwJw3pmzxJEzcu2W5bdr4Kv7Rl3AoO/SXBMky4nK+hhgstBndB E7XNkuGAuMfHYIVM3AvNMxC/33Kaftxf/l/nkZ+TrN75JxRdQW5sD8rtKReT3kN0ebQv ETsB0UcXFPWfiPRlon5ShgQLL+rjSbCatoS4dNJvZ1uJqzrakpI13ZVsuNnYUsPJ4uO4 56Yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MVgLvreS; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id x13si22893646pge.418.2022.02.21.21.13.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 21:13:49 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MVgLvreS; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3D78FE02D9; Mon, 21 Feb 2022 20:46:15 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352696AbiBUJ40 (ORCPT + 99 others); Mon, 21 Feb 2022 04:56:26 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:41672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352919AbiBUJsC (ORCPT ); Mon, 21 Feb 2022 04:48:02 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 260C419C02; Mon, 21 Feb 2022 01:21:27 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 9538ACE0E89; Mon, 21 Feb 2022 09:21:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7622CC340E9; Mon, 21 Feb 2022 09:21:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1645435284; bh=lIrrySYVtcncVdCuEiZ4YiYeeNz35RMRuhzq2z1xfFE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MVgLvreSF++hSu3wdPZT9TpuVkBItMnVMUFsoxi1zwG3QCL8CojULlv4p/O5+OOJS TAR/eTpFeSzcwaVNJCKNfCwe2Bn0pdIe0OTtiSPRx1hQv7bfsGVLue/sPw+tHKHOB6 IQq6lzGx65Pr6nTIU59CIGvZbs1LoBB0Dpd+e0kU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= , Johannes Berg Subject: [PATCH 5.16 108/227] cfg80211: fix race in netlink owner interface destruction Date: Mon, 21 Feb 2022 09:48:47 +0100 Message-Id: <20220221084938.458981899@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220221084934.836145070@linuxfoundation.org> References: <20220221084934.836145070@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Johannes Berg commit f0a6fd1527067da537e9c48390237488719948ed upstream. My previous fix here to fix the deadlock left a race where the exact same deadlock (see the original commit referenced below) can still happen if cfg80211_destroy_ifaces() already runs while nl80211_netlink_notify() is still marking some interfaces as nl_owner_dead. The race happens because we have two loops here - first we dev_close() all the netdevs, and then we destroy them. If we also have two netdevs (first one need only be a wdev though) then we can find one during the first iteration, close it, and go to the second iteration -- but then find two, and try to destroy also the one we didn't close yet. Fix this by only iterating once. Reported-by: Toke Høiland-Jørgensen Fixes: ea6b2098dd02 ("cfg80211: fix locking in netlink owner interface destruction") Tested-by: Toke Høiland-Jørgensen Link: https://lore.kernel.org/r/20220201130951.22093-1-johannes@sipsolutions.net Signed-off-by: Johannes Berg Signed-off-by: Greg Kroah-Hartman --- net/wireless/core.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) --- a/net/wireless/core.c +++ b/net/wireless/core.c @@ -5,7 +5,7 @@ * Copyright 2006-2010 Johannes Berg * Copyright 2013-2014 Intel Mobile Communications GmbH * Copyright 2015-2017 Intel Deutschland GmbH - * Copyright (C) 2018-2021 Intel Corporation + * Copyright (C) 2018-2022 Intel Corporation */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt @@ -332,29 +332,20 @@ static void cfg80211_event_work(struct w void cfg80211_destroy_ifaces(struct cfg80211_registered_device *rdev) { struct wireless_dev *wdev, *tmp; - bool found = false; ASSERT_RTNL(); - list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { + list_for_each_entry_safe(wdev, tmp, &rdev->wiphy.wdev_list, list) { if (wdev->nl_owner_dead) { if (wdev->netdev) dev_close(wdev->netdev); - found = true; - } - } - - if (!found) - return; - wiphy_lock(&rdev->wiphy); - list_for_each_entry_safe(wdev, tmp, &rdev->wiphy.wdev_list, list) { - if (wdev->nl_owner_dead) { + wiphy_lock(&rdev->wiphy); cfg80211_leave(rdev, wdev); rdev_del_virtual_intf(rdev, wdev); + wiphy_unlock(&rdev->wiphy); } } - wiphy_unlock(&rdev->wiphy); } static void cfg80211_destroy_iface_wk(struct work_struct *work)