From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 330F6A04B7; Tue, 13 Oct 2020 13:51:54 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 3C5671DAF0; Tue, 13 Oct 2020 13:51:19 +0200 (CEST) Received: from incedge.chinasoftinc.com (unknown [114.113.233.8]) by dpdk.org (Postfix) with ESMTP id 894061DADB for ; Tue, 13 Oct 2020 13:51:15 +0200 (CEST) X-ASG-Debug-ID: 1602589872-149d114caf2078c0001-TfluYd Received: from mail.chinasoftinc.com (inccas001.ito.icss [10.168.0.51]) by incedge.chinasoftinc.com with ESMTP id xxfe1ZEcnMJOdSK8 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 13 Oct 2020 19:51:12 +0800 (CST) X-Barracuda-Envelope-From: huwei013@chinasoftinc.com X-Barracuda-RBL-Trusted-Forwarder: 10.168.0.51 X-ASG-Whitelist: Client Received: from localhost.localdomain (65.49.108.226) by INCCAS001.ito.icss (10.168.0.60) with Microsoft SMTP Server id 14.3.487.0; Tue, 13 Oct 2020 19:51:12 +0800 From: "Wei Hu (Xavier)" X-Barracuda-RBL-Trusted-Forwarder: 10.168.0.60 To: , , , , CC: Date: Tue, 13 Oct 2020 19:50:54 +0800 X-ASG-Orig-Subj: [PATCH v5 2/3] ethdev: check if queue setup in queue-related APIs Message-ID: <20201013115055.34295-3-huwei013@chinasoftinc.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20201013115055.34295-1-huwei013@chinasoftinc.com> References: <20201010071212.24086-1-huwei013@chinasoftinc.com> <20201013115055.34295-1-huwei013@chinasoftinc.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [65.49.108.226] X-Barracuda-Connect: inccas001.ito.icss[10.168.0.51] X-Barracuda-Start-Time: 1602589872 X-Barracuda-Encrypted: ECDHE-RSA-AES256-SHA X-Barracuda-URL: https://incspam.chinasofti.com:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at chinasoftinc.com X-Barracuda-Scan-Msg-Size: 2266 Subject: [dpdk-dev] [PATCH v5 2/3] ethdev: check if queue setup in queue-related APIs X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: "Wei Hu (Xavier)" This patch adds checking whether the related Tx or Rx queue has been setup in the queue-related API functions to avoid illegal address access. Signed-off-by: Chengchang Tang Signed-off-by: Wei Hu (Xavier) Signed-off-by: Chengwen Feng Acked-by: Stephen Hemminger Reviewed-by: Kalesh AP --- lib/librte_ethdev/rte_ethdev.c | 16 ++++++++++++++++ lib/librte_ethdev/rte_ethdev.h | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index 11e54d9..4acf858 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -890,6 +890,14 @@ eth_dev_validate_rx_queue(const struct rte_eth_dev *dev, uint16_t rx_queue_id) return -EINVAL; } + if (dev->data->rx_queues[rx_queue_id] == NULL) { + port_id = dev->data->port_id; + RTE_ETHDEV_LOG(ERR, + "Queue %u of device with port_id=%u has not been setup\n", + rx_queue_id, port_id); + return -EINVAL; + } + return 0; } @@ -906,6 +914,14 @@ eth_dev_validate_tx_queue(const struct rte_eth_dev *dev, uint16_t tx_queue_id) return -EINVAL; } + if (dev->data->tx_queues[tx_queue_id] == NULL) { + port_id = dev->data->port_id; + RTE_ETHDEV_LOG(ERR, + "Queue %u of device with port_id=%u has not been setup\n", + tx_queue_id, port_id); + return -EINVAL; + } + return 0; } diff --git a/lib/librte_ethdev/rte_ethdev.h b/lib/librte_ethdev/rte_ethdev.h index 5bcfbb8..f4cc591 100644 --- a/lib/librte_ethdev/rte_ethdev.h +++ b/lib/librte_ethdev/rte_ethdev.h @@ -4721,7 +4721,8 @@ rte_eth_rx_queue_count(uint16_t port_id, uint16_t queue_id) RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL); dev = &rte_eth_devices[port_id]; RTE_FUNC_PTR_OR_ERR_RET(*dev->rx_queue_count, -ENOTSUP); - if (queue_id >= dev->data->nb_rx_queues) + if (queue_id >= dev->data->nb_rx_queues || + dev->data->rx_queues[queue_id] == NULL) return -EINVAL; return (int)(*dev->rx_queue_count)(dev, queue_id); -- 2.9.5