Skip to content

Commit 5b7022c

Browse files
ShayAgroskuba-moo
authored andcommitted
net: ena: handle bad request id in ena_netdev
After request id is checked in validate_rx_req_id() its value is still used in the line rx_ring->free_ids[next_to_clean] = rx_ring->ena_bufs[i].req_id; even if it was found to be out-of-bound for the array free_ids. The patch moves the request id to an earlier stage in the napi routine and makes sure its value isn't used if it's found out-of-bounds. Fixes: 30623e1 ("net: ena: avoid memory access violation by validating req_id properly") Signed-off-by: Ido Segev <[email protected]> Signed-off-by: Shay Agroskin <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent d8f0a86 commit 5b7022c

File tree

2 files changed

+14
-32
lines changed

2 files changed

+14
-32
lines changed

drivers/net/ethernet/amazon/ena/ena_eth_com.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ int ena_com_rx_pkt(struct ena_com_io_cq *io_cq,
516516
{
517517
struct ena_com_rx_buf_info *ena_buf = &ena_rx_ctx->ena_bufs[0];
518518
struct ena_eth_io_rx_cdesc_base *cdesc = NULL;
519+
u16 q_depth = io_cq->q_depth;
519520
u16 cdesc_idx = 0;
520521
u16 nb_hw_desc;
521522
u16 i = 0;
@@ -543,6 +544,8 @@ int ena_com_rx_pkt(struct ena_com_io_cq *io_cq,
543544
do {
544545
ena_buf[i].len = cdesc->length;
545546
ena_buf[i].req_id = cdesc->req_id;
547+
if (unlikely(ena_buf[i].req_id >= q_depth))
548+
return -EIO;
546549

547550
if (++i >= nb_hw_desc)
548551
break;

drivers/net/ethernet/amazon/ena/ena_netdev.c

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -789,24 +789,6 @@ static void ena_free_all_io_tx_resources(struct ena_adapter *adapter)
789789
adapter->num_io_queues);
790790
}
791791

792-
static int validate_rx_req_id(struct ena_ring *rx_ring, u16 req_id)
793-
{
794-
if (likely(req_id < rx_ring->ring_size))
795-
return 0;
796-
797-
netif_err(rx_ring->adapter, rx_err, rx_ring->netdev,
798-
"Invalid rx req_id: %hu\n", req_id);
799-
800-
u64_stats_update_begin(&rx_ring->syncp);
801-
rx_ring->rx_stats.bad_req_id++;
802-
u64_stats_update_end(&rx_ring->syncp);
803-
804-
/* Trigger device reset */
805-
rx_ring->adapter->reset_reason = ENA_REGS_RESET_INV_RX_REQ_ID;
806-
set_bit(ENA_FLAG_TRIGGER_RESET, &rx_ring->adapter->flags);
807-
return -EFAULT;
808-
}
809-
810792
/* ena_setup_rx_resources - allocate I/O Rx resources (Descriptors)
811793
* @adapter: network interface device structure
812794
* @qid: queue index
@@ -1356,15 +1338,10 @@ static struct sk_buff *ena_rx_skb(struct ena_ring *rx_ring,
13561338
struct ena_rx_buffer *rx_info;
13571339
u16 len, req_id, buf = 0;
13581340
void *va;
1359-
int rc;
13601341

13611342
len = ena_bufs[buf].len;
13621343
req_id = ena_bufs[buf].req_id;
13631344

1364-
rc = validate_rx_req_id(rx_ring, req_id);
1365-
if (unlikely(rc < 0))
1366-
return NULL;
1367-
13681345
rx_info = &rx_ring->rx_buffer_info[req_id];
13691346

13701347
if (unlikely(!rx_info->page)) {
@@ -1440,10 +1417,6 @@ static struct sk_buff *ena_rx_skb(struct ena_ring *rx_ring,
14401417
len = ena_bufs[buf].len;
14411418
req_id = ena_bufs[buf].req_id;
14421419

1443-
rc = validate_rx_req_id(rx_ring, req_id);
1444-
if (unlikely(rc < 0))
1445-
return NULL;
1446-
14471420
rx_info = &rx_ring->rx_buffer_info[req_id];
14481421
} while (1);
14491422

@@ -1697,12 +1670,18 @@ static int ena_clean_rx_irq(struct ena_ring *rx_ring, struct napi_struct *napi,
16971670
error:
16981671
adapter = netdev_priv(rx_ring->netdev);
16991672

1700-
u64_stats_update_begin(&rx_ring->syncp);
1701-
rx_ring->rx_stats.bad_desc_num++;
1702-
u64_stats_update_end(&rx_ring->syncp);
1673+
if (rc == -ENOSPC) {
1674+
u64_stats_update_begin(&rx_ring->syncp);
1675+
rx_ring->rx_stats.bad_desc_num++;
1676+
u64_stats_update_end(&rx_ring->syncp);
1677+
adapter->reset_reason = ENA_REGS_RESET_TOO_MANY_RX_DESCS;
1678+
} else {
1679+
u64_stats_update_begin(&rx_ring->syncp);
1680+
rx_ring->rx_stats.bad_req_id++;
1681+
u64_stats_update_end(&rx_ring->syncp);
1682+
adapter->reset_reason = ENA_REGS_RESET_INV_RX_REQ_ID;
1683+
}
17031684

1704-
/* Too many desc from the device. Trigger reset */
1705-
adapter->reset_reason = ENA_REGS_RESET_TOO_MANY_RX_DESCS;
17061685
set_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags);
17071686

17081687
return 0;

0 commit comments

Comments
 (0)