diff mbox series

[net-next] ethtool: ignore unused/unreliable fields in set_eee op

Message ID 4806ef46-a162-4782-8c15-17e12ad88de7@gmail.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net-next] ethtool: ignore unused/unreliable fields in set_eee op | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 942 this patch: 942
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 1 maintainers not CCed: ahmed.zaki@intel.com
netdev/build_clang success Errors and warnings before: 958 this patch: 958
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 success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 959 this patch: 959
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 20 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-02-21--12-00 (tests: 1454)

Commit Message

Heiner Kallweit Feb. 21, 2024, 7:24 a.m. UTC
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(-)

Comments

Andrew Lunn Feb. 21, 2024, 3:41 p.m. UTC | #1
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
Heiner Kallweit Feb. 21, 2024, 7:50 p.m. UTC | #2
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
diff mbox series

Patch

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,