diff mbox series

[net-next] sfc: ensure type is valid before updating seen_gen

Message ID 20221121213708.13645-1-edward.cree@amd.com (mailing list archive)
State Accepted
Commit e80bd08fd75a644e2337fb535c1afdb6417357ff
Delegated to: Netdev Maintainers
Headers show
Series [net-next] sfc: ensure type is valid before updating seen_gen | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 22 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

edward.cree@amd.com Nov. 21, 2022, 9:37 p.m. UTC
From: Edward Cree <ecree.xilinx@gmail.com>

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.

Reported-by: coverity-bot <keescook+coverity-bot@chromium.org>
Addresses-Coverity-ID: 1527356 ("Memory - illegal accesses")
Fixes: 25730d8be5d8 ("sfc: add extra RX channel to receive MAE counter updates on ef100")
Signed-off-by: Edward Cree <ecree.xilinx@gmail.com>
---
 drivers/net/ethernet/sfc/tc_counters.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

Comments

Kees Cook Nov. 23, 2022, 5:17 a.m. UTC | #1
On Mon, Nov 21, 2022 at 09:37:08PM +0000, edward.cree@amd.com wrote:
> From: Edward Cree <ecree.xilinx@gmail.com>
> 
> 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.
> 
> Reported-by: coverity-bot <keescook+coverity-bot@chromium.org>
> Addresses-Coverity-ID: 1527356 ("Memory - illegal accesses")
> Fixes: 25730d8be5d8 ("sfc: add extra RX channel to receive MAE counter updates on ef100")
> Signed-off-by: Edward Cree <ecree.xilinx@gmail.com>

Reviewed-by: Kees Cook <keescook@chromium.org>
patchwork-bot+netdevbpf@kernel.org Nov. 23, 2022, 1:50 p.m. UTC | #2
Hello:

This patch was applied to netdev/net-next.git (master)
by David S. Miller <davem@davemloft.net>:

On Mon, 21 Nov 2022 21:37:08 +0000 you wrote:
> From: Edward Cree <ecree.xilinx@gmail.com>
> 
> 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!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/sfc/tc_counters.c b/drivers/net/ethernet/sfc/tc_counters.c
index 2bba5d3a2fdb..d1a91d54c6bb 100644
--- a/drivers/net/ethernet/sfc/tc_counters.c
+++ b/drivers/net/ethernet/sfc/tc_counters.c
@@ -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;