Skip to content

Commit 61deee9

Browse files
sf-hgkdavem330
authored andcommitted
sfc: don't try and read ef10 data on non-ef10 NIC
The MAC stats command takes a port ID, which doesn't exist on pre-ef10 NICs (5000- and 6000- series). This is extracted from the NIC specific data; we misinterpret this as the ef10 data structure, causing us to read potentially unallocated data. With a KASAN kernel this can cause errors with: BUG: KASAN: slab-out-of-bounds in efx_mcdi_mac_stats Fixes: 0a2ab4d ("sfc: set the port-id when calling MC_CMD_MAC_STATS") Reported-by: Stefano Brivio <[email protected]> Tested-by: Stefano Brivio <[email protected]> Signed-off-by: Bert Kenward <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c90e951 commit 61deee9

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/net/ethernet/sfc/mcdi_port.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,6 @@ enum efx_stats_action {
938938
static int efx_mcdi_mac_stats(struct efx_nic *efx,
939939
enum efx_stats_action action, int clear)
940940
{
941-
struct efx_ef10_nic_data *nic_data = efx->nic_data;
942941
MCDI_DECLARE_BUF(inbuf, MC_CMD_MAC_STATS_IN_LEN);
943942
int rc;
944943
int change = action == EFX_STATS_PULL ? 0 : 1;
@@ -960,7 +959,12 @@ static int efx_mcdi_mac_stats(struct efx_nic *efx,
960959
MAC_STATS_IN_PERIODIC_NOEVENT, 1,
961960
MAC_STATS_IN_PERIOD_MS, period);
962961
MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_LEN, dma_len);
963-
MCDI_SET_DWORD(inbuf, MAC_STATS_IN_PORT_ID, nic_data->vport_id);
962+
963+
if (efx_nic_rev(efx) >= EFX_REV_HUNT_A0) {
964+
struct efx_ef10_nic_data *nic_data = efx->nic_data;
965+
966+
MCDI_SET_DWORD(inbuf, MAC_STATS_IN_PORT_ID, nic_data->vport_id);
967+
}
964968

965969
rc = efx_mcdi_rpc_quiet(efx, MC_CMD_MAC_STATS, inbuf, sizeof(inbuf),
966970
NULL, 0, NULL);

0 commit comments

Comments
 (0)