Skip to content

Commit 18ac559

Browse files
committed
Merge branch 'virtio_net-ethtool-validation'
Nikolay Aleksandrov says: ==================== virtio_net: better ethtool setting validation This small set is a follow-up for the recent patches that added ethtool get/set settings. Patch 1 changes the speed validation routine to check if the speed is between 0 and INT_MAX (or SPEED_UNKNOWN) and patch 2 adds port validation to virtio_net and better validation comment. This set is on top of Michael's patch which explains that speeds from 0 to INT_MAX are valid: http://patchwork.ozlabs.org/patch/578911/ ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 83840f5 + 0cf3ace commit 18ac559

File tree

2 files changed

+5
-20
lines changed

2 files changed

+5
-20
lines changed

drivers/net/virtio_net.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,11 +1386,13 @@ static bool virtnet_validate_ethtool_cmd(const struct ethtool_cmd *cmd)
13861386
struct ethtool_cmd diff1 = *cmd;
13871387
struct ethtool_cmd diff2 = {};
13881388

1389-
/* advertising and cmd are usually set, ignore port because we set it */
1389+
/* cmd is always set so we need to clear it, validate the port type
1390+
* and also without autonegotiation we can ignore advertising
1391+
*/
13901392
ethtool_cmd_speed_set(&diff1, 0);
1393+
diff2.port = PORT_OTHER;
13911394
diff1.advertising = 0;
13921395
diff1.duplex = 0;
1393-
diff1.port = 0;
13941396
diff1.cmd = 0;
13951397

13961398
return !memcmp(&diff1, &diff2, sizeof(diff1));

include/uapi/linux/ethtool.h

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,24 +1377,7 @@ enum ethtool_sfeatures_retval_bits {
13771377

13781378
static inline int ethtool_validate_speed(__u32 speed)
13791379
{
1380-
switch (speed) {
1381-
case SPEED_10:
1382-
case SPEED_100:
1383-
case SPEED_1000:
1384-
case SPEED_2500:
1385-
case SPEED_5000:
1386-
case SPEED_10000:
1387-
case SPEED_20000:
1388-
case SPEED_25000:
1389-
case SPEED_40000:
1390-
case SPEED_50000:
1391-
case SPEED_56000:
1392-
case SPEED_100000:
1393-
case SPEED_UNKNOWN:
1394-
return 1;
1395-
}
1396-
1397-
return 0;
1380+
return speed <= INT_MAX || speed == SPEED_UNKNOWN;
13981381
}
13991382

14001383
/* Duplex, half or full. */

0 commit comments

Comments
 (0)