Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp689061pxb; Tue, 5 Apr 2022 18:53:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxB8WsmkO2n6R714r5fzZTYufZgZ+dphgzVmw2gHxP1oeYaGrcLaRN9YK1tGqh67Z3miDvk X-Received: by 2002:a17:903:22c9:b0:156:9c66:5cf4 with SMTP id y9-20020a17090322c900b001569c665cf4mr6285703plg.22.1649210001640; Tue, 05 Apr 2022 18:53:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649210001; cv=none; d=google.com; s=arc-20160816; b=zP/DCpETmvjMKmffj3CaN0YXwsKyi6Q0gCenzBtB69m8wZS50T3mbm6crjVQZ0jCUN 9L5RIN0WeIFQqcgeUK/oiyxOf5L2Wczd5j7OYDlDs4SOiv+f3A48S18KeMV2V8i/0NCp QK0j+vNJ4Y/4n0Ksiqwyw6Fosotj0WoiD9ZQnyh7a4xufrnyDI8nC2HD/nFy34O0cBwf AM1uJaIay1gcVPIhVyzF+6Mlhr4ctqW73QYax6ykA+4Fr32FAmKHPpgoYfEbL/kzXkJM jLkWsBrcaAXsA3c74DCJDXalD4IhyP3UIyeGmdz7w3hfPATQ6BlWMvv9T8IesnUbPJB2 Y4PQ== 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=Tm8bSbnpJrMS7byRjwOGc5BZgJWiuWqamdSNFBSQ++w=; b=KB6EroBjyK1si2+nCK+GMe37+3DHey5sv0VmHjTnpIFX8y84VpJyaRKQ0L0OUzj4Hy JI23dV89K5M8B+GdoNSwMD97ZhpHNZzkqLHQCn6NQiKa+XkkfxdTgHvtt7omdbGoJCsj lcq0Ck+Yg8Q3Z+xD7KaMSpYQwziYBfLFeMO1qHPj36GTedOJJg0hHLZvAfZ/j/G/7Mo+ BMs0m1SNFWGOzcxRCy9nCH+PlsK3Rzzprk+OfWi9XTPZHEHKi76KwNGPVmwTzZ9YbWdW IL03S8y78bQSyB+woLyourVdHwul6AlSW2IV5P0VMrw4TS6TED9NPW+XRD2NaqbIgVnB fF1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=v81NYQq1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bd11-20020a656e0b000000b00399621efa3csi2120547pgb.317.2022.04.05.18.53.06; Tue, 05 Apr 2022 18:53:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=v81NYQq1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S243965AbiDEJk4 (ORCPT + 99 others); Tue, 5 Apr 2022 05:40:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239330AbiDEIT6 (ORCPT ); Tue, 5 Apr 2022 04:19:58 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14CC385BEB; Tue, 5 Apr 2022 01:11:15 -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 B18EDB81B92; Tue, 5 Apr 2022 08:11:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1F66C385A1; Tue, 5 Apr 2022 08:11:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649146272; bh=DbvDUCjs6PJjOYcbBZnASjkLrK3/Xw+n/fw/88LNon8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v81NYQq11gaLjJZ7dJAAx9tWs1WI4wlYQdKqVlyhDtsJJ22YkFhDJV06GoTkehuWb PiLmZ4fC7Kn4Shxl5UQWiqcfbFAdVVtbRW+mjcHv7jqUOXmDnt1wijrRkNN5n/aMcl QJS7G/6ez8lGz9vMm95GHiooVnw/8CoSOT4uaBYI= 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.17 0703/1126] net: dsa: fix panic on shutdown if multi-chip tree failed to probe Date: Tue, 5 Apr 2022 09:24:10 +0200 Message-Id: <20220405070428.239374191@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070407.513532867@linuxfoundation.org> References: <20220405070407.513532867@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=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 88e2808019b4..a39bbed77f87 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -1722,6 +1722,10 @@ void dsa_switch_shutdown(struct dsa_switch *ds) struct dsa_port *dp; mutex_lock(&dsa2_mutex); + + if (!ds->setup) + goto out; + rtnl_lock(); dsa_switch_for_each_user_port(dp, ds) { @@ -1738,6 +1742,7 @@ void dsa_switch_shutdown(struct dsa_switch *ds) dp->master->dsa_ptr = NULL; rtnl_unlock(); +out: mutex_unlock(&dsa2_mutex); } EXPORT_SYMBOL_GPL(dsa_switch_shutdown); -- 2.34.1