diff mbox series

[net,3/4] net-sysfs: check device is present when showing testing

Message ID 2a96f450e4150e9b8c39fb000d82c17987c5bbc5.1721784184.git.jamie.bainbridge@gmail.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net-sysfs: check device is present when showing paths | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 273 this patch: 273
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 281 this patch: 281
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes fail Problems with Fixes tag: 1
netdev/build_allmodconfig_warn success Errors and warnings before: 281 this patch: 281
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-07-25--00-00 (tests: 703)

Commit Message

Jamie Bainbridge July 24, 2024, 1:46 a.m. UTC
A sysfs reader can race with a device reset or removal.

This was fixed for speed_show with commit 4224cfd7fb65 ("net-sysfs: add
check for netdevice being present to speed_show") so add the same check
to testing_show.

Fixes: db30a57779b1 ("net: Add testing sysfs attribute")

Signed-off-by: Jamie Bainbridge <jamie.bainbridge@gmail.com>
---
 net/core/net-sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Andrew Lunn July 24, 2024, 10:35 a.m. UTC | #1
On Wed, Jul 24, 2024 at 11:46:52AM +1000, Jamie Bainbridge wrote:
> A sysfs reader can race with a device reset or removal.
> 
> This was fixed for speed_show with commit 4224cfd7fb65 ("net-sysfs: add
> check for netdevice being present to speed_show") so add the same check
> to testing_show.
> 
> Fixes: db30a57779b1 ("net: Add testing sysfs attribute")
> 
> Signed-off-by: Jamie Bainbridge <jamie.bainbridge@gmail.com>
> ---
>  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 3a539a2bd4d11c5f5d7b6f15a23d61439f178c3b..17927832a4fbb56d3e1dfbed29c567d70ab944be 100644
> --- a/net/core/net-sysfs.c
> +++ b/net/core/net-sysfs.c
> @@ -291,7 +291,7 @@ static ssize_t testing_show(struct device *dev,
>  {
>  	struct net_device *netdev = to_net_dev(dev);
>  
> -	if (netif_running(netdev))
> +	if (netif_running(netdev) && netif_device_present(netdev))

Maybe a dumb observation, but how can it be running if it is not
present?

And if we are not holding any locks, it might be gone by the time you
call netif_testing()?

>  		return sysfs_emit(buf, fmt_dec, !!netif_testing(netdev));

	Andrew
diff mbox series

Patch

diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 3a539a2bd4d11c5f5d7b6f15a23d61439f178c3b..17927832a4fbb56d3e1dfbed29c567d70ab944be 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -291,7 +291,7 @@  static ssize_t testing_show(struct device *dev,
 {
 	struct net_device *netdev = to_net_dev(dev);
 
-	if (netif_running(netdev))
+	if (netif_running(netdev) && netif_device_present(netdev))
 		return sysfs_emit(buf, fmt_dec, !!netif_testing(netdev));
 
 	return -EINVAL;