From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by dpdk.org (Postfix) with ESMTP id 1D6881B399 for ; Wed, 20 Mar 2019 18:52:31 +0100 (CET) Received: by mail-pg1-f193.google.com with SMTP id b12so2359418pgk.0 for ; Wed, 20 Mar 2019 10:52:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0hd307KV1uHBn+iar8RePjFlIT4Mrh9T/sRVPUNkzGo=; b=eme6EQs3uDdrZeMcjP4zWaS7DMNnjB/hmCInFiy/JHT0BF0M71b9pXYA/Jw9owCO5U IX0HbM4YaQsnLyCESwxkYEvxM+/gqTvhdtIEcOfyEtwxxMfzELKsIdv8f0dfRirfE1hX F0upbvRZbSHLCWjMwE4H94SU5phj+5nSR/Z9+RN+upeXa5qSpi72/puIRq8hKDaBX4eg z9HwGrA5lsLkwPCGcgncj9CeZ0VojZ58lac9JN7tbvAcEbi6kDzWpGfOQbAIfB8dMkAw bgvisWBStvY1fvsTLf/hUrx2OIWFUVc6jkoc1AmIoDOSCls0jzVjCTMPuJtF7AcijLuh J8EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0hd307KV1uHBn+iar8RePjFlIT4Mrh9T/sRVPUNkzGo=; b=BGTNkESf0oB8+NDncmG3rGK5o3uVEW3uaq8Cxied6A7gO6fscQQmYAIZcocKod8khC lAeBwW6jZG+7pOhhfK9Ocl4hEcdQ662jbcIqBFTp/g3b43tW4M1uHp2wko577D/Dr+54 68fjSriOqDhin8Wo9Kfwhspc6bmwEO02tzeKFdaiGjKBc6xA65QhV6agCm1OVhYr1kse MN6LzVkHJu9maocERuAlRfKB4+q+ZG6/CW6RmPhrm3mCnbMq43v6EKFldiEFcTFmsO8Q nWr8R7xrVTAfkib/QO4M7CsUI63MAl+RLEoZ9c8T+3y70WhDPSYlj7J9Q+3IoM3ZRBcu uLaQ== X-Gm-Message-State: APjAAAUJ4P3vnhLiiorZWD7in4ru5p1aOgeKK+H781l8rQtfdcFm0pei vwHADGH7iI1vFqBkCrEHj56Cmg== X-Google-Smtp-Source: APXvYqy6JiDdyqIJtTZJyYp4WDw5RrdLzanqOY/s3Q/j2kP+8rfstvadTQ6G6toclmz58VhtD/GFCQ== X-Received: by 2002:aa7:85cc:: with SMTP id z12mr8888992pfn.142.1553104350306; Wed, 20 Mar 2019 10:52:30 -0700 (PDT) Received: from shemminger-XPS-13-9360 (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id o2sm6908968pfa.76.2019.03.20.10.52.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Mar 2019 10:52:30 -0700 (PDT) Date: Wed, 20 Mar 2019 10:52:26 -0700 From: Stephen Hemminger To: Ferruh Yigit Cc: 20190311181544.15646-1-stephen@networkplumber.org, dev@dpdk.org, Andrew Rybchenko Message-ID: <20190320105226.58f3d5fc@shemminger-XPS-13-9360> In-Reply-To: <7fffa0cb-1bfc-1ff1-5f1d-15fff4b3ff00@intel.com> References: <20190314162047.20375-1-stephen@networkplumber.org> <7fffa0cb-1bfc-1ff1-5f1d-15fff4b3ff00@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH v3] ethdev: check for invalid device name 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: , X-List-Received-Date: Wed, 20 Mar 2019 17:52:31 -0000 On Wed, 20 Mar 2019 14:28:22 +0000 Ferruh Yigit wrote: > On 3/14/2019 4:20 PM, Stephen Hemminger wrote: > > 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); > > 'strlen' does not check against NULL pointer and it will crash if NULL provided. > > This is internal API, so the input is not completely out of our control but > still as an API if we need to check zero length, shouldn't we check for NULL > pointer as well? Maybe, but none of the other DPDK API's check for NULL in name fields. Probably best to just crash. 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 56781A00E6 for ; Wed, 20 Mar 2019 18:52:33 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id ADA671B3A0; Wed, 20 Mar 2019 18:52:32 +0100 (CET) Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by dpdk.org (Postfix) with ESMTP id 1D6881B399 for ; Wed, 20 Mar 2019 18:52:31 +0100 (CET) Received: by mail-pg1-f193.google.com with SMTP id b12so2359418pgk.0 for ; Wed, 20 Mar 2019 10:52:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0hd307KV1uHBn+iar8RePjFlIT4Mrh9T/sRVPUNkzGo=; b=eme6EQs3uDdrZeMcjP4zWaS7DMNnjB/hmCInFiy/JHT0BF0M71b9pXYA/Jw9owCO5U IX0HbM4YaQsnLyCESwxkYEvxM+/gqTvhdtIEcOfyEtwxxMfzELKsIdv8f0dfRirfE1hX F0upbvRZbSHLCWjMwE4H94SU5phj+5nSR/Z9+RN+upeXa5qSpi72/puIRq8hKDaBX4eg z9HwGrA5lsLkwPCGcgncj9CeZ0VojZ58lac9JN7tbvAcEbi6kDzWpGfOQbAIfB8dMkAw bgvisWBStvY1fvsTLf/hUrx2OIWFUVc6jkoc1AmIoDOSCls0jzVjCTMPuJtF7AcijLuh J8EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0hd307KV1uHBn+iar8RePjFlIT4Mrh9T/sRVPUNkzGo=; b=BGTNkESf0oB8+NDncmG3rGK5o3uVEW3uaq8Cxied6A7gO6fscQQmYAIZcocKod8khC lAeBwW6jZG+7pOhhfK9Ocl4hEcdQ662jbcIqBFTp/g3b43tW4M1uHp2wko577D/Dr+54 68fjSriOqDhin8Wo9Kfwhspc6bmwEO02tzeKFdaiGjKBc6xA65QhV6agCm1OVhYr1kse MN6LzVkHJu9maocERuAlRfKB4+q+ZG6/CW6RmPhrm3mCnbMq43v6EKFldiEFcTFmsO8Q nWr8R7xrVTAfkib/QO4M7CsUI63MAl+RLEoZ9c8T+3y70WhDPSYlj7J9Q+3IoM3ZRBcu uLaQ== X-Gm-Message-State: APjAAAUJ4P3vnhLiiorZWD7in4ru5p1aOgeKK+H781l8rQtfdcFm0pei vwHADGH7iI1vFqBkCrEHj56Cmg== X-Google-Smtp-Source: APXvYqy6JiDdyqIJtTZJyYp4WDw5RrdLzanqOY/s3Q/j2kP+8rfstvadTQ6G6toclmz58VhtD/GFCQ== X-Received: by 2002:aa7:85cc:: with SMTP id z12mr8888992pfn.142.1553104350306; Wed, 20 Mar 2019 10:52:30 -0700 (PDT) Received: from shemminger-XPS-13-9360 (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id o2sm6908968pfa.76.2019.03.20.10.52.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Mar 2019 10:52:30 -0700 (PDT) Date: Wed, 20 Mar 2019 10:52:26 -0700 From: Stephen Hemminger To: Ferruh Yigit Cc: 20190311181544.15646-1-stephen@networkplumber.org, dev@dpdk.org, Andrew Rybchenko Message-ID: <20190320105226.58f3d5fc@shemminger-XPS-13-9360> In-Reply-To: <7fffa0cb-1bfc-1ff1-5f1d-15fff4b3ff00@intel.com> References: <20190314162047.20375-1-stephen@networkplumber.org> <7fffa0cb-1bfc-1ff1-5f1d-15fff4b3ff00@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH v3] ethdev: check for invalid device name 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" Message-ID: <20190320175226.Xa9O4hpc4i1vgP3bt98w1Ua07fe9fSZHiHcE3-ndhPs@z> On Wed, 20 Mar 2019 14:28:22 +0000 Ferruh Yigit wrote: > On 3/14/2019 4:20 PM, Stephen Hemminger wrote: > > 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); > > 'strlen' does not check against NULL pointer and it will crash if NULL provided. > > This is internal API, so the input is not completely out of our control but > still as an API if we need to check zero length, shouldn't we check for NULL > pointer as well? Maybe, but none of the other DPDK API's check for NULL in name fields. Probably best to just crash.