From: <edward.cree@amd.com>
To: <netdev@vger.kernel.org>, <linux-net-drivers@amd.com>
Cc: <davem@davemloft.net>, <kuba@kernel.org>, <pabeni@redhat.com>,
<edumazet@google.com>, <habetsm.xilinx@gmail.com>,
Edward Cree <ecree.xilinx@gmail.com>,
coverity-bot <keescook+coverity-bot@chromium.org>
Subject: [PATCH net-next] sfc: ensure type is valid before updating seen_gen
Date: Mon, 21 Nov 2022 21:37:08 +0000 [thread overview]
Message-ID: <20221121213708.13645-1-edward.cree@amd.com> (raw)
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(-)
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;
next reply other threads:[~2022-11-21 21:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-21 21:37 edward.cree [this message]
2022-11-23 5:17 ` [PATCH net-next] sfc: ensure type is valid before updating seen_gen Kees Cook
2022-11-23 13:50 ` patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221121213708.13645-1-edward.cree@amd.com \
--to=edward.cree@amd.com \
--cc=davem@davemloft.net \
--cc=ecree.xilinx@gmail.com \
--cc=edumazet@google.com \
--cc=habetsm.xilinx@gmail.com \
--cc=keescook+coverity-bot@chromium.org \
--cc=kuba@kernel.org \
--cc=linux-net-drivers@amd.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).