Skip to content

Commit 0d1b7d6

Browse files
kuba-mooPaolo Abeni
authored andcommitted
bnxt: fix crashes when reducing ring count with active RSS contexts
bnxt doesn't check if a ring is used by RSS contexts when reducing ring count. Core performs a similar check for the drivers for the main context, but core doesn't know about additional contexts, so it can't validate them. bnxt_fill_hw_rss_tbl_p5() uses ring id to index bp->rx_ring[], which without the check may end up being out of bounds. BUG: KASAN: slab-out-of-bounds in __bnxt_hwrm_vnic_set_rss+0xb79/0xe40 Read of size 2 at addr ffff8881c5809618 by task ethtool/31525 Call Trace: __bnxt_hwrm_vnic_set_rss+0xb79/0xe40 bnxt_hwrm_vnic_rss_cfg_p5+0xf7/0x460 __bnxt_setup_vnic_p5+0x12e/0x270 __bnxt_open_nic+0x2262/0x2f30 bnxt_open_nic+0x5d/0xf0 ethnl_set_channels+0x5d4/0xb30 ethnl_default_set_doit+0x2f1/0x620 Core does track the additional contexts in net-next, so we can move this validation out of the driver as a follow up there. Fixes: b3d0083 ("bnxt_en: Support RSS contexts in ethtool .{get|set}_rxfh()") Signed-off-by: Jakub Kicinski <[email protected]> Reviewed-by: Pavan Chebbi <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 30f747b commit 0d1b7d6

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

drivers/net/ethernet/broadcom/bnxt/bnxt.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6146,6 +6146,21 @@ static u16 bnxt_get_max_rss_ring(struct bnxt *bp)
61466146
return max_ring;
61476147
}
61486148

6149+
u16 bnxt_get_max_rss_ctx_ring(struct bnxt *bp)
6150+
{
6151+
u16 i, tbl_size, max_ring = 0;
6152+
struct bnxt_rss_ctx *rss_ctx;
6153+
6154+
tbl_size = bnxt_get_rxfh_indir_size(bp->dev);
6155+
6156+
list_for_each_entry(rss_ctx, &bp->rss_ctx_list, list) {
6157+
for (i = 0; i < tbl_size; i++)
6158+
max_ring = max(max_ring, rss_ctx->rss_indir_tbl[i]);
6159+
}
6160+
6161+
return max_ring;
6162+
}
6163+
61496164
int bnxt_get_nr_rss_ctxs(struct bnxt *bp, int rx_rings)
61506165
{
61516166
if (bp->flags & BNXT_FLAG_CHIP_P5_PLUS) {

drivers/net/ethernet/broadcom/bnxt/bnxt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2776,6 +2776,7 @@ int bnxt_hwrm_vnic_set_tpa(struct bnxt *bp, struct bnxt_vnic_info *vnic,
27762776
void bnxt_fill_ipv6_mask(__be32 mask[4]);
27772777
int bnxt_alloc_rss_indir_tbl(struct bnxt *bp, struct bnxt_rss_ctx *rss_ctx);
27782778
void bnxt_set_dflt_rss_indir_tbl(struct bnxt *bp, struct bnxt_rss_ctx *rss_ctx);
2779+
u16 bnxt_get_max_rss_ctx_ring(struct bnxt *bp);
27792780
int bnxt_get_nr_rss_ctxs(struct bnxt *bp, int rx_rings);
27802781
int bnxt_hwrm_vnic_cfg(struct bnxt *bp, struct bnxt_vnic_info *vnic);
27812782
int bnxt_hwrm_vnic_alloc(struct bnxt *bp, struct bnxt_vnic_info *vnic,

drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,12 @@ static int bnxt_set_channels(struct net_device *dev,
961961
return rc;
962962
}
963963

964+
if (req_rx_rings < bp->rx_nr_rings &&
965+
req_rx_rings <= bnxt_get_max_rss_ctx_ring(bp)) {
966+
netdev_warn(dev, "Can't deactivate rings used by RSS contexts\n");
967+
return -EINVAL;
968+
}
969+
964970
if (bnxt_get_nr_rss_ctxs(bp, req_rx_rings) !=
965971
bnxt_get_nr_rss_ctxs(bp, bp->rx_nr_rings) &&
966972
netif_is_rxfh_configured(dev)) {

0 commit comments

Comments
 (0)