From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by dpdk.org (Postfix) with ESMTP id 87A00374E for ; Thu, 14 Mar 2019 17:20:51 +0100 (CET) Received: by mail-pg1-f174.google.com with SMTP id b2so4300087pgl.9 for ; Thu, 14 Mar 2019 09:20:51 -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=OxsS1y+lJoAfGCVtmgZtgubcpj0Y87zYLw+OW7KwBH0=; b=vCoH7ckU0bp7v0J/sQ3Cxv1Kze7jJvQzjYSGooP0JKTpgCz8D6N0niaM+hEFLPw0+c rWewqupA5KuzBh5nfEKQ6G+Fawxeo29oo86/OXVTm37nzM9nn93NW5WIzds+u8C9sXuL jP2tzUitTIerEA6BUQ9vX/eykO0OEsJ6fGbq2SZzARQhtSVdIFHT0zoCd0Ondsdcnqkf /8JIwbVjgSr6Kgh6sO9QvKuc0wx1bNlJVauUkgx0hmLn6tvE0mB8zOT8z1KneyOJUjf1 vJLkpV6tuRPaN1MiKZCrmbId6cdD8Ort4QkZlAbHdPExufggGH80Dbrl23Imfn9gEdip lKow== 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=OxsS1y+lJoAfGCVtmgZtgubcpj0Y87zYLw+OW7KwBH0=; b=SHmfhS12c6/E343qpbF+tYcM25OiTUxL3aeQpoQZQ+ttdDyQwd6GZpVn8yxME99KVU JNacO5VFQVlLIAiH+pSDr9I6Wf7LNkusD0YczhEthTeYk9HRI4iDtKdsLWgo1shY9uy8 bDS+SK6wDdq29L+xfgVgQPTbEy1WpBonOB+d3SStsYLvDuxeIBQM3S1y5ETdOhBMizTr mtNNr4GNvMa/rVU8zmjPXn1Cxvh3EbZhFM/ALgtVbUfFOj8g5O81gRDnCKYcgU4Rpb1I 7XlSYg2lVN/jewYCBQPYl/qtmpWOACpqRAxKYRENn9CcP+OO36pX6WEQi/mmYxgzFvY9 oSyg== X-Gm-Message-State: APjAAAUz4aVSj1n0NMwsuXZoxu2RD0ByJwOnIac9+1S2fHIp9M6JfJ9J nfSXADDHorROOW4U+46gVBU0IwclCvaXDQ== X-Google-Smtp-Source: APXvYqzjXiHnDCKkgd0VBqUohbl/6xdsbTzIfjgz2tUO/k8Qd40zrESmNhv4rLd3/lFVBKxuEZayFQ== X-Received: by 2002:a62:1b92:: with SMTP id b140mr50935029pfb.159.1552580450485; Thu, 14 Mar 2019 09:20:50 -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 f10sm18478784pgo.55.2019.03.14.09.20.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Mar 2019 09:20:49 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Thu, 14 Mar 2019 09:20:47 -0700 Message-Id: <20190314162047.20375-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.17.1 Subject: [dpdk-dev] [PATCH v3] 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:20:51 -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 --- v3 -- fix whitespace issue 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..cf69daaf3224 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 2C1CEA0096 for ; Thu, 14 Mar 2019 17:20:54 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 386094C99; Thu, 14 Mar 2019 17:20:53 +0100 (CET) Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by dpdk.org (Postfix) with ESMTP id 87A00374E for ; Thu, 14 Mar 2019 17:20:51 +0100 (CET) Received: by mail-pg1-f174.google.com with SMTP id b2so4300087pgl.9 for ; Thu, 14 Mar 2019 09:20:51 -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=OxsS1y+lJoAfGCVtmgZtgubcpj0Y87zYLw+OW7KwBH0=; b=vCoH7ckU0bp7v0J/sQ3Cxv1Kze7jJvQzjYSGooP0JKTpgCz8D6N0niaM+hEFLPw0+c rWewqupA5KuzBh5nfEKQ6G+Fawxeo29oo86/OXVTm37nzM9nn93NW5WIzds+u8C9sXuL jP2tzUitTIerEA6BUQ9vX/eykO0OEsJ6fGbq2SZzARQhtSVdIFHT0zoCd0Ondsdcnqkf /8JIwbVjgSr6Kgh6sO9QvKuc0wx1bNlJVauUkgx0hmLn6tvE0mB8zOT8z1KneyOJUjf1 vJLkpV6tuRPaN1MiKZCrmbId6cdD8Ort4QkZlAbHdPExufggGH80Dbrl23Imfn9gEdip lKow== 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=OxsS1y+lJoAfGCVtmgZtgubcpj0Y87zYLw+OW7KwBH0=; b=SHmfhS12c6/E343qpbF+tYcM25OiTUxL3aeQpoQZQ+ttdDyQwd6GZpVn8yxME99KVU JNacO5VFQVlLIAiH+pSDr9I6Wf7LNkusD0YczhEthTeYk9HRI4iDtKdsLWgo1shY9uy8 bDS+SK6wDdq29L+xfgVgQPTbEy1WpBonOB+d3SStsYLvDuxeIBQM3S1y5ETdOhBMizTr mtNNr4GNvMa/rVU8zmjPXn1Cxvh3EbZhFM/ALgtVbUfFOj8g5O81gRDnCKYcgU4Rpb1I 7XlSYg2lVN/jewYCBQPYl/qtmpWOACpqRAxKYRENn9CcP+OO36pX6WEQi/mmYxgzFvY9 oSyg== X-Gm-Message-State: APjAAAUz4aVSj1n0NMwsuXZoxu2RD0ByJwOnIac9+1S2fHIp9M6JfJ9J nfSXADDHorROOW4U+46gVBU0IwclCvaXDQ== X-Google-Smtp-Source: APXvYqzjXiHnDCKkgd0VBqUohbl/6xdsbTzIfjgz2tUO/k8Qd40zrESmNhv4rLd3/lFVBKxuEZayFQ== X-Received: by 2002:a62:1b92:: with SMTP id b140mr50935029pfb.159.1552580450485; Thu, 14 Mar 2019 09:20:50 -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 f10sm18478784pgo.55.2019.03.14.09.20.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Mar 2019 09:20:49 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Thu, 14 Mar 2019 09:20:47 -0700 Message-Id: <20190314162047.20375-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.17.1 Subject: [dpdk-dev] [PATCH v3] 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: <20190314162047.jSMoU5uxgeL34HYH6EBaOTq6yz7YHTOUXviw4Qpyac4@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 --- v3 -- fix whitespace issue 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..cf69daaf3224 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