Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3183563pxp; Mon, 14 Mar 2022 12:46:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWLcnCDjOxoSyFVMeiuYSIVpMDVa20uVE7rnyjeH+r55NU9oHk2TzljwMoNjBEMMFbzCTn X-Received: by 2002:a62:8f83:0:b0:4f1:68e4:c561 with SMTP id n125-20020a628f83000000b004f168e4c561mr25716040pfd.67.1647287168026; Mon, 14 Mar 2022 12:46:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647287168; cv=none; d=google.com; s=arc-20160816; b=hiouGiKp+KYSjFfnJNdwVlYrZipq1ISRRi3YE3v5fWKtHR786RegaKEE7Vn15MoErB BEfWG49a3C3BUKnYf9lS+2xgWBxUXrMF/KJdc3TfBzfJ4TliJu1DbONm75fhPciBw2H9 WD7XGL7K3DyCEQvcRDINjKj4buhX/NHuQaUF6eB1N1h48DbeinCHCfRTfL1nwqODfJfR HOq5MWRQAWR3a+LZUdG+ikcppgN9Z4zoLMIa/Yzp83PmxUcal0hqCffQc2Pyo78EWGqo P6jTzcCQ25zMz6S62BYPHwXHTBwndOZdXwLDRY6IvgUvPMGxYKga83pv3Wvch2Fu00Rf re6g== 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=EO75NlUbpB3uFFOCw00mNyMeTQe5yjCrF3EcrxGU3dw=; b=fnyxGMMr9ztExc3lzGWlJBYviogX/eBDYHqvPHzIdH06P2fOaJjwm5aQxw4GWXTzHr DRmRq6AKwBUChqztPHObjM8WXNHasfUAq4CaiJozfNrkdSYmSJkgL6IkrvXtulekZl9S HYJh483yO0wHaD08KcCRAXIfm0r9aZZhnxfOoJUqbM8dXSGy3oZ7BGPx3Gr1YFRUzVZw Fy9y9oMfmMIUX1neb5GVoctyMMk7AOb6PbXXwm2dDROBXTdJuXBXbqLR/896y0bu/2p0 JDh9xF43wPaiAk/T1wL/nTH2eSsdrGB7BG2QbICZ5qZZ/abcxLv0e1qhADp1mU/2WDqI tRww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2dLiZtRh; 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 l10-20020a170902f68a00b0015385ad7fb3si2238898plg.521.2022.03.14.12.45.54; Mon, 14 Mar 2022 12:46:08 -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=2dLiZtRh; 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 S240105AbiCNL7v (ORCPT + 99 others); Mon, 14 Mar 2022 07:59:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239884AbiCNL5p (ORCPT ); Mon, 14 Mar 2022 07:57:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 971E313F52; Mon, 14 Mar 2022 04:56: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 dfw.source.kernel.org (Postfix) with ESMTPS id 36D306112C; Mon, 14 Mar 2022 11:56:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9BCCC340F4; Mon, 14 Mar 2022 11:56:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1647258992; bh=LifRiThbtJzMmdTf0+XH3zzZRhAM1u0Nj2cU5JFV2dY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2dLiZtRhPThIiQKZML8MJjlzD0bMOR6jGDB9wVeBL6E9BqqRh1ntSER+JysNUWv/T 1qgKUNA5T5vgJswhL7j4FCAghwQgHsV86EXPZvTtdNK+w3FqTLtYpEf/2oH/bebQnN JoGSrkrGO3la4m64SvLr7snTIdzCmR6SqWIgq+6c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, suresh kumar , "David S. Miller" , Sasha Levin Subject: [PATCH 5.4 22/43] net-sysfs: add check for netdevice being present to speed_show Date: Mon, 14 Mar 2022 12:53:33 +0100 Message-Id: <20220314112735.040356766@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220314112734.415677317@linuxfoundation.org> References: <20220314112734.415677317@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=-8.6 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: suresh kumar [ Upstream commit 4224cfd7fb6523f7a9d1c8bb91bb5df1e38eb624 ] When bringing down the netdevice or system shutdown, a panic can be triggered while accessing the sysfs path because the device is already removed. [ 755.549084] mlx5_core 0000:12:00.1: Shutdown was called [ 756.404455] mlx5_core 0000:12:00.0: Shutdown was called ... [ 757.937260] BUG: unable to handle kernel NULL pointer dereference at (null) [ 758.031397] IP: [] dma_pool_alloc+0x1ab/0x280 crash> bt ... PID: 12649 TASK: ffff8924108f2100 CPU: 1 COMMAND: "amsd" ... #9 [ffff89240e1a38b0] page_fault at ffffffff8f38c778 [exception RIP: dma_pool_alloc+0x1ab] RIP: ffffffff8ee11acb RSP: ffff89240e1a3968 RFLAGS: 00010046 RAX: 0000000000000246 RBX: ffff89243d874100 RCX: 0000000000001000 RDX: 0000000000000000 RSI: 0000000000000246 RDI: ffff89243d874090 RBP: ffff89240e1a39c0 R8: 000000000001f080 R9: ffff8905ffc03c00 R10: ffffffffc04680d4 R11: ffffffff8edde9fd R12: 00000000000080d0 R13: ffff89243d874090 R14: ffff89243d874080 R15: 0000000000000000 ORIG_RAX: ffffffffffffffff CS: 0010 SS: 0018 #10 [ffff89240e1a39c8] mlx5_alloc_cmd_msg at ffffffffc04680f3 [mlx5_core] #11 [ffff89240e1a3a18] cmd_exec at ffffffffc046ad62 [mlx5_core] #12 [ffff89240e1a3ab8] mlx5_cmd_exec at ffffffffc046b4fb [mlx5_core] #13 [ffff89240e1a3ae8] mlx5_core_access_reg at ffffffffc0475434 [mlx5_core] #14 [ffff89240e1a3b40] mlx5e_get_fec_caps at ffffffffc04a7348 [mlx5_core] #15 [ffff89240e1a3bb0] get_fec_supported_advertised at ffffffffc04992bf [mlx5_core] #16 [ffff89240e1a3c08] mlx5e_get_link_ksettings at ffffffffc049ab36 [mlx5_core] #17 [ffff89240e1a3ce8] __ethtool_get_link_ksettings at ffffffff8f25db46 #18 [ffff89240e1a3d48] speed_show at ffffffff8f277208 #19 [ffff89240e1a3dd8] dev_attr_show at ffffffff8f0b70e3 #20 [ffff89240e1a3df8] sysfs_kf_seq_show at ffffffff8eedbedf #21 [ffff89240e1a3e18] kernfs_seq_show at ffffffff8eeda596 #22 [ffff89240e1a3e28] seq_read at ffffffff8ee76d10 #23 [ffff89240e1a3e98] kernfs_fop_read at ffffffff8eedaef5 #24 [ffff89240e1a3ed8] vfs_read at ffffffff8ee4e3ff #25 [ffff89240e1a3f08] sys_read at ffffffff8ee4f27f #26 [ffff89240e1a3f50] system_call_fastpath at ffffffff8f395f92 crash> net_device.state ffff89443b0c0000 state = 0x5 (__LINK_STATE_START| __LINK_STATE_NOCARRIER) To prevent this scenario, we also make sure that the netdevice is present. Signed-off-by: suresh kumar Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/core/net-sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index bcad7028bbf4..ad45f13a0370 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -212,7 +212,7 @@ static ssize_t speed_show(struct device *dev, if (!rtnl_trylock()) return restart_syscall(); - if (netif_running(netdev)) { + if (netif_running(netdev) && netif_device_present(netdev)) { struct ethtool_link_ksettings cmd; if (!__ethtool_get_link_ksettings(netdev, &cmd)) -- 2.34.1