netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] ethtool: ignore unused/unreliable fields in set_eee op
@ 2024-02-21  7:24 Heiner Kallweit
  2024-02-21 15:41 ` Andrew Lunn
  0 siblings, 1 reply; 3+ messages in thread
From: Heiner Kallweit @ 2024-02-21  7:24 UTC (permalink / raw)
  To: Andrew Lunn, Russell King - ARM Linux, Paolo Abeni,
	Jakub Kicinski, David Miller, Eric Dumazet
  Cc: netdev@vger.kernel.org

This function is used with the set_eee() ethtool operation. Certain
fields of struct ethtool_keee() are relevant only for the get_eee()
operation. In addition, in case of the ioctl interface, we have no
guarantee that userspace sends sane values in struct ethtool_eee.
Therefore explicitly ignore all fields not needed for set_eee().
This protects from drivers trying to use unchecked and unreliable
data, relying on specific userspace behavior.

Note: Such unsafe driver behavior has been found and fixed in the
tg3 driver.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 net/ethtool/ioctl.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c
index 1763e8b69..ff28c113b 100644
--- a/net/ethtool/ioctl.c
+++ b/net/ethtool/ioctl.c
@@ -1513,20 +1513,13 @@ static void eee_to_keee(struct ethtool_keee *keee,
 {
 	memset(keee, 0, sizeof(*keee));
 
-	keee->supported_u32 = eee->supported;
 	keee->advertised_u32 = eee->advertised;
-	keee->lp_advertised_u32 = eee->lp_advertised;
-	keee->eee_active = eee->eee_active;
 	keee->eee_enabled = eee->eee_enabled;
 	keee->tx_lpi_enabled = eee->tx_lpi_enabled;
 	keee->tx_lpi_timer = eee->tx_lpi_timer;
 
-	ethtool_convert_legacy_u32_to_link_mode(keee->supported,
-						eee->supported);
 	ethtool_convert_legacy_u32_to_link_mode(keee->advertised,
 						eee->advertised);
-	ethtool_convert_legacy_u32_to_link_mode(keee->lp_advertised,
-						eee->lp_advertised);
 }
 
 static void keee_to_eee(struct ethtool_eee *eee,
-- 
2.43.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next] ethtool: ignore unused/unreliable fields in set_eee op
  2024-02-21  7:24 [PATCH net-next] ethtool: ignore unused/unreliable fields in set_eee op Heiner Kallweit
@ 2024-02-21 15:41 ` Andrew Lunn
  2024-02-21 19:50   ` Heiner Kallweit
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Lunn @ 2024-02-21 15:41 UTC (permalink / raw)
  To: Heiner Kallweit
  Cc: Russell King - ARM Linux, Paolo Abeni, Jakub Kicinski,
	David Miller, Eric Dumazet, netdev@vger.kernel.org

On Wed, Feb 21, 2024 at 08:24:40AM +0100, Heiner Kallweit wrote:
> This function is used with the set_eee() ethtool operation. Certain
> fields of struct ethtool_keee() are relevant only for the get_eee()
> operation. In addition, in case of the ioctl interface, we have no
> guarantee that userspace sends sane values in struct ethtool_eee.
> Therefore explicitly ignore all fields not needed for set_eee().
> This protects from drivers trying to use unchecked and unreliable
> data, relying on specific userspace behavior.
> 
> Note: Such unsafe driver behavior has been found and fixed in the
> tg3 driver.
> 
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
>  net/ethtool/ioctl.c | 7 -------
>  1 file changed, 7 deletions(-)
> 
> diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c
> index 1763e8b69..ff28c113b 100644
> --- a/net/ethtool/ioctl.c
> +++ b/net/ethtool/ioctl.c
> @@ -1513,20 +1513,13 @@ static void eee_to_keee(struct ethtool_keee *keee,
>  {
>  	memset(keee, 0, sizeof(*keee));
>  
> -	keee->supported_u32 = eee->supported;
>  	keee->advertised_u32 = eee->advertised;
> -	keee->lp_advertised_u32 = eee->lp_advertised;

This overlaps with the last patch in my series, which removes all the
_u32 members from keee. They are no longer used at the end of my
series. I added this removal patch because i kept missing a _u32, and
i wanted the compiler to tell me.

	Andrew

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next] ethtool: ignore unused/unreliable fields in set_eee op
  2024-02-21 15:41 ` Andrew Lunn
@ 2024-02-21 19:50   ` Heiner Kallweit
  0 siblings, 0 replies; 3+ messages in thread
From: Heiner Kallweit @ 2024-02-21 19:50 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: Russell King - ARM Linux, Paolo Abeni, Jakub Kicinski,
	David Miller, Eric Dumazet, netdev@vger.kernel.org

On 21.02.2024 16:41, Andrew Lunn wrote:
> On Wed, Feb 21, 2024 at 08:24:40AM +0100, Heiner Kallweit wrote:
>> This function is used with the set_eee() ethtool operation. Certain
>> fields of struct ethtool_keee() are relevant only for the get_eee()
>> operation. In addition, in case of the ioctl interface, we have no
>> guarantee that userspace sends sane values in struct ethtool_eee.
>> Therefore explicitly ignore all fields not needed for set_eee().
>> This protects from drivers trying to use unchecked and unreliable
>> data, relying on specific userspace behavior.
>>
>> Note: Such unsafe driver behavior has been found and fixed in the
>> tg3 driver.
>>
>> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
>> ---
>>  net/ethtool/ioctl.c | 7 -------
>>  1 file changed, 7 deletions(-)
>>
>> diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c
>> index 1763e8b69..ff28c113b 100644
>> --- a/net/ethtool/ioctl.c
>> +++ b/net/ethtool/ioctl.c
>> @@ -1513,20 +1513,13 @@ static void eee_to_keee(struct ethtool_keee *keee,
>>  {
>>  	memset(keee, 0, sizeof(*keee));
>>  
>> -	keee->supported_u32 = eee->supported;
>>  	keee->advertised_u32 = eee->advertised;
>> -	keee->lp_advertised_u32 = eee->lp_advertised;
> 
> This overlaps with the last patch in my series, which removes all the
> _u32 members from keee. They are no longer used at the end of my
> series. I added this removal patch because i kept missing a _u32, and
> i wanted the compiler to tell me.
> 
Ah, didn't see this. Then I'll wait for your series to be applied,
afterwards will check whether parts of my patch are still applicable.

> 	Andrew

Heiner

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-02-21 19:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-21  7:24 [PATCH net-next] ethtool: ignore unused/unreliable fields in set_eee op Heiner Kallweit
2024-02-21 15:41 ` Andrew Lunn
2024-02-21 19:50   ` Heiner Kallweit

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).