From patchwork Wed Oct 28 16:27:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bruce Richardson X-Patchwork-Id: 82672 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id D5FDAA04DD; Wed, 28 Oct 2020 17:27:34 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D431D9B04; Wed, 28 Oct 2020 17:27:23 +0100 (CET) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 81DBE72E2; Wed, 28 Oct 2020 17:27:20 +0100 (CET) IronPort-SDR: rl8R4IzT4TUG7Ar+Saq8u4sfk3NQqIVyYcNSsGnLIlJDKiMddaKH2Bq1DGZIbEq0/EUYBQZuPT btR4PekapzIA== X-IronPort-AV: E=McAfee;i="6000,8403,9788"; a="165699131" X-IronPort-AV: E=Sophos;i="5.77,427,1596524400"; d="scan'208";a="165699131" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Oct 2020 09:27:18 -0700 IronPort-SDR: kjaueFKv8qv5y1kdMOPzRwUG+GazdrkIO8T8NSKG9mNw+cQSeYPgoDgdINSGAVzaWcXekEDyYn flRPDSLlLHMg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,427,1596524400"; d="scan'208";a="334787959" Received: from silpixa00399126.ir.intel.com ([10.237.222.4]) by orsmga002.jf.intel.com with ESMTP; 28 Oct 2020 09:27:16 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: Bruce Richardson , stable@dpdk.org, David Hunt , Alan Carew , Pablo de Lara Date: Wed, 28 Oct 2020 16:27:00 +0000 Message-Id: <20201028162702.969509-2-bruce.richardson@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201028162702.969509-1-bruce.richardson@intel.com> References: <20200814110045.217724-1-bruce.richardson@intel.com> <20201028162702.969509-1-bruce.richardson@intel.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 1/3] examples/vm_power_manager: fix string truncation warning 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" When compiling on ubuntu 20.04, a warning was issued about possible truncation of the path string for the power management socket. channel_manager.c: In function ‘add_all_channels’: channel_manager.c:470:41: warning: ‘%s’ directive output may be truncated writing up to 255 bytes into a region of size 90 [-Wformat-truncation=] 470 | sizeof(chan_info->channel_path), "%s%s", | ^~ This can be fixed by adding in an explicit truncation check to the code and handling it appropriately. Fixes: e8ae9b662506 ("examples/vm_power: channel manager and monitor in host") Cc: stable@dpdk.org Signed-off-by: Bruce Richardson Acked-by: David Hunt --- examples/vm_power_manager/channel_manager.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/vm_power_manager/channel_manager.c b/examples/vm_power_manager/channel_manager.c index 74a2a677e..a26315051 100644 --- a/examples/vm_power_manager/channel_manager.c +++ b/examples/vm_power_manager/channel_manager.c @@ -467,9 +467,15 @@ add_all_channels(const char *vm_name) continue; } - snprintf(chan_info->channel_path, + if ((size_t)snprintf(chan_info->channel_path, sizeof(chan_info->channel_path), "%s%s", - CHANNEL_MGR_SOCKET_PATH, dir->d_name); + CHANNEL_MGR_SOCKET_PATH, dir->d_name) + >= sizeof(chan_info->channel_path)) { + RTE_LOG(ERR, CHANNEL_MANAGER, "Pathname too long for channel '%s%s'\n", + CHANNEL_MGR_SOCKET_PATH, dir->d_name); + rte_free(chan_info); + continue; + } if (setup_channel_info(&vm_info, &chan_info, channel_num) < 0) { rte_free(chan_info); From patchwork Wed Oct 28 16:27:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bruce Richardson X-Patchwork-Id: 82673 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id CD34FA04DD; Wed, 28 Oct 2020 17:27:52 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6F296BC64; Wed, 28 Oct 2020 17:27:26 +0100 (CET) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id A39E272E2; Wed, 28 Oct 2020 17:27:22 +0100 (CET) IronPort-SDR: u0f3lWtKy2GxQSOvYyK6oOb6g5xg+5b5YUkaCDcAEJ+dKxXPOmeIpGo8XxC5Fu6Htek2clZKiS C9hMWKxf5lUA== X-IronPort-AV: E=McAfee;i="6000,8403,9788"; a="165699149" X-IronPort-AV: E=Sophos;i="5.77,427,1596524400"; d="scan'208";a="165699149" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Oct 2020 09:27:22 -0700 IronPort-SDR: 2EZT8twnFPfNigHiliRcA6Wy0lO2XrhMN5jRukhU8Hl++BuNPOEGJLQ4d7Ih0RaaS98sGrTwKA qYu5qT8SZOIg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,427,1596524400"; d="scan'208";a="334787986" Received: from silpixa00399126.ir.intel.com ([10.237.222.4]) by orsmga002.jf.intel.com with ESMTP; 28 Oct 2020 09:27:20 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: Bruce Richardson , stable@dpdk.org, Stephen Hemminger , Radu Nicolau , Anatoly Burakov Date: Wed, 28 Oct 2020 16:27:01 +0000 Message-Id: <20201028162702.969509-3-bruce.richardson@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201028162702.969509-1-bruce.richardson@intel.com> References: <20200814110045.217724-1-bruce.richardson@intel.com> <20201028162702.969509-1-bruce.richardson@intel.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 2/3] examples/mp_server: fix snprintf overflow 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" When producing a printable mac address the buffer was appropriately sized for holding the mac address exactly, but the actual snprintf included a '\n' character at the end, which means that the snprintf technically is getting truncated i.e. the \n would not be added due to lack of space. This gets flagged as a problem by modern versions of gcc, e.g. on Ubuntu 20.04. main.c:77:37: warning: ‘__builtin___snprintf_chk’ output truncated before the last format character [-Wformat-truncation=] 77 | "%02x:%02x:%02x:%02x:%02x:%02x\n", | ^ Since the \n is getting stripped anyway, we can fix the issue by just removing it. In the process we can switch to using the standard ethernet address formating function from rte_ether.h. Fixes: af75078fece3 ("first public release") Cc: stable@dpdk.org Cc: Stephen Hemminger Signed-off-by: Bruce Richardson Acked-by: Radu Nicolau --- V2: switched code to use standard formatting function --- .../client_server_mp/mp_server/main.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/examples/multi_process/client_server_mp/mp_server/main.c b/examples/multi_process/client_server_mp/mp_server/main.c index ec7f6b11f..b18e12dd4 100644 --- a/examples/multi_process/client_server_mp/mp_server/main.c +++ b/examples/multi_process/client_server_mp/mp_server/main.c @@ -59,12 +59,17 @@ static struct client_rx_buf *cl_rx_buf; static const char * get_printable_mac_addr(uint16_t port) { - static const char err_address[] = "00:00:00:00:00:00"; - static char addresses[RTE_MAX_ETHPORTS][sizeof(err_address)]; + static const struct rte_ether_addr null_mac; /* static defaults to 0 */ + static char err_address[32]; + static char addresses[RTE_MAX_ETHPORTS][32]; int ret; - if (unlikely(port >= RTE_MAX_ETHPORTS)) + if (unlikely(port >= RTE_MAX_ETHPORTS)) { + if (err_address[0] == '\0') + rte_ether_format_addr(err_address, + sizeof(err_address), &null_mac); return err_address; + } if (unlikely(addresses[port][0]=='\0')){ struct rte_ether_addr mac; ret = rte_eth_macaddr_get(port, &mac); @@ -73,10 +78,8 @@ get_printable_mac_addr(uint16_t port) port, rte_strerror(-ret)); return err_address; } - snprintf(addresses[port], sizeof(addresses[port]), - "%02x:%02x:%02x:%02x:%02x:%02x\n", - mac.addr_bytes[0], mac.addr_bytes[1], mac.addr_bytes[2], - mac.addr_bytes[3], mac.addr_bytes[4], mac.addr_bytes[5]); + rte_ether_format_addr(addresses[port], + sizeof(addresses[port]), &mac); } return addresses[port]; } From patchwork Wed Oct 28 16:27:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bruce Richardson X-Patchwork-Id: 82674 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3030CA04DD; Wed, 28 Oct 2020 17:28:14 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 622CCBE5D; Wed, 28 Oct 2020 17:27:30 +0100 (CET) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id C753449E0; Wed, 28 Oct 2020 17:27:24 +0100 (CET) IronPort-SDR: YAGlN0HxB6AgHsh1KB3eOZul7exBNqliU2GgQkBNUwXjLkKI6gYDlVvmfjqOVkVmo3L3ReqPrr FDeEKuIlur6w== X-IronPort-AV: E=McAfee;i="6000,8403,9788"; a="165699156" X-IronPort-AV: E=Sophos;i="5.77,427,1596524400"; d="scan'208";a="165699156" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Oct 2020 09:27:24 -0700 IronPort-SDR: 6z10H/kwjYjmaA7VRhuC0ZQ6FjCa3th3RDtbzcufGRW/VZxeOg+A86gFr33dmN+mmO25SGLnJ0 8XNAF/mTNR0Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,427,1596524400"; d="scan'208";a="334787994" Received: from silpixa00399126.ir.intel.com ([10.237.222.4]) by orsmga002.jf.intel.com with ESMTP; 28 Oct 2020 09:27:23 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: Bruce Richardson , stable@dpdk.org, Radu Nicolau , Anatoly Burakov Date: Wed, 28 Oct 2020 16:27:02 +0000 Message-Id: <20201028162702.969509-4-bruce.richardson@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201028162702.969509-1-bruce.richardson@intel.com> References: <20200814110045.217724-1-bruce.richardson@intel.com> <20201028162702.969509-1-bruce.richardson@intel.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 3/3] examples/mp_server: clear string truncation warning 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" Compiling with GCC 9.3 on Ubuntu 20.04 gives a warning about possible string truncation when getting the RX queue name: In file included from init.c:36: init.c: In function ‘init’: ../shared/common.h:38:28: warning: ‘%u’ directive output may be truncated writing between 1 and 10 bytes into a region of size 8 [-Wformat-truncation=] 38 | #define MP_CLIENT_RXQ_NAME "MProc_Client_%u_RX" | ^~~~~~~~~~~~~~~~~~~~ ../shared/common.h:52:35: note: in expansion of macro ‘MP_CLIENT_RXQ_NAME’ 52 | snprintf(buffer, sizeof(buffer), MP_CLIENT_RXQ_NAME, id); | ^~~~~~~~~~~~~~~~~~ This is a false positive, as the value of the "id" is limited to 255, being stored in the app as a uint8_t value, removing the possibility of the %u being replaced by anything other then 3 characters max (rather than up to 10 as thought by the compiler). Therefore, the warning can be easily removed by changing the type of the "id" parameter to the local function from "unsigned" to "uint8_t" also, ensuring the compiler is aware of the range limit. Cc: stable@dpdk.org Signed-off-by: Bruce Richardson Acked-by: Radu Nicolau --- examples/multi_process/client_server_mp/shared/common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/multi_process/client_server_mp/shared/common.h b/examples/multi_process/client_server_mp/shared/common.h index 6dd43fcac..76beca010 100644 --- a/examples/multi_process/client_server_mp/shared/common.h +++ b/examples/multi_process/client_server_mp/shared/common.h @@ -43,7 +43,7 @@ struct port_info { * Given the rx queue name template above, get the queue name */ static inline const char * -get_rx_queue_name(unsigned id) +get_rx_queue_name(uint8_t id) { /* buffer for return value. Size calculated by %u being replaced * by maximum 3 digits (plus an extra byte for safety) */