Skip to content

Commit 30623e1

Browse files
akiyanodavem330
authored andcommitted
net: ena: avoid memory access violation by validating req_id properly
Rx req_id is an index in struct ena_eth_io_rx_cdesc_base. The driver should validate that the Rx req_id it received from the device is in range [0, ring_size -1]. Failure to do so could yield to potential memory access violoation. The validation was mistakenly done when refilling the Rx submission queue and not in Rx completion queue. Fixes: ad974ba ("net: ena: add support for out of order rx buffers refill") Signed-off-by: Noam Dagan <[email protected]> Signed-off-by: Arthur Kiyanovski <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e02ae6e commit 30623e1

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,13 +1018,9 @@ static int ena_refill_rx_bufs(struct ena_ring *rx_ring, u32 num)
10181018
struct ena_rx_buffer *rx_info;
10191019

10201020
req_id = rx_ring->free_ids[next_to_use];
1021-
rc = validate_rx_req_id(rx_ring, req_id);
1022-
if (unlikely(rc < 0))
1023-
break;
10241021

10251022
rx_info = &rx_ring->rx_buffer_info[req_id];
10261023

1027-
10281024
rc = ena_alloc_rx_page(rx_ring, rx_info,
10291025
GFP_ATOMIC | __GFP_COMP);
10301026
if (unlikely(rc < 0)) {
@@ -1379,9 +1375,15 @@ static struct sk_buff *ena_rx_skb(struct ena_ring *rx_ring,
13791375
struct ena_rx_buffer *rx_info;
13801376
u16 len, req_id, buf = 0;
13811377
void *va;
1378+
int rc;
13821379

13831380
len = ena_bufs[buf].len;
13841381
req_id = ena_bufs[buf].req_id;
1382+
1383+
rc = validate_rx_req_id(rx_ring, req_id);
1384+
if (unlikely(rc < 0))
1385+
return NULL;
1386+
13851387
rx_info = &rx_ring->rx_buffer_info[req_id];
13861388

13871389
if (unlikely(!rx_info->page)) {
@@ -1454,6 +1456,11 @@ static struct sk_buff *ena_rx_skb(struct ena_ring *rx_ring,
14541456
buf++;
14551457
len = ena_bufs[buf].len;
14561458
req_id = ena_bufs[buf].req_id;
1459+
1460+
rc = validate_rx_req_id(rx_ring, req_id);
1461+
if (unlikely(rc < 0))
1462+
return NULL;
1463+
14571464
rx_info = &rx_ring->rx_buffer_info[req_id];
14581465
} while (1);
14591466

0 commit comments

Comments
 (0)