From patchwork Thu Jan 9 11:10:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lirongqing X-Patchwork-Id: 13932415 X-Patchwork-Delegate: kuba@kernel.org Received: from baidu.com (mx22.baidu.com [220.181.50.185]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA189215F55 for ; Thu, 9 Jan 2025 11:11:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.181.50.185 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736421114; cv=none; b=CkRolQ/+ImHx60IsH39acUc6lisbABogcLXaSLyJnl35IuopQrv/w9nZP9JhjOaUd20A3shMiIbv22E+8h48OgjGpujoJG7vechF5hiFZkz+uMLkRz/Vf3vniv5cPmEJenXnbmZa7GenqyIoUwTfDKKBEPuRS0eFJrUKnROvBLY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736421114; c=relaxed/simple; bh=p+8tuaA12qnzDxLXL3elomf6gRdwwAbsOoIxas4iErM=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=PT0zEG3YGaADXJDDy25PokXTF2KxRY8ww/2sQSUuqzUcAtAuhXV8HwGtzU9W/sHwj/8LC2X289u7CDwz2YcaQtu9UrwFO4t3w6hBhr3MJ9OE2SiyhzKpqTnH4A6UEyduwXaHS3pgxQbFySvztXn97sv4KVVHwUnPxaGftUWzQEY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=baidu.com; spf=pass smtp.mailfrom=baidu.com; arc=none smtp.client-ip=220.181.50.185 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=baidu.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baidu.com From: lirongqing To: , , , , , , , , , , , , , CC: Li RongQing Subject: [PATCH][net-next][v2] net: ethtool: Use hwprov under rcu_read_lock Date: Thu, 9 Jan 2025 19:10:57 +0800 Message-ID: <20250109111057.4746-1-lirongqing@baidu.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: BC-Mail-Ex14.internal.baidu.com (172.31.51.54) To BJHW-Mail-Ex15.internal.baidu.com (10.127.64.38) X-Baidu-BdMsfe-DateCheck: 1_BJHW-Mail-Ex15_2025-01-09 19:11:04:384 X-Baidu-BdMsfe-DateCheck: 1_BJHW-Mail-Ex15_2025-01-09 19:11:04:400 X-FEAS-Client-IP: 10.127.64.38 X-FE-Policy-ID: 52:10:53:SYSTEM X-Patchwork-Delegate: kuba@kernel.org From: Li RongQing hwprov should be protected by rcu_read_lock to prevent possible UAF Fixes: 4c61d809cf60 ("net: ethtool: Fix suspicious rcu_dereference usage") Signed-off-by: Li RongQing Acked-by: Kory Maincent diff with v1: move and use err varialbe, instead of define a new variable net/ethtool/common.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/net/ethtool/common.c b/net/ethtool/common.c index 2607aea..2bd77c9 100644 --- a/net/ethtool/common.c +++ b/net/ethtool/common.c @@ -869,6 +869,7 @@ int __ethtool_get_ts_info(struct net_device *dev, struct kernel_ethtool_ts_info *info) { struct hwtstamp_provider *hwprov; + int err = 0; rcu_read_lock(); hwprov = rcu_dereference(dev->hwprov); @@ -876,7 +877,6 @@ int __ethtool_get_ts_info(struct net_device *dev, if (!hwprov) { const struct ethtool_ops *ops = dev->ethtool_ops; struct phy_device *phydev = dev->phydev; - int err = 0; ethtool_init_tsinfo(info); if (phy_is_default_hwtstamp(phydev) && @@ -892,8 +892,9 @@ int __ethtool_get_ts_info(struct net_device *dev, return err; } + err = ethtool_get_ts_info_by_phc(dev, info, &hwprov->desc); rcu_read_unlock(); - return ethtool_get_ts_info_by_phc(dev, info, &hwprov->desc); + return err; } bool net_support_hwtstamp_qualifier(struct net_device *dev,