Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp964888pxb; Wed, 6 Apr 2022 05:29:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwkdYvMZPvbGz905mGtgVwNLsd2zCUU0A/xj2CaubPBd/UBS2X43XS9S3q+Jdgr6yLzbUmb X-Received: by 2002:a17:90b:1082:b0:1ca:aac5:5553 with SMTP id gj2-20020a17090b108200b001caaac55553mr9624514pjb.235.1649248196556; Wed, 06 Apr 2022 05:29:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649248196; cv=none; d=google.com; s=arc-20160816; b=RICIDV31YP5BgvdGo6cgO/uAPiPFd/j+ir1N9ivMnsDU9354nUjO4akYqww3CH6xQ2 Lxwg7I2gHCVWxcvu0mlu5eXk+gVyzmDhKPjX9OVaN2rAhvt8ukQ+yw/x+HIPfr1NNtpw 2snaQM1KURfdAcsoO2klkDAhQz7SmUnuh3R6yMk9APsZT0CbhyDreMmOvoxtWWPmqQFZ EGLiV/O1gHrv8LasFMoDYizthH/1ooG5Gv5y9ygHW340m3wtuXaonGsIIkolc/4J8kEZ Ke3OAC7tdOlPwmM4PXhI//qxFp7H44VTxLVZEL9ZwRu5T2NVH/vTDWlG03UdPkmGm5IB TJwA== 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=j9yVx2h2fB3W9e+Lfi3B4r3e7wtVNhaVNKZSEzhUxj8=; b=NgwPrLzjTiqM6gVa96k7uhhhOUqvyTled7zL8f+cwFUoupWTY+W+QqAfIQNqyxJAep ZTPBmYhalAO+CHNwp/ZcAqq5p3JWPejD2jPk5Mm0zI0u7CrP9jVBEjO/a6IkvUQZAbOj Or2c1ScRuOULHPvAiIZU0ZJIa/EzxX1HYsU05eIhs6s2zoVrAPDUrIMlkn7NLf+4wF4p Iq04B3AJTXp3DJJV1ZRUrkNRCxEpe3VnsI1RgKbO2RJQSgFLoyD/uGnZ0eZz3EWZDj02 yFulKs4m7Wkkt1hKm6UDhEokrMmtIz7Z8kgD2YzNZ4nc6Vs6q3/a7nvFq2SzY1AzaeuS dR2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CAuNJTQl; 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 x35-20020a631723000000b0039ca75905dasi1664923pgl.424.2022.04.06.05.29.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 05:29:56 -0700 (PDT) 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=CAuNJTQl; 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 035644AFB4E; Wed, 6 Apr 2022 02:04:33 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1838903AbiDFA5U (ORCPT + 99 others); Tue, 5 Apr 2022 20:57:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349372AbiDEJtp (ORCPT ); Tue, 5 Apr 2022 05:49:45 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5663C13EBF; Tue, 5 Apr 2022 02:44:33 -0700 (PDT) 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 ams.source.kernel.org (Postfix) with ESMTPS id 0C9DFB818F3; Tue, 5 Apr 2022 09:44:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7425DC385A2; Tue, 5 Apr 2022 09:44:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649151870; bh=4fbjqP+vp1WmsSfJDDK7G6+EtjHfQPVD0fOpK2cWyjo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CAuNJTQl4iAzSB1xfWWI6PZvAxH7jR16O/W/WLJN9hHjq/TK1J3O1/pY0kHxXOQ/4 x78gJD2AxH0Lwqrni3ePr+LhWkK3bSaFoPug95U4sqhTSR9h37bvpb3+k6PEP+EKQg gsiZ32yZC0Q2jRvuowuB4/AFuSjR9/gu8XrsRXYw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vladimir Oltean , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.15 570/913] net: dsa: fix panic on shutdown if multi-chip tree failed to probe Date: Tue, 5 Apr 2022 09:27:12 +0200 Message-Id: <20220405070356.930457121@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@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: Vladimir Oltean [ Upstream commit 8fd36358ce82382519b50b05f437493e1e00c4a9 ] DSA probing is atypical because a tree of devices must probe all at once, so out of N switches which call dsa_tree_setup_routing_table() during probe, for (N - 1) of them, "complete" will return false and they will exit probing early. The Nth switch will set up the whole tree on their behalf. The implication is that for (N - 1) switches, the driver binds to the device successfully, without doing anything. When the driver is bound, the ->shutdown() method may run. But if the Nth switch has failed to initialize the tree, there is nothing to do for the (N - 1) driver instances, since the slave devices have not been created, etc. Moreover, dsa_switch_shutdown() expects that the calling @ds has been in fact initialized, so it jumps at dereferencing the various data structures, which is incorrect. Avoid the ensuing NULL pointer dereferences by simply checking whether the Nth switch has previously set "ds->setup = true" for the switch which is currently shutting down. The entire setup is serialized under dsa2_mutex which we already hold. Fixes: 0650bf52b31f ("net: dsa: be compatible with masters which unregister on shutdown") Signed-off-by: Vladimir Oltean Link: https://lore.kernel.org/r/20220318195443.275026-1-vladimir.oltean@nxp.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/dsa/dsa2.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c index e7fa8ce41a4c..64a56db3de58 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -1631,6 +1631,10 @@ void dsa_switch_shutdown(struct dsa_switch *ds) struct dsa_port *dp; mutex_lock(&dsa2_mutex); + + if (!ds->setup) + goto out; + rtnl_lock(); list_for_each_entry(dp, &ds->dst->ports, list) { @@ -1665,6 +1669,7 @@ void dsa_switch_shutdown(struct dsa_switch *ds) unregister_netdevice_many(&unregister_list); rtnl_unlock(); +out: mutex_unlock(&dsa2_mutex); } EXPORT_SYMBOL_GPL(dsa_switch_shutdown); -- 2.34.1