ethtool: ioctl: improve error checking for set_wol
Subsystems (3)
PATCH 1/1 ethtool: ioctl: improve error checking for set_wol
The netlink version of set_wol checks for not supported wolopts and avoids setting wol when the correct wolopt is already set. If we do the same with the ioctl version then we can remove these checks from the driver layer.
--- net/ethtool/ioctl.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
net/ethtool/ioctl.c +12 -2
@@ -1436,15 +1436,25 @@ static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)static int ethtool_set_wol (struct net_device *dev,char __user *useraddr) { -struct ethtool_wolinfo wol; +struct ethtool_wolinfo wol, cur_wol;int ret; -if (!dev->ethtool_ops->set_wol) +if (!dev->ethtool_ops->get_wol || !dev->ethtool_ops->set_wol)return -EOPNOTSUPP ; +memset (&cur_wol,0 ,sizeof (struct ethtool_wolinfo )); + cur_wol.cmd =ETHTOOL_GWOL ; + dev->ethtool_ops->get_wol (dev, &cur_wol); +if (copy_from_user (&wol, useraddr,sizeof (wol)))return -EFAULT ; +if (wol.wolopts & ~cur_wol.supported) +return -EOPNOTSUPP ; + +if (wol.wolopts == cur_wol.wolopts) +return 0 ; + ret = dev->ethtool_ops->set_wol (dev, &wol);if (ret)return ret;
Signature · 1 line
2.7.4
+ Daniil Tatianin <[email protected]>, Andrew Lunn <[email protected]> as per ./scripts/get_maintainer.pl --git-min-percent 25 net/ethtool/ioctl.c
Quoted 3 lines · Justin Chen
The netlink version of
set_wolchecks for not supported wolopts and avoids setting wol when the correct wolopt is already set. If we do the same with the ioctl version then we can remove these checks from the driver layer.
Hi Justin,
Are you planning follow-up patches for the driver layer?
Quoted 10 lines
Signed-off-by Justin Chen <[email protected]>--- net/ethtool/ioctl.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)net/ethtool/ioctl.c +0
-0
net/ethtool/ioctl.c static int ethtool_get_wol(struct net_device *dev, char __user *useraddr) · line 1443
Quoted 10 lines
net/ethtool/ioctl.c +2
-2@@ -1436,15 +1436,25 @@ static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)static int ethtool_set_wol (struct net_device *dev,char __user *useraddr) { -struct ethtool_wolinfo wol; +struct ethtool_wolinfo wol, cur_wol;int ret; -if (!dev->ethtool_ops->set_wol) +if (!dev->ethtool_ops->get_wol || !dev->ethtool_ops->set_wol)return -EOPNOTSUPP ;
Are there cases where (in-tree) drivers provide set_wol byt not get_wol? If so, does this break their set_wol support?
Quoted 17 lines
net/ethtool/ioctl.c +10
-0+memset (&cur_wol,0 ,sizeof (struct ethtool_wolinfo )); + cur_wol.cmd =ETHTOOL_GWOL ; + dev->ethtool_ops->get_wol (dev, &cur_wol); +if (copy_from_user (&wol, useraddr,sizeof (wol)))return -EFAULT ; +if (wol.wolopts & ~cur_wol.supported) +return -EOPNOTSUPP ; + +if (wol.wolopts == cur_wol.wolopts) +return 0 ; + ret = dev->ethtool_ops->set_wol (dev, &wol);if (ret)return ret;
Jakub Kicinski
maintainerQuoted 2 lines · On Thu, 1 Jun 2023 17:55:21 +0200 Simon Horman wrote:
+ Daniil Tatianin <[email protected]>, Andrew Lunn <[email protected]> as per
./scripts/get_maintainer.pl--git-min-percent 25net/ethtool/ioctl.c
Sorry to chime in but always prefer running get_maintainer on the patch rather than a file path. File path misses stuff like Fixes tags. If it was up to me that option would have been removed :(
Quoted 7 lines · Jakub Kicinski
Quoted 2 lines · On Thu, 1 Jun 2023 17:55:21 +0200 Simon Horman wrote:
+ Daniil Tatianin <[email protected]>, Andrew Lunn <[email protected]> as per
./scripts/get_maintainer.pl--git-min-percent 25net/ethtool/ioctl.cSorry to chime in but always prefer running
get_maintaineron the patch rather than a file path. File path misses stuff like Fixes tags. If it was up to me that option would have been removed :(
Apologies, Will do next time.
Justin
Quoted 6 lines · Jakub Kicinski
Quoted 2 lines · On Thu, 1 Jun 2023 17:55:21 +0200 Simon Horman wrote:
+ Daniil Tatianin <[email protected]>, Andrew Lunn <[email protected]> as per
./scripts/get_maintainer.pl--git-min-percent 25net/ethtool/ioctl.cSorry to chime in but always prefer running
get_maintaineron the patch rather than a file path. File path misses stuff like Fixes tags. If it was up to me that option would have been removed :(
Yes, sorry about that.
Quoted 12 lines · Simon Horman
+ Daniil Tatianin <[email protected]>, Andrew Lunn <[email protected]> as per
./scripts/get_maintainer.pl--git-min-percent 25net/ethtool/ioctl.cQuoted 3 lines · Justin Chen
The netlink version of
set_wolchecks for not supported wolopts and avoids setting wol when the correct wolopt is already set. If we do the same with the ioctl version then we can remove these checks from the driver layer.Hi Justin,
Are you planning follow-up patches for the driver layer?
I was planning to for the Broadcom drivers since those I can test. But I could do it across the board if that is preferred.
Quoted 17 lines
Quoted 17 lines
Signed-off-by Justin Chen <[email protected]>--- net/ethtool/ioctl.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)net/ethtool/ioctl.c +1
-1@@ -1436,15 +1436,25 @@ static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)static int ethtool_set_wol (struct net_device *dev,char __user *useraddr) { -struct ethtool_wolinfo wol; +struct ethtool_wolinfo wol, cur_wol;int ret;
Quoted 7 lines
net/ethtool/ioctl.c static int ethtool_get_wol(struct net_device *dev, char __user *useraddr) · line 1443
Quoted 3 lines
net/ethtool/ioctl.c +1
-1-if (!dev->ethtool_ops->set_wol) +if (!dev->ethtool_ops->get_wol || !dev->ethtool_ops->set_wol)return -EOPNOTSUPP ;Are there cases where (in-tree) drivers provide
set_wolbyt notget_wol? If so, does this break theirset_wolsupport?
My original thought was to match netlink set wol behavior. So drivers that do that won't work with netlink set_wol right now. I'll skim around to see if any drivers do this. But I would reckon this should be a driver fix.
Thanks,
Justin
Quoted 17 lines
Quoted 17 lines
net/ethtool/ioctl.c +10
-0+memset (&cur_wol,0 ,sizeof (struct ethtool_wolinfo )); + cur_wol.cmd =ETHTOOL_GWOL ; + dev->ethtool_ops->get_wol (dev, &cur_wol); +if (copy_from_user (&wol, useraddr,sizeof (wol)))return -EFAULT ; +if (wol.wolopts & ~cur_wol.supported) +return -EOPNOTSUPP ; + +if (wol.wolopts == cur_wol.wolopts) +return 0 ; + ret = dev->ethtool_ops->set_wol (dev, &wol);if (ret)return ret;
Quoted 43 lines · Justin Chen
Quoted 4 lines · Simon Horman
+ Daniil Tatianin <[email protected]>, Andrew Lunn <[email protected]>
as per./scripts/get_maintainer.pl--git-min-percent 25net/ethtool/ioctl.cQuoted 9 lines
Quoted 3 lines · Justin Chen
The netlink version of
set_wolchecks for not supported wolopts and avoids setting wol when the correct wolopt is already set. If we do the same with the ioctl version then we can remove these checks from the driver layer.Hi Justin,
Are you planning follow-up patches for the driver layer?
I was planning to for the Broadcom drivers since those I can test. But I could do it across the board if that is preferred.
Quoted 14 lines
Quoted 14 lines
Signed-off-by Justin Chen <[email protected]>---
net/ethtool/ioctl.c| 14 ++++++++++++--1 file changed, 12 insertions(+), 2 deletions(-)net/ethtool/ioctl.c +0
-1@@ -1436,15 +1436,25 @@ static int ethtool_get_wol(struct net_device *dev, char __user *useraddr) static int ethtool_set_wol(struct net_device *dev, char __user *useraddr) { - struct ethtool_wolinfo wol;Quoted 9 lines
net/ethtool/ioctl.c static int ethtool_get_wol(struct net_device *dev, char __user *useraddr) · line 1443
Quoted 5 lines
net/ethtool/ioctl.c +2
-1+ struct ethtool_wolinfo wol, cur_wol; int ret; - if (!dev->ethtool_ops->set_wol) + if (!dev->ethtool_ops->get_wol || !dev->ethtool_ops->set_wol) return -EOPNOTSUPP;Are there cases where (in-tree) drivers provide
set_wolbyt notget_wol? If so, does this break theirset_wolsupport?
Quoted 5 lines
My original thought was to match netlink set wol behavior. So drivers that do that won't work with netlink
set_wolright now. I'll skim around to see if any drivers do this. But I would reckon this should be a driver fix.Thanks,
Justin
I see a driver at drivers/net/phy/microchip.c. But this is a phy driver set_wol hook.
Justin
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
net/ethtool/ioctl.c +10
-0+ memset(&cur_wol, 0, sizeof(struct ethtool_wolinfo)); + cur_wol.cmd = ETHTOOL_GWOL; + dev->ethtool_ops->get_wol(dev, &cur_wol); + if (copy_from_user(&wol, useraddr, sizeof(wol))) return -EFAULT; + if (wol.wolopts & ~cur_wol.supported) + return -EOPNOTSUPP; + + if (wol.wolopts == cur_wol.wolopts) + return 0; + ret = dev->ethtool_ops->set_wol(dev, &wol); if (ret) return ret;
Quoted 46 lines · Justin Chen
Quoted 43 lines · Justin Chen
Quoted 4 lines · Simon Horman
+ Daniil Tatianin <[email protected]>, Andrew Lunn <[email protected]>
as per./scripts/get_maintainer.pl--git-min-percent 25net/ethtool/ioctl.cQuoted 9 lines
Quoted 3 lines · Justin Chen
The netlink version of
set_wolchecks for not supported wolopts and avoids setting wol when the correct wolopt is already set. If we do the same with the ioctl version then we can remove these checks from the driver layer.Hi Justin,
Are you planning follow-up patches for the driver layer?
I was planning to for the Broadcom drivers since those I can test. But I could do it across the board if that is preferred.
Quoted 23 lines
Quoted 10 lines
Signed-off-by Justin Chen <[email protected]>---
net/ethtool/ioctl.c| 14 ++++++++++++--1 file changed, 12 insertions(+), 2 deletions(-)net/ethtool/ioctl.c +0
-0net/ethtool/ioctl.c static int ethtool_get_wol(struct net_device · line 1442
Quoted 9 lines
net/ethtool/ioctl.c +2
-2@@ -1436,15 +1436,25 @@ static int ethtool_get_wol(struct net_device *dev, char __user *useraddr) static int ethtool_set_wol(struct net_device *dev, char __user *useraddr) { - struct ethtool_wolinfo wol; + struct ethtool_wolinfo wol, cur_wol; int ret; - if (!dev->ethtool_ops->set_wol) + if (!dev->ethtool_ops->get_wol || !dev->ethtool_ops->set_wol) return -EOPNOTSUPP;Are there cases where (in-tree) drivers provide
set_wolbyt notget_wol? If so, does this break theirset_wolsupport?
Quoted 7 lines
Quoted 5 lines
My original thought was to match netlink set wol behavior. So drivers that do that won't work with netlink
set_wolright now. I'll skim around to see if any drivers do this. But I would reckon this should be a driver fix.Thanks,
JustinI see a driver at
drivers/net/phy/microchip.c. But this is a phy driverset_wolhook.
That part of the driver appears to be dead code. It attempts to pretend to support Wake-on-LAN, but it does not do any specific programming of wake-up filters, nor does it implement get_wol. It also does not make use of the recently introduced PHY_ALWAYS_CALL_SUSPEND flag.
When it is time to determine whether to suspend the PHY or not, eventually phy_suspend() will call phy_ethtool_get_wol(). Since no get_wol is implemented, the wol.wolopts will remain zero, therefore we will just suspend the PHY.
I suspect this was added to work around MAC drivers that may forcefully try to suspend the PHY, but that should not even be possible these days.
I would just remove that logic from microchip.c entirely.
Signature · 1 line
Florian
Andrew Lunn
maintainerQuoted 50 lines
Quoted 33 lines
Quoted 33 lines
I was planning to for the Broadcom drivers since those I can test. But I could do it across the board if that is preferred.
Quoted 15 lines
Quoted 15 lines
Signed-off-by Justin Chen <[email protected]>---
net/ethtool/ioctl.c| 14 ++++++++++++--1 file changed, 12 insertions(+), 2 deletions(-)net/ethtool/ioctl.c +0
-0@@ -1436,15 +1436,25 @@ static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)static int
ethtool_set_wol(struct net_device *dev, char __user *useraddr)
{
- structethtool_wolinfowol;Quoted 9 lines
Quoted 5 lines
+ struct
ethtool_wolinfowol,cur_wol;
int ret;
- if (!dev->ethtool_ops->set_wol)
+ if (!dev->ethtool_ops->get_wol || !dev->ethtool_ops->set_wol) return-EOPNOTSUPP;Are there cases where (in-tree) drivers provide
set_wolbyt notget_wol? If so, does this break theirset_wolsupport?My original thought was to match netlink set wol behavior. So drivers that do that won't work with netlink
set_wolright now. I'll skim around to see if any drivers do this. But I would reckon this should be a driver fix.Quoted 6 lines
Quoted 3 lines
Thanks,
JustinI see a driver at
drivers/net/phy/microchip.c. But this is a phy driverset_wolhook.That part of the driver appears to be dead code. It attempts to pretend to support Wake-on-LAN, but it does not do any specific programming of wake-up filters, nor does it implement
get_wol. It also does not make use of the recently introducedPHY_ALWAYS_CALL_SUSPENDflag.When it is time to determine whether to suspend the PHY or not, eventually
phy_suspend()will callphy_ethtool_get_wol(). Since noget_wolis implemented, the wol.wolopts will remain zero, therefore we will just suspend the PHY.
Quoted 4 lines
I suspect this was added to work around MAC drivers that may forcefully try to suspend the PHY, but that should not even be possible these days.
I would just remove that logic from
microchip.centirely.
The Microchip developers are reasonably responsive. So we should Cc:
them.
Andrew
+ Woojung, UNGLinuxDriver
Quoted 59 lines · Andrew Lunn
Quoted 50 lines
Quoted 33 lines
Quoted 33 lines
I was planning to for the Broadcom drivers since those I can test. But I could do it across the board if that is preferred.
Quoted 15 lines
Quoted 15 lines
Signed-off-by Justin Chen <[email protected]>--- net/ethtool/ioctl.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)net/ethtool/ioctl.c +0
-1@@ -1436,15 +1436,25 @@ static int ethtool_get_wol(struct net_device *dev, char __user *useraddr) static int ethtool_set_wol(struct net_device *dev, char__user *useraddr) { - struct ethtool_wolinfo wol;Quoted 9 lines
net/ethtool/ioctl.c static int ethtool_get_wol(struct net_device *dev, char __user *useraddr) · line 1443
Quoted 5 lines
net/ethtool/ioctl.c +2
-1+ struct ethtool_wolinfo wol, cur_wol; int ret; - if (!dev->ethtool_ops->set_wol) + if (!dev->ethtool_ops->get_wol || !dev->ethtool_ops->set_wol) return -EOPNOTSUPP;Are there cases where (in-tree) drivers provide
set_wolbyt notget_wol? If so, does this break theirset_wolsupport?My original thought was to match netlink set wol behavior. So drivers that do that won't work with netlink
set_wolright now. I'll skim around to see if any drivers do this. But I would reckon this should be a driver fix.Quoted 6 lines
Quoted 3 lines
Thanks,
JustinI see a driver at
drivers/net/phy/microchip.c. But this is a phy driverset_wolhook.That part of the driver appears to be dead code. It attempts to pretend to support Wake-on-LAN, but it does not do any specific programming of wake-up filters, nor does it implement
get_wol. It also does not make use of the recently introducedPHY_ALWAYS_CALL_SUSPENDflag.When it is time to determine whether to suspend the PHY or not, eventually
phy_suspend()will callphy_ethtool_get_wol(). Since noget_wolis implemented, the wol.wolopts will remain zero, therefore we will just suspend the PHY.Quoted 4 lines
I suspect this was added to work around MAC drivers that may forcefully try to suspend the PHY, but that should not even be possible these days.
I would just remove that logic from
microchip.centirely.The Microchip developers are reasonably responsive. So we should Cc:
them.Andrew
Quoted 48 lines · Andrew Lunn
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
I was planning to for the Broadcom drivers since those I can test. But I could do it across the board if that is preferred.
Quoted 14 lines
Quoted 14 lines
Signed-off-by Justin Chen <[email protected]>--- net/ethtool/ioctl.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)net/ethtool/ioctl.c +0
-0@@ -1436,15 +1436,25 @@ static int ethtool_get_wol(struct net_device *dev, char __user *useraddr) static int ethtool_set_wol(struct net_device *dev, char__user *useraddr) {Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
net/ethtool/ioctl.c static int ethtool_get_wol(struct · line 1443
Quoted 6 lines
net/ethtool/ioctl.c +2
-2- struct ethtool_wolinfo wol; + struct ethtool_wolinfo wol, cur_wol; int ret; - if (!dev->ethtool_ops->set_wol) + if (!dev->ethtool_ops->get_wol || !dev->ethtool_ops->set_wol) return -EOPNOTSUPP;Are there cases where (in-tree) drivers provide
set_wolbyt not
get_wol?Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 2 lines
If so, does this break their
set_wolsupport?My original thought was to match netlink set wol behavior. So drivers that do that won't work with netlink
set_wolright now. I'll skim around to see if any drivers do this. But I would reckon this should be a driver fix.Thanks,
JustinQuoted 5 lines
Quoted 5 lines
Quoted 2 lines
I see a driver at
drivers/net/phy/microchip.c. But this is a phy driverset_wolhook.That part of the driver appears to be dead code. It attempts to pretend to support Wake-on-LAN, but it does not do any specific programming of
wake-up
Quoted 3 lines
Quoted 3 lines
filters, nor does it implement
get_wol. It also does not make use of the recently introducedPHY_ALWAYS_CALL_SUSPENDflag.
Quoted 14 lines
Quoted 1 line
Quoted 1 line
When it is time to determine whether to suspend the PHY or not,
eventually
Quoted 5 lines
Quoted 5 lines
phy_suspend()will callphy_ethtool_get_wol(). Since noget_wolis implemented, the wol.wolopts will remain zero, therefore we will just suspend the PHY.I suspect this was added to work around MAC drivers that may forcefully
try
Quoted 6 lines
Quoted 3 lines
to suspend the PHY, but that should not even be possible these days.
I would just remove that logic from
microchip.centirely.The Microchip developers are reasonably responsive. So we should Cc:
them.
set_wol in drivers/net/phy/microchip.c is used to set the flag to avoid PHY power down at suspend time.
Looks it is old-fashioned now because frame work is not calling suspend after calling get_wol. We will make a patch for it.
BTW, this patch is checking MAC driver set_wol and get_wol.
So I don't think it breaks drivers/net/phy/microchip.c suspend operation anyway.
Thanks.
Woojung
Simon Horman
Reviewed-byQuoted 11 lines · Justin Chen
Quoted 8 lines · Simon Horman
+ Daniil Tatianin <[email protected]>, Andrew Lunn <[email protected]> as per
./scripts/get_maintainer.pl--git-min-percent 25net/ethtool/ioctl.cQuoted 3 lines · Justin Chen
The netlink version of
set_wolchecks for not supported wolopts and avoids setting wol when the correct wolopt is already set. If we do the same with the ioctl version then we can remove these checks from the driver layer.
Quoted 7 lines
Quoted 4 lines
Hi Justin,
Are you planning follow-up patches for the driver layer?
I was planning to for the Broadcom drivers since those I can test. But I could do it across the board if that is preferred.
I think that would be my suggestion.
But I'm unsure of the magnitude of change involved. Or how risky it is in terms of introducing regressions. In any case, perhaps it's best to start small.
Quoted 23 lines
Quoted 5 lines
Quoted 5 lines
Signed-off-by Justin Chen <[email protected]>--- net/ethtool/ioctl.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)Quoted 17 lines
net/ethtool/ioctl.c static int ethtool_get_wol(struct net_device *dev, char __user *useraddr) · line 1441
Quoted 13 lines
net/ethtool/ioctl.c +2
-2@@ -1436,15 +1436,25 @@ static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)static int ethtool_set_wol (struct net_device *dev,char __user *useraddr) { -struct ethtool_wolinfo wol; +struct ethtool_wolinfo wol, cur_wol;int ret; -if (!dev->ethtool_ops->set_wol) +if (!dev->ethtool_ops->get_wol || !dev->ethtool_ops->set_wol)return -EOPNOTSUPP ;Are there cases where (in-tree) drivers provide
set_wolbyt notget_wol? If so, does this break theirset_wolsupport?
Quoted 3 lines
My original thought was to match netlink set wol behavior. So drivers that do that won't work with netlink
set_wolright now. I'll skim around to see if any drivers do this. But I would reckon this should be a driver fix.
It seems, from other discussion in a different sub-thread, that we are likely clear there :)
As that was my only real reservation wrt this patch:
Jakub Kicinski
maintainerQuoted 5 lines · On Wed, 31 May 2023 13:53:49 -0700 Justin Chen wrote:
The netlink version of
set_wolchecks for not supported wolopts and avoids setting wol when the correct wolopt is already set. If we do the same with the ioctl version then we can remove these checks from the driver layer.Signed-off-by Justin Chen <[email protected]>
If I understand the discussion correctly the patch is ready to be applied. Could you repost it? It has been marked as "changes requested" in patchwork, I'm not 100% sure about the reason.