]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net: ena: handle bad request id in ena_netdev
authorShay Agroskin <shayagr@amazon.com>
Mon, 23 Nov 2020 19:08:57 +0000 (21:08 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 2 Dec 2020 07:51:57 +0000 (08:51 +0100)
[ Upstream commit 5b7022cf1dc0d721bd4b5f3bada05bd8ced82fe0 ]

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: 30623e1ed116 ("net: ena: avoid memory access violation by validating req_id properly")
Signed-off-by: Ido Segev <idose@amazon.com>
Signed-off-by: Shay Agroskin <shayagr@amazon.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ethernet/amazon/ena/ena_eth_com.c
drivers/net/ethernet/amazon/ena/ena_netdev.c

index ccd440589565160108c0243749ea1f3d7a2a5e4d..336f115e8091ff7f8affe43167fcfb6d8ed2edee 100644 (file)
@@ -538,6 +538,7 @@ int ena_com_rx_pkt(struct ena_com_io_cq *io_cq,
 {
        struct ena_com_rx_buf_info *ena_buf = &ena_rx_ctx->ena_bufs[0];
        struct ena_eth_io_rx_cdesc_base *cdesc = NULL;
+       u16 q_depth = io_cq->q_depth;
        u16 cdesc_idx = 0;
        u16 nb_hw_desc;
        u16 i = 0;
@@ -565,6 +566,8 @@ int ena_com_rx_pkt(struct ena_com_io_cq *io_cq,
        do {
                ena_buf[i].len = cdesc->length;
                ena_buf[i].req_id = cdesc->req_id;
+               if (unlikely(ena_buf[i].req_id >= q_depth))
+                       return -EIO;
 
                if (++i >= nb_hw_desc)
                        break;
index a3a8edf9a734d02474080e4ae686d93c45a44239..0a8520a2e46499b15b0a51f6a00b831a7973ebe7 100644 (file)
@@ -801,24 +801,6 @@ static void ena_free_all_io_tx_resources(struct ena_adapter *adapter)
                                              adapter->num_io_queues);
 }
 
-static int validate_rx_req_id(struct ena_ring *rx_ring, u16 req_id)
-{
-       if (likely(req_id < rx_ring->ring_size))
-               return 0;
-
-       netif_err(rx_ring->adapter, rx_err, rx_ring->netdev,
-                 "Invalid rx req_id: %hu\n", req_id);
-
-       u64_stats_update_begin(&rx_ring->syncp);
-       rx_ring->rx_stats.bad_req_id++;
-       u64_stats_update_end(&rx_ring->syncp);
-
-       /* Trigger device reset */
-       rx_ring->adapter->reset_reason = ENA_REGS_RESET_INV_RX_REQ_ID;
-       set_bit(ENA_FLAG_TRIGGER_RESET, &rx_ring->adapter->flags);
-       return -EFAULT;
-}
-
 /* ena_setup_rx_resources - allocate I/O Rx resources (Descriptors)
  * @adapter: network interface device structure
  * @qid: queue index
@@ -1368,15 +1350,10 @@ static struct sk_buff *ena_rx_skb(struct ena_ring *rx_ring,
        struct ena_rx_buffer *rx_info;
        u16 len, req_id, buf = 0;
        void *va;
-       int rc;
 
        len = ena_bufs[buf].len;
        req_id = ena_bufs[buf].req_id;
 
-       rc = validate_rx_req_id(rx_ring, req_id);
-       if (unlikely(rc < 0))
-               return NULL;
-
        rx_info = &rx_ring->rx_buffer_info[req_id];
 
        if (unlikely(!rx_info->page)) {
@@ -1452,10 +1429,6 @@ static struct sk_buff *ena_rx_skb(struct ena_ring *rx_ring,
                len = ena_bufs[buf].len;
                req_id = ena_bufs[buf].req_id;
 
-               rc = validate_rx_req_id(rx_ring, req_id);
-               if (unlikely(rc < 0))
-                       return NULL;
-
                rx_info = &rx_ring->rx_buffer_info[req_id];
        } while (1);
 
@@ -1704,12 +1677,18 @@ static int ena_clean_rx_irq(struct ena_ring *rx_ring, struct napi_struct *napi,
 error:
        adapter = netdev_priv(rx_ring->netdev);
 
-       u64_stats_update_begin(&rx_ring->syncp);
-       rx_ring->rx_stats.bad_desc_num++;
-       u64_stats_update_end(&rx_ring->syncp);
+       if (rc == -ENOSPC) {
+               u64_stats_update_begin(&rx_ring->syncp);
+               rx_ring->rx_stats.bad_desc_num++;
+               u64_stats_update_end(&rx_ring->syncp);
+               adapter->reset_reason = ENA_REGS_RESET_TOO_MANY_RX_DESCS;
+       } else {
+               u64_stats_update_begin(&rx_ring->syncp);
+               rx_ring->rx_stats.bad_req_id++;
+               u64_stats_update_end(&rx_ring->syncp);
+               adapter->reset_reason = ENA_REGS_RESET_INV_RX_REQ_ID;
+       }
 
-       /* Too many desc from the device. Trigger reset */
-       adapter->reset_reason = ENA_REGS_RESET_TOO_MANY_RX_DESCS;
        set_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags);
 
        return 0;