From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by dpdk.org (Postfix) with ESMTP id BEC4D4C96 for ; Thu, 14 Mar 2019 17:17:39 +0100 (CET) Received: by mail-pf1-f195.google.com with SMTP id r15so1406035pfn.9 for ; Thu, 14 Mar 2019 09:17:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:reply-to; bh=JST/0p3t7+iqCyyGgtviykLjmmBKvV62AqBe2KNOY+0=; b=cUSClT79OoDGKJGraLrc7Y2tDURe+bqKymWqAXs8H7zNB7j1dOAalmC5j0K5t3oGjJ 5DVFy2P7I2kLSL+U/E9eE8687JemI0P2B9ufAxM+Vat39FoukzQBY1F4J0kPYjRlskef taIcp6DbduNDn2ULxMYUYAY3tWdZwPKLAwlRIFm7J+HTIwi9USwXCNr7Vazg+JnuYFWW LGq/MQ46vEH40UekF1ujbqQDZsXISeIYfEQA+n8RLVqCN1snhEvDKl2YOH9cWHBB6FC7 hC9FK+epkRgejGMNO/810QPiXN7A+CYP7vqlmKkrh3iSASZ6MzetQ3Fa1vqriWm72vZE 54VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JST/0p3t7+iqCyyGgtviykLjmmBKvV62AqBe2KNOY+0=; b=K3xnCs6ipBrCEWmts9ZeLK6F9wcCsgA1xuvlNGlXNnKFMDFxmlv/pmWF9h1DR68+AW h6SuSp/CPXXk/sDlkxXlt+uvzhc42OEewnu3lMMOGor4BHpasgi1UDOgTOr2TAlSEFnE ficXnyA9Aa1OtgW8V/3YMNcDHlLpxpI/Pvbi+wKXJ7fw2Y4oen4mWMibKss4zM7dOEpR 3pYyo/koZPTSb45CszFlJCc7K8AzZylh7xxsiF+naME8BZkOnK64l+PUKumK3oI91OYH ZR28MtzuJSFBS10KiMH3n6qL+kOoMlY3abokGSO2Ec3lVcuyWvHDDC/ThqZ7sjXAZYLw JU0g== X-Gm-Message-State: APjAAAUgm6NhY1x3I+r0IKOubcP8R2HyxGDUguAPNyktO1BogjUixf+d 4tt0+zKTaQVw9ZNGAB8h/3Apg9n+ErKY0g== X-Google-Smtp-Source: APXvYqwTNIi8OK3mdi+Px3cswHxEwRPWMuhDHt7MYigwIazCohCiDDAQEn76kop7TBWTgrYAEcHpgg== X-Received: by 2002:a63:4146:: with SMTP id o67mr32369468pga.122.1552580258568; Thu, 14 Mar 2019 09:17:38 -0700 (PDT) Received: from shemminger-XPS-13-9360.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id q13sm19786027pgh.24.2019.03.14.09.17.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Mar 2019 09:17:37 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Thu, 14 Mar 2019 09:17:30 -0700 Message-Id: <20190314161730.20016-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.17.1 Subject: [dpdk-dev] [PATCH v2] ethdev: check for invalid device name X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: 20190311181544.15646-1-stephen@networkplumber.org List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Mar 2019 16:17:40 -0000 Do not allow creating a ethernet device with a name over the allowed maximum (or zero length). This is safer than silently truncating which is what happens now. Signed-off-by: Stephen Hemminger Acked-by: Andrew Rybchenko --- v2 - fix zero length name test lib/librte_ethdev/rte_ethdev.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index 85c1794968dd..b19df3061d54 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -438,6 +438,18 @@ rte_eth_dev_allocate(const char *name) { uint16_t port_id; struct rte_eth_dev *eth_dev = NULL; + size_t name_len; + + name_len = strnlen(name, RTE_ETH_NAME_MAX_LEN); + if (name_len == 0) { + RTE_ETHDEV_LOG(ERR, "Zero length Ethernet device name\n"); + return NULL; + } + + if (name_len >= RTE_ETH_NAME_MAX_LEN) { + RTE_ETHDEV_LOG(ERR, "Ethernet device name is too long\n"); + return NULL; + } rte_eth_dev_shared_data_prepare(); -- 2.17.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 16DF6A0096 for ; Thu, 14 Mar 2019 17:17:42 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 603F54C99; Thu, 14 Mar 2019 17:17:41 +0100 (CET) Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by dpdk.org (Postfix) with ESMTP id BEC4D4C96 for ; Thu, 14 Mar 2019 17:17:39 +0100 (CET) Received: by mail-pf1-f195.google.com with SMTP id r15so1406035pfn.9 for ; Thu, 14 Mar 2019 09:17:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:reply-to; bh=JST/0p3t7+iqCyyGgtviykLjmmBKvV62AqBe2KNOY+0=; b=cUSClT79OoDGKJGraLrc7Y2tDURe+bqKymWqAXs8H7zNB7j1dOAalmC5j0K5t3oGjJ 5DVFy2P7I2kLSL+U/E9eE8687JemI0P2B9ufAxM+Vat39FoukzQBY1F4J0kPYjRlskef taIcp6DbduNDn2ULxMYUYAY3tWdZwPKLAwlRIFm7J+HTIwi9USwXCNr7Vazg+JnuYFWW LGq/MQ46vEH40UekF1ujbqQDZsXISeIYfEQA+n8RLVqCN1snhEvDKl2YOH9cWHBB6FC7 hC9FK+epkRgejGMNO/810QPiXN7A+CYP7vqlmKkrh3iSASZ6MzetQ3Fa1vqriWm72vZE 54VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JST/0p3t7+iqCyyGgtviykLjmmBKvV62AqBe2KNOY+0=; b=K3xnCs6ipBrCEWmts9ZeLK6F9wcCsgA1xuvlNGlXNnKFMDFxmlv/pmWF9h1DR68+AW h6SuSp/CPXXk/sDlkxXlt+uvzhc42OEewnu3lMMOGor4BHpasgi1UDOgTOr2TAlSEFnE ficXnyA9Aa1OtgW8V/3YMNcDHlLpxpI/Pvbi+wKXJ7fw2Y4oen4mWMibKss4zM7dOEpR 3pYyo/koZPTSb45CszFlJCc7K8AzZylh7xxsiF+naME8BZkOnK64l+PUKumK3oI91OYH ZR28MtzuJSFBS10KiMH3n6qL+kOoMlY3abokGSO2Ec3lVcuyWvHDDC/ThqZ7sjXAZYLw JU0g== X-Gm-Message-State: APjAAAUgm6NhY1x3I+r0IKOubcP8R2HyxGDUguAPNyktO1BogjUixf+d 4tt0+zKTaQVw9ZNGAB8h/3Apg9n+ErKY0g== X-Google-Smtp-Source: APXvYqwTNIi8OK3mdi+Px3cswHxEwRPWMuhDHt7MYigwIazCohCiDDAQEn76kop7TBWTgrYAEcHpgg== X-Received: by 2002:a63:4146:: with SMTP id o67mr32369468pga.122.1552580258568; Thu, 14 Mar 2019 09:17:38 -0700 (PDT) Received: from shemminger-XPS-13-9360.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id q13sm19786027pgh.24.2019.03.14.09.17.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Mar 2019 09:17:37 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Thu, 14 Mar 2019 09:17:30 -0700 Message-Id: <20190314161730.20016-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.17.1 Subject: [dpdk-dev] [PATCH v2] ethdev: check for invalid device name X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: 20190311181544.15646-1-stephen@networkplumber.org List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Content-Type: text/plain; charset="UTF-8" Message-ID: <20190314161730.vVe6DZqxyme8mLdJNPE0KHA0sqkvMsDu0fgmMsLWPkc@z> Do not allow creating a ethernet device with a name over the allowed maximum (or zero length). This is safer than silently truncating which is what happens now. Signed-off-by: Stephen Hemminger Acked-by: Andrew Rybchenko --- v2 - fix zero length name test lib/librte_ethdev/rte_ethdev.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index 85c1794968dd..b19df3061d54 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -438,6 +438,18 @@ rte_eth_dev_allocate(const char *name) { uint16_t port_id; struct rte_eth_dev *eth_dev = NULL; + size_t name_len; + + name_len = strnlen(name, RTE_ETH_NAME_MAX_LEN); + if (name_len == 0) { + RTE_ETHDEV_LOG(ERR, "Zero length Ethernet device name\n"); + return NULL; + } + + if (name_len >= RTE_ETH_NAME_MAX_LEN) { + RTE_ETHDEV_LOG(ERR, "Ethernet device name is too long\n"); + return NULL; + } rte_eth_dev_shared_data_prepare(); -- 2.17.1