Skip to contentSkip to conversation

sfc: ensure type is valid before updating seen_gen

PATCH Applied [email protected] 3 participants 3 messages Nov 21, 2022 – Nov 23, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sfc: ensure type is valid before updating seen_gen

From: Edward Cree <[email protected]>

In the case of invalid or corrupted v2 counter update packets,
efx_tc_rx_version_2() returns EFX_TC_COUNTER_TYPE_MAX. In this case we should not attempt to update generation counts as this will write beyond the end of the seen_gen array.

Addresses-Coverity-ID: 1527356 ("Memory - illegal accesses")

Fixes 25730d8be5d8 ("sfc: add extra RX channel to receive MAE counter updates on ef100")
---
 drivers/net/ethernet/sfc/tc_counters.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/net/ethernet/sfc/tc_counters.c +9 -7
index 2bba5d3a2fdb..d1a91d54c6bb 100644
@@ -476,13 +476,15 @@ static bool efx_tc_rx(struct efx_rx_queue *rx_queue, u32 mark)
 		goto out;
 	}
 
-	/* Update seen_gen unconditionally, to avoid a missed wakeup if
-	 * we race with efx_mae_stop_counters().
-	 */
-	efx->tc->seen_gen[type] = mark;
-	if (efx->tc->flush_counters &&
-	    (s32)(efx->tc->flush_gen[type] - mark) <= 0)
-		wake_up(&efx->tc->flush_wq);
+	if (type < EFX_TC_COUNTER_TYPE_MAX) {
+		/* Update seen_gen unconditionally, to avoid a missed wakeup if
+		 * we race with efx_mae_stop_counters().
+		 */
+		efx->tc->seen_gen[type] = mark;
+		if (efx->tc->flush_counters &&
+		    (s32)(efx->tc->flush_gen[type] - mark) <= 0)
+			wake_up(&efx->tc->flush_wq);
+	}
 out:
 	efx_free_rx_buffers(rx_queue, rx_buf, 1);
 	channel->rx_pkt_n_frags = 0;
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · On Mon, Nov 21, 2022 at 09:37:08PM +0000, [email protected] wrote:

From: Edward Cree <[email protected]>

In the case of invalid or corrupted v2 counter update packets,
efx_tc_rx_version_2() returns EFX_TC_COUNTER_TYPE_MAX. In this case we should not attempt to update generation counts as this will write beyond the end of the seen_gen array.

Addresses-Coverity-ID: 1527356 ("Memory - illegal accesses")

Fixes 25730d8be5d8 ("sfc: add extra RX channel to receive MAE counter updates on ef100")
Signature · 1 line
Kees Cook
#2 lore raw
In reply to [email protected]
This patch was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Quoted 8 lines · On Mon, 21 Nov 2022 21:37:08 +0000 you wrote:

From: Edward Cree <[email protected]>

In the case of invalid or corrupted v2 counter update packets,
efx_tc_rx_version_2() returns EFX_TC_COUNTER_TYPE_MAX. In this case we should not attempt to update generation counts as this will write beyond the end of the seen_gen array.

[...]

Here is the summary with links:
- [net-next] sfc: ensure type is valid before updating seen_gen

    https://git.kernel.org/netdev/net-next/c/e80bd08fd75a

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html