From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7882843755; Thu, 21 Dec 2023 22:03:35 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 042A3402A6; Thu, 21 Dec 2023 22:03:35 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id E49454028B; Thu, 21 Dec 2023 22:03:33 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1086) id 20B0420B3CC1; Thu, 21 Dec 2023 13:03:33 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 20B0420B3CC1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1703192613; bh=YeW1rPH3AyoCN5Oc1CZaU0HwxU+aNW4uuaocUdVwsBc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=h6lHEtn/pfow0ZSlszdIo3dgwm8f9ZTbOWqw0oNysi0WeXgtKdvOiPdlLDP6M4arh OLM47S5aYBwxhHldpcXIKdHbodEeFMShT1v1Z6Qf2IBDWEFU4JaGcNs5SQpXrVK0v5 lDrFCDpLDJLpZWm2JPOwveQPBZHoL5KaHAy5Oqjc= Date: Thu, 21 Dec 2023 13:03:33 -0800 From: Tyler Retzlaff To: Sivaramakrishnan Venkat Cc: Igor Russkikh , Selwin Sebastian , Ajit Khaparde , Somnath Kotur , Nithin Dabilpuram , Kiran Kumar K , Sunil Kumar Kori , Satha Rao , Yuying Zhang , Beilei Xing , Rahul Lakkireddy , Hemant Agrawal , Sachin Saxena , Simei Su , Wenjun Wu , Gagandeep Singh , John Daley , Hyong Youb Kim , Gaetan Rivet , Qi Zhang , Xiao Wang , Jie Hai , Yisen Zhuang , Jingjing Wu , Qiming Yang , Junfeng Guo , Andrew Boyer , Matan Azrad , Viacheslav Ovsiienko , Dariusz Sosnowski , Ori Kam , Suanming Mou , Long Li , Chaoyong He , Jiawen Wu , Harman Kalra , Devendra Singh Rawat , Alok Prasad , Andrew Rybchenko , Jerin Jacob , Maciej Czekaj , Jian Wang , Jochen Behrens , Thomas Monjalon , Ferruh Yigit , dev@dpdk.org, ciara.power@intel.com, ferruh.yigit@intel.com, stable@dpdk.org Subject: Re: [PATCH v3] ethdev: fix getting supported ptypes list Message-ID: <20231221210333.GA7666@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> References: <20231212143722.1803259-1-venkatx.sivaramakrishnan@intel.com> <20231221184001.928922-1-venkatx.sivaramakrishnan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231221184001.928922-1-venkatx.sivaramakrishnan@intel.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Thu, Dec 21, 2023 at 06:40:01PM +0000, Sivaramakrishnan Venkat wrote: > Incorrect ptypes list causes buffer overflow for Address Sanitizer > run.Previously, the last element in the ptypes lists to be > "RTE_PTYPE_UNKNOWN" for rte_eth_dev_get_supported_ptypes(), but this was > not clearly documented and many PMDs did not follow this implementation. > Instead, the dev_supported_ptypes_get() function pointer now returns the > number of elements to eliminate the need for "RTE_PTYPE_UNKNOWN" > as the last item. > > Fixes: 4790935 ("ethdev: make device operations struct private") > Cc: ferruh.yigit@intel.com > CC: stable@dpdk.org > > -- > V3: Rework function pointer to return number of elements and remove > the need for RTE_PTYPE_UNKNOWN in list > > Signed-off-by: Sivaramakrishnan Venkat > --- > drivers/net/atlantic/atl_ethdev.c | 13 ++++++++----- > drivers/net/axgbe/axgbe_ethdev.c | 13 ++++++++----- > drivers/net/bnxt/bnxt_ethdev.c | 7 ++++--- > drivers/net/cnxk/cnxk_ethdev.h | 3 ++- > drivers/net/cnxk/cnxk_lookup.c | 7 ++++--- > drivers/net/cpfl/cpfl_ethdev.c | 7 ++++--- > drivers/net/cxgbe/cxgbe_ethdev.c | 10 ++++++---- > drivers/net/cxgbe/cxgbe_pfvf.h | 3 ++- > drivers/net/dpaa/dpaa_ethdev.c | 7 +++++-- > drivers/net/dpaa2/dpaa2_ethdev.c | 10 ++++++---- > drivers/net/e1000/igb_ethdev.c | 13 ++++++++----- > drivers/net/enetc/enetc_ethdev.c | 7 ++++--- > drivers/net/enic/enic_ethdev.c | 17 ++++++++++------- > drivers/net/failsafe/failsafe_ops.c | 5 +++-- > drivers/net/fm10k/fm10k_ethdev.c | 15 +++++++++------ > drivers/net/hns3/hns3_rxtx.c | 16 +++++++++------- > drivers/net/hns3/hns3_rxtx.h | 3 ++- > drivers/net/i40e/i40e_rxtx.c | 11 +++++++---- > drivers/net/i40e/i40e_rxtx.h | 3 ++- > drivers/net/iavf/iavf_ethdev.c | 10 ++++++---- > drivers/net/ice/ice_dcf_ethdev.c | 7 ++++--- > drivers/net/ice/ice_rxtx.c | 23 ++++++++++++++--------- > drivers/net/ice/ice_rxtx.h | 3 ++- > drivers/net/idpf/idpf_ethdev.c | 7 ++++--- > drivers/net/igc/igc_ethdev.c | 10 ++++++---- > drivers/net/ionic/ionic_rxtx.c | 7 ++++--- > drivers/net/ionic/ionic_rxtx.h | 3 ++- > drivers/net/ixgbe/ixgbe_ethdev.c | 18 ++++++++++++------ > drivers/net/mlx4/mlx4.h | 3 ++- > drivers/net/mlx4/mlx4_ethdev.c | 17 ++++++++++------- > drivers/net/mlx5/mlx5.h | 3 ++- > drivers/net/mlx5/mlx5_ethdev.c | 11 +++++++---- > drivers/net/netvsc/hn_var.h | 3 ++- > drivers/net/netvsc/hn_vf.c | 5 +++-- > drivers/net/nfp/nfp_net_common.c | 12 +++++++++--- > drivers/net/nfp/nfp_net_common.h | 3 ++- > drivers/net/ngbe/ngbe_ethdev.c | 9 ++++++--- > drivers/net/ngbe/ngbe_ethdev.h | 3 ++- > drivers/net/ngbe/ngbe_ptypes.c | 3 ++- > drivers/net/ngbe/ngbe_ptypes.h | 2 +- > drivers/net/octeontx/octeontx_ethdev.c | 11 +++++++---- > drivers/net/pfe/pfe_ethdev.c | 8 ++++++-- > drivers/net/qede/qede_ethdev.c | 11 +++++++---- > drivers/net/sfc/sfc_dp_rx.h | 2 +- > drivers/net/sfc/sfc_ef10.h | 3 ++- > drivers/net/sfc/sfc_ef100_rx.c | 7 ++++--- > drivers/net/sfc/sfc_ef10_rx.c | 11 ++++++----- > drivers/net/sfc/sfc_ethdev.c | 5 +++-- > drivers/net/sfc/sfc_rx.c | 7 ++++--- > drivers/net/tap/rte_eth_tap.c | 4 +++- > drivers/net/thunderx/nicvf_ethdev.c | 4 +++- > drivers/net/txgbe/txgbe_ethdev.c | 9 ++++++--- > drivers/net/txgbe/txgbe_ethdev.h | 3 ++- > drivers/net/txgbe/txgbe_ptypes.c | 6 +++--- > drivers/net/txgbe/txgbe_ptypes.h | 2 +- > drivers/net/vmxnet3/vmxnet3_ethdev.c | 14 +++++++++----- > lib/ethdev/ethdev_driver.h | 3 ++- > lib/ethdev/rte_ethdev.c | 10 ++++++---- > 58 files changed, 280 insertions(+), 172 deletions(-) > > diff --git a/drivers/net/atlantic/atl_ethdev.c b/drivers/net/atlantic/atl_ethdev.c > index 3a028f4290..d0d9e121db 100644 > --- a/drivers/net/atlantic/atl_ethdev.c > +++ b/drivers/net/atlantic/atl_ethdev.c > @@ -43,7 +43,8 @@ static int atl_dev_stats_reset(struct rte_eth_dev *dev); > static int atl_fw_version_get(struct rte_eth_dev *dev, char *fw_version, > size_t fw_size); > > -static const uint32_t *atl_dev_supported_ptypes_get(struct rte_eth_dev *dev); > +static const uint32_t *atl_dev_supported_ptypes_get(struct rte_eth_dev *dev, > + uint32_t *no_of_elements); based on the code that follows no_of_elements should probably be type size_t * because the resulting type of the expression using RTE_DIM. clearly it will never overflow uint32_t i suppose you could explicitly cast to make it clear the potential truncation is on purpose. > > static int atl_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu); > > @@ -1132,7 +1133,8 @@ atl_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) > } > > static const uint32_t * > -atl_dev_supported_ptypes_get(struct rte_eth_dev *dev) > +atl_dev_supported_ptypes_get(struct rte_eth_dev *dev, > + uint32_t *no_of_elements) > { > static const uint32_t ptypes[] = { > RTE_PTYPE_L2_ETHER, > @@ -1143,12 +1145,13 @@ atl_dev_supported_ptypes_get(struct rte_eth_dev *dev) > RTE_PTYPE_L4_TCP, > RTE_PTYPE_L4_UDP, > RTE_PTYPE_L4_SCTP, > - RTE_PTYPE_L4_ICMP, > - RTE_PTYPE_UNKNOWN > + RTE_PTYPE_L4_ICMP > }; > > - if (dev->rx_pkt_burst == atl_recv_pkts) > + if (dev->rx_pkt_burst == atl_recv_pkts) { > + *no_of_elements = RTE_DIM(ptypes); ^^^^^^^^^^^^^^^ <-- is T = size_t > return ptypes; > + } > > return NULL; > }