* [PATCH net 0/4] net-sysfs: check device is present when showing paths
@ 2024-07-24 1:46 Jamie Bainbridge
2024-07-24 1:46 ` [PATCH net 1/4] net-sysfs: check device is present when showing carrier Jamie Bainbridge
` (3 more replies)
0 siblings, 4 replies; 10+ messages in thread
From: Jamie Bainbridge @ 2024-07-24 1:46 UTC (permalink / raw)
To: netdev, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni
Cc: Jamie Bainbridge
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 carrier, duplex, testing, and dormant paths.
Submitting as separate patches to make Fixes reporting accurate.
Signed-off-by: Jamie Bainbridge <jamie.bainbridge@gmail.com>
Jamie Bainbridge (4):
net-sysfs: check device is present when showing carrier
net-sysfs: check device is present when showing duplex
net-sysfs: check device is present when showing testing
net-sysfs: check device is present when showing dormant
net/core/net-sysfs.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
--
2.39.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH net 1/4] net-sysfs: check device is present when showing carrier
2024-07-24 1:46 [PATCH net 0/4] net-sysfs: check device is present when showing paths Jamie Bainbridge
@ 2024-07-24 1:46 ` Jamie Bainbridge
2024-07-24 9:35 ` Johannes Berg
2024-07-25 2:22 ` Shigeru Yoshida
2024-07-24 1:46 ` [PATCH net 2/4] net-sysfs: check device is present when showing duplex Jamie Bainbridge
` (2 subsequent siblings)
3 siblings, 2 replies; 10+ messages in thread
From: Jamie Bainbridge @ 2024-07-24 1:46 UTC (permalink / raw)
To: netdev, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni
Cc: Jamie Bainbridge, Johannes Berg, Jiri Pirko, linux-kernel
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 carrier_show.
Fixes: facd15dfd691 ("net: core: synchronize link-watch when carrier is queried")
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 0e2084ce7b7572bff458ed7e02358d9258c74628..7fabe5afa3012ecad6551e12f478b755952933b8 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -206,7 +206,7 @@ static ssize_t carrier_show(struct device *dev,
if (!rtnl_trylock())
return restart_syscall();
- if (netif_running(netdev)) {
+ if (netif_running(netdev) && netif_device_present(netdev)) {
/* Synchronize carrier state with link watch,
* see also rtnl_getlink().
*/
--
2.39.2
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH net 2/4] net-sysfs: check device is present when showing duplex
2024-07-24 1:46 [PATCH net 0/4] net-sysfs: check device is present when showing paths Jamie Bainbridge
2024-07-24 1:46 ` [PATCH net 1/4] net-sysfs: check device is present when showing carrier Jamie Bainbridge
@ 2024-07-24 1:46 ` Jamie Bainbridge
2024-07-24 1:46 ` [PATCH net 3/4] net-sysfs: check device is present when showing testing Jamie Bainbridge
2024-07-24 1:46 ` [PATCH net 4/4] net-sysfs: check device is present when showing dormant Jamie Bainbridge
3 siblings, 0 replies; 10+ messages in thread
From: Jamie Bainbridge @ 2024-07-24 1:46 UTC (permalink / raw)
To: netdev, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni
Cc: Jamie Bainbridge, David Decotigny, linux-kernel
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 duplex_show.
Fixes: 8ae6daca85c8 ("ethtool: Call ethtool's get/set_settings callbacks with cleaned data")
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 7fabe5afa3012ecad6551e12f478b755952933b8..3a539a2bd4d11c5f5d7b6f15a23d61439f178c3b 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -261,7 +261,7 @@ static ssize_t duplex_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.39.2
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH net 3/4] net-sysfs: check device is present when showing testing
2024-07-24 1:46 [PATCH net 0/4] net-sysfs: check device is present when showing paths Jamie Bainbridge
2024-07-24 1:46 ` [PATCH net 1/4] net-sysfs: check device is present when showing carrier Jamie Bainbridge
2024-07-24 1:46 ` [PATCH net 2/4] net-sysfs: check device is present when showing duplex Jamie Bainbridge
@ 2024-07-24 1:46 ` Jamie Bainbridge
2024-07-24 10:35 ` Andrew Lunn
2024-07-24 1:46 ` [PATCH net 4/4] net-sysfs: check device is present when showing dormant Jamie Bainbridge
3 siblings, 1 reply; 10+ messages in thread
From: Jamie Bainbridge @ 2024-07-24 1:46 UTC (permalink / raw)
To: netdev, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni
Cc: Jamie Bainbridge, Andrew Lunn, Florian Fainelli, linux-kernel
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))
return sysfs_emit(buf, fmt_dec, !!netif_testing(netdev));
return -EINVAL;
--
2.39.2
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH net 4/4] net-sysfs: check device is present when showing dormant
2024-07-24 1:46 [PATCH net 0/4] net-sysfs: check device is present when showing paths Jamie Bainbridge
` (2 preceding siblings ...)
2024-07-24 1:46 ` [PATCH net 3/4] net-sysfs: check device is present when showing testing Jamie Bainbridge
@ 2024-07-24 1:46 ` Jamie Bainbridge
3 siblings, 0 replies; 10+ messages in thread
From: Jamie Bainbridge @ 2024-07-24 1:46 UTC (permalink / raw)
To: netdev, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni
Cc: Jamie Bainbridge, Stefan Rompf, linux-kernel
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 dormant_show.
Fixes: b00055aacdb1 ("[NET] core: add RFC2863 operstate")
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 17927832a4fbb56d3e1dfbed29c567d70ab944be..ff2a1f6ef7e18be56c2de51902519066431e47a8 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -303,7 +303,7 @@ static ssize_t dormant_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_dormant(netdev));
return -EINVAL;
--
2.39.2
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH net 1/4] net-sysfs: check device is present when showing carrier
2024-07-24 1:46 ` [PATCH net 1/4] net-sysfs: check device is present when showing carrier Jamie Bainbridge
@ 2024-07-24 9:35 ` Johannes Berg
2024-07-24 9:41 ` Johannes Berg
2024-07-25 2:22 ` Shigeru Yoshida
1 sibling, 1 reply; 10+ messages in thread
From: Johannes Berg @ 2024-07-24 9:35 UTC (permalink / raw)
To: Jamie Bainbridge, netdev@vger.kernel.org, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Jiri Pirko, linux-kernel@vger.kernel.org
On Wed, 2024-07-24 at 01:46 +0000, Jamie Bainbridge wrote:
> A sysfs reader can race with a device reset or removal.
Kind of, yes, but please check what the race actually is.
> 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 carrier_show.
You didn't say why it's needed here, so ... why is it?
FWIW, I don't think it actually _is_ needed, since the netdev struct
itself is still around, linkwatch_sync_dev() will not do anything that's
not still needed anyway (the removal from list must clearly either still
happen or nothing happens in the function). This will not call into the
driver (which would be the problematic part).
So while I don't think this is _wrong_ per se, I also don't think it's
necessary, nor are you demonstrating that it is.
And for userspace it should be pretty much immaterial whether it gets a
real value or -EINVAL in the race, or -ENOENT because the file
disappeared anyway?
johannes
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net 1/4] net-sysfs: check device is present when showing carrier
2024-07-24 9:35 ` Johannes Berg
@ 2024-07-24 9:41 ` Johannes Berg
2024-07-24 22:54 ` Jamie Bainbridge
0 siblings, 1 reply; 10+ messages in thread
From: Johannes Berg @ 2024-07-24 9:41 UTC (permalink / raw)
To: Jamie Bainbridge, netdev@vger.kernel.org, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Jiri Pirko, linux-kernel@vger.kernel.org
On Wed, 2024-07-24 at 11:35 +0200, Johannes Berg wrote:
> On Wed, 2024-07-24 at 01:46 +0000, Jamie Bainbridge wrote:
> > A sysfs reader can race with a device reset or removal.
>
> Kind of, yes, but please check what the race actually is.
>
> > 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 carrier_show.
>
> You didn't say why it's needed here, so ... why is it?
>
> FWIW, I don't think it actually _is_ needed, since the netdev struct
> itself is still around, linkwatch_sync_dev() will not do anything that's
> not still needed anyway (the removal from list must clearly either still
> happen or nothing happens in the function). This will not call into the
> driver (which would be the problematic part).
>
> So while I don't think this is _wrong_ per se, I also don't think it's
> necessary, nor are you demonstrating that it is.
>
> And for userspace it should be pretty much immaterial whether it gets a
> real value or -EINVAL in the race, or -ENOENT because the file
> disappeared anyway?
>
All of which, btw, is also true for patches 3 and 4 in this set.
For patch 2 it seems applicable.
I do wonder if ethtool itself, at least ethtool netlink, doesn't have a
similar problem though, since it just uses netdev_get_by_name() /
netdev_get_by_index()?
johannes
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net 3/4] net-sysfs: check device is present when showing testing
2024-07-24 1:46 ` [PATCH net 3/4] net-sysfs: check device is present when showing testing Jamie Bainbridge
@ 2024-07-24 10:35 ` Andrew Lunn
0 siblings, 0 replies; 10+ messages in thread
From: Andrew Lunn @ 2024-07-24 10:35 UTC (permalink / raw)
To: Jamie Bainbridge
Cc: netdev, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Florian Fainelli, linux-kernel
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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net 1/4] net-sysfs: check device is present when showing carrier
2024-07-24 9:41 ` Johannes Berg
@ 2024-07-24 22:54 ` Jamie Bainbridge
0 siblings, 0 replies; 10+ messages in thread
From: Jamie Bainbridge @ 2024-07-24 22:54 UTC (permalink / raw)
To: Johannes Berg
Cc: netdev@vger.kernel.org, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Jiri Pirko,
linux-kernel@vger.kernel.org
On Wed, 24 Jul 2024 at 19:42, Johannes Berg <johannes@sipsolutions.net> wrote:
>
> On Wed, 2024-07-24 at 11:35 +0200, Johannes Berg wrote:
> > On Wed, 2024-07-24 at 01:46 +0000, Jamie Bainbridge wrote:
> > > A sysfs reader can race with a device reset or removal.
> >
> > Kind of, yes, but please check what the race actually is.
> >
> > > 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 carrier_show.
> >
> > You didn't say why it's needed here, so ... why is it?
> >
> > FWIW, I don't think it actually _is_ needed, since the netdev struct
> > itself is still around, linkwatch_sync_dev() will not do anything that's
> > not still needed anyway (the removal from list must clearly either still
> > happen or nothing happens in the function). This will not call into the
> > driver (which would be the problematic part).
> >
> > So while I don't think this is _wrong_ per se, I also don't think it's
> > necessary, nor are you demonstrating that it is.
> >
> > And for userspace it should be pretty much immaterial whether it gets a
> > real value or -EINVAL in the race, or -ENOENT because the file
> > disappeared anyway?
> >
>
> All of which, btw, is also true for patches 3 and 4 in this set.
>
> For patch 2 it seems applicable.
>
> I do wonder if ethtool itself, at least ethtool netlink, doesn't have a
> similar problem though, since it just uses netdev_get_by_name() /
> netdev_get_by_index()?
>
> johannes
You are correct, patch 2 (duplex) is the one where we panicked during
device reset. I thought to fix the other "show" functions in advance
while I was there.
I will revise this and re-submit with only the necessary patch.
Thanks for the review, it is appreciated.
Jamie
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net 1/4] net-sysfs: check device is present when showing carrier
2024-07-24 1:46 ` [PATCH net 1/4] net-sysfs: check device is present when showing carrier Jamie Bainbridge
2024-07-24 9:35 ` Johannes Berg
@ 2024-07-25 2:22 ` Shigeru Yoshida
1 sibling, 0 replies; 10+ messages in thread
From: Shigeru Yoshida @ 2024-07-25 2:22 UTC (permalink / raw)
To: jamie.bainbridge
Cc: netdev, davem, edumazet, kuba, pabeni, johannes.berg, jiri,
linux-kernel
Hi Jamie,
On Wed, 24 Jul 2024 11:46:50 +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 carrier_show.
>
> Fixes: facd15dfd691 ("net: core: synchronize link-watch when carrier is queried")
>
> Signed-off-by: Jamie Bainbridge <jamie.bainbridge@gmail.com>
nit: When resubmitting your fix, there is no need for a blank line
between the Fixes and SOB tags.
Thanks,
Shigeru
> ---
> 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 0e2084ce7b7572bff458ed7e02358d9258c74628..7fabe5afa3012ecad6551e12f478b755952933b8 100644
> --- a/net/core/net-sysfs.c
> +++ b/net/core/net-sysfs.c
> @@ -206,7 +206,7 @@ static ssize_t carrier_show(struct device *dev,
> if (!rtnl_trylock())
> return restart_syscall();
>
> - if (netif_running(netdev)) {
> + if (netif_running(netdev) && netif_device_present(netdev)) {
> /* Synchronize carrier state with link watch,
> * see also rtnl_getlink().
> */
> --
> 2.39.2
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2024-07-25 2:22 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-24 1:46 [PATCH net 0/4] net-sysfs: check device is present when showing paths Jamie Bainbridge
2024-07-24 1:46 ` [PATCH net 1/4] net-sysfs: check device is present when showing carrier Jamie Bainbridge
2024-07-24 9:35 ` Johannes Berg
2024-07-24 9:41 ` Johannes Berg
2024-07-24 22:54 ` Jamie Bainbridge
2024-07-25 2:22 ` Shigeru Yoshida
2024-07-24 1:46 ` [PATCH net 2/4] net-sysfs: check device is present when showing duplex Jamie Bainbridge
2024-07-24 1:46 ` [PATCH net 3/4] net-sysfs: check device is present when showing testing Jamie Bainbridge
2024-07-24 10:35 ` Andrew Lunn
2024-07-24 1:46 ` [PATCH net 4/4] net-sysfs: check device is present when showing dormant Jamie Bainbridge
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).