Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp4238225pxp; Tue, 15 Mar 2022 16:07:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwS/lnW8/HtuVfaiG+SQQfRtp4z0KjhUL6vd5g63zYGEzoLbX1EFPjxhDzyt3v+EDRo+5TD X-Received: by 2002:a17:902:a50c:b0:14d:4e8b:d6f with SMTP id s12-20020a170902a50c00b0014d4e8b0d6fmr30480748plq.42.1647385620710; Tue, 15 Mar 2022 16:07:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647385620; cv=none; d=google.com; s=arc-20160816; b=XdaZ0MwDg6JbfV03s4cZmJyZXdcxrwpowjf1KByaWu4vmWhFBj/Ny9DrNrZAPBHTda Nqd/MyB2diSH5JxFnXDkxeYCeP+9WAo89vakS4qAbO4pTZOE/5V/eFjYj1Li1ZFt7ttn 0dGSfc410LxJWDBbcMyLPRdqxB281gy3vt+tffVbLPu52H5Ni/M0lcCZx69M1Zv3vYzl LDUJ/Y+w7ckS8hoyjAWgSND8cX/cs8r1z7XJuoZZvABTJMdjLEj5lCY7kWYPSFxa/IZj UFN0KllQmK77qTrkriLWNONNFzMKE5v2n/UevF4k4I2l2vIOT5/ofSUIJpXBCRmZol3i 1vaQ== 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=aIRWX7ehaYT4kSRLICZAMDLJ+qJJ7Ocmdg8BywDWUPw=; b=OatStlYRW4nyL7MDYiJDzXqJGDI2aj6BXu7xJ37t/48Fn7uRy8NZPq+HgATE6qTie+ GkgdSELZ0ghqgfoRj+IYWp1ojTgp0q68jsw2U8OKba72uZa9tkQUm4uFRV+/OLZXiWeU m9eOKR5TsnflcMboIZx09WpEapLVs5Xq2toHXN8SD2BC/Urszjfn8huJ20NIdJkWYaIy iye4e/X4QaHh4lscZn/Sr48bXlnXas9BI6g3Fv/DQmJllvr0wyZVDNkttcxThQcMCbMO ETPvQ5wF0I1wmd2WD+iMNTKxpQHAxCcFgZNj4Bg2jNEJafet0qlEIXXam+7vvsjg824E ZjkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DPPgU9Hg; 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 t190-20020a6381c7000000b003813c1df412si419457pgd.572.2022.03.15.16.06.47; Tue, 15 Mar 2022 16:07:00 -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=DPPgU9Hg; 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 S245029AbiCNMcm (ORCPT + 99 others); Mon, 14 Mar 2022 08:32:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243928AbiCNMVY (ORCPT ); Mon, 14 Mar 2022 08:21:24 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A7CD13CE4; Mon, 14 Mar 2022 05:18:37 -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 E024FB80DF4; Mon, 14 Mar 2022 12:18:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4518FC340E9; Mon, 14 Mar 2022 12:18:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1647260314; bh=Mqf59jWgVyICVi1MOdIXW8LT3afhn1KB7de9lEOHhq4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DPPgU9HgfYMsQQo8goeLKvlkmNzwKe5AJtrkMXsbxfh5FROg0IeXtWtrjxNCtXVGd qvAT7QVv6uPhMSBroR731fguPPRn3OIypWmwH5HW5+6Xp2ymbZEH5sVrP0Jv8Thx/X VpSUrc5zFlSOjUFkfOCLd68/jqzNaZpsdGWQZTBQ= 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.16 072/121] net-sysfs: add check for netdevice being present to speed_show Date: Mon, 14 Mar 2022 12:54:15 +0100 Message-Id: <20220314112746.132053856@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220314112744.120491875@linuxfoundation.org> References: <20220314112744.120491875@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 d7f9ee830d34..9e5657f63245 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -213,7 +213,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