linux/net/ethtool
Jamie Bainbridge a699781c79 ethtool: check device is present when getting link settings
A sysfs reader can race with a device reset or removal, attempting to
read device state when the device is not actually present. eg:

     [exception RIP: qed_get_current_link+17]
  #8 [ffffb9e4f2907c48] qede_get_link_ksettings at ffffffffc07a994a [qede]
  #9 [ffffb9e4f2907cd8] __rh_call_get_link_ksettings at ffffffff992b01a3
 #10 [ffffb9e4f2907d38] __ethtool_get_link_ksettings at ffffffff992b04e4
 #11 [ffffb9e4f2907d90] duplex_show at ffffffff99260300
 #12 [ffffb9e4f2907e38] dev_attr_show at ffffffff9905a01c
 #13 [ffffb9e4f2907e50] sysfs_kf_seq_show at ffffffff98e0145b
 #14 [ffffb9e4f2907e68] seq_read at ffffffff98d902e3
 #15 [ffffb9e4f2907ec8] vfs_read at ffffffff98d657d1
 #16 [ffffb9e4f2907f00] ksys_read at ffffffff98d65c3f
 #17 [ffffb9e4f2907f38] do_syscall_64 at ffffffff98a052fb

 crash> struct net_device.state ffff9a9d21336000
    state = 5,

state 5 is __LINK_STATE_START (0b1) and __LINK_STATE_NOCARRIER (0b100).
The device is not present, note lack of __LINK_STATE_PRESENT (0b10).

This is the same sort of panic as observed in commit 4224cfd7fb
("net-sysfs: add check for netdevice being present to speed_show").

There are many other callers of __ethtool_get_link_ksettings() which
don't have a device presence check.

Move this check into ethtool to protect all callers.

Fixes: d519e17e2d ("net: export device speed and duplex via sysfs")
Fixes: 4224cfd7fb ("net-sysfs: add check for netdevice being present to speed_show")
Signed-off-by: Jamie Bainbridge <jamie.bainbridge@gmail.com>
Link: https://patch.msgid.link/8bae218864beaa44ed01628140475b9bf641c5b0.1724393671.git.jamie.bainbridge@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2024-08-26 14:03:02 -07:00
..
bitset.c Revert "ethtool: Fix mod state of verbose no_mask bitset" 2023-10-19 09:27:12 -07:00
bitset.h ethtool: add ethnl_parse_bitset() helper 2020-03-12 15:32:32 -07:00
cabletest.c net: ethtool: remove unused struct 'cable_test_tdr_req_info' 2024-06-05 10:19:08 +01:00
channels.c ethtool: fail closed if we can't get max channel used in indirection tables 2024-07-11 14:41:41 -07:00
cmis_cdb.c ethtool: cmis_cdb: Add a layer for supporting CDB commands 2024-06-28 10:48:23 +01:00
cmis_fw_update.c net: ethtool: Allow write mechanism of LPL and both LPL and EPL 2024-08-15 12:20:14 +02:00
cmis.h ethtool: cmis_fw_update: add a layer for supporting firmware update using CDB 2024-06-28 10:48:23 +01:00
coalesce.c net: ethtool: Fix the panic caused by dev being null when dumping coalesce 2024-07-01 13:43:50 +01:00
common.c Merge branch 'net-make-timestamping-selectable' 2024-07-15 08:02:30 -07:00
common.h Merge branch 'net-make-timestamping-selectable' 2024-07-15 08:02:30 -07:00
debug.c ethtool: netlink: always pass genl_info to .prepare_data 2023-08-15 15:01:03 -07:00
eee.c net: ethtool: eee: Remove legacy _u32 from keee 2024-02-28 12:18:05 +00:00
eeprom.c ethtool: move firmware flashing flag to struct ethtool_netdev_state 2024-07-04 15:45:15 -07:00
features.c ethtool: netlink: Add missing ethnl_ops_begin/complete 2024-01-18 13:21:06 +01:00
fec.c ethtool: netlink: always pass genl_info to .prepare_data 2023-08-15 15:01:03 -07:00
ioctl.c ethtool: check device is present when getting link settings 2024-08-26 14:03:02 -07:00
linkinfo.c ethtool: netlink: always pass genl_info to .prepare_data 2023-08-15 15:01:03 -07:00
linkmodes.c ethtool: netlink: always pass genl_info to .prepare_data 2023-08-15 15:01:03 -07:00
linkstate.c ethtool: netlink: do not return SQI value if link is down 2024-07-11 11:19:07 +02:00
Makefile ethtool: cmis_fw_update: add a layer for supporting firmware update using CDB 2024-06-28 10:48:23 +01:00
mm.c ethtool: netlink: always pass genl_info to .prepare_data 2023-08-15 15:01:03 -07:00
module_fw.h ethtool: Add ability to flash transceiver modules' firmware 2024-06-28 10:48:23 +01:00
module.c net: ethtool: Monotonically increase the message sequence number 2024-07-13 15:37:36 -07:00
netlink.c ethtool: move firmware flashing flag to struct ethtool_netdev_state 2024-07-04 15:45:15 -07:00
netlink.h ethtool: Add ability to flash transceiver modules' firmware 2024-06-28 10:48:23 +01:00
pause.c ethtool: netlink: always pass genl_info to .prepare_data 2023-08-15 15:01:03 -07:00
phc_vclocks.c ethtool: netlink: always pass genl_info to .prepare_data 2023-08-15 15:01:03 -07:00
plca.c Revert "Introduce PHY listing and link_topology tracking" 2024-01-04 16:05:47 -08:00
privflags.c ethtool: netlink: always pass genl_info to .prepare_data 2023-08-15 15:01:03 -07:00
pse-pd.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2024-07-15 13:19:17 -07:00
rings.c ethtool: add SET for TCP_DATA_SPLIT ringparam 2023-12-13 18:22:02 -08:00
rss.c ethtool: rss: echo the context number back 2024-07-25 16:23:47 -07:00
stats.c ethtool: netlink: always pass genl_info to .prepare_data 2023-08-15 15:01:03 -07:00
strset.c Revert "Introduce PHY listing and link_topology tracking" 2024-01-04 16:05:47 -08:00
tsinfo.c net: Add struct kernel_ethtool_ts_info 2024-07-15 08:02:26 -07:00
tunnels.c genetlink: use attrs from struct genl_info 2023-08-15 15:00:45 -07:00
wol.c net: move ethtool-related netdev state into its own struct 2024-06-28 18:53:17 -07:00