From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) by dpdk.org (Postfix) with ESMTP id A71971BB69 for ; Fri, 11 Jan 2019 21:35:31 +0100 (CET) Received: by mail-pl1-f194.google.com with SMTP id y1so7239873plp.9 for ; Fri, 11 Jan 2019 12:35:31 -0800 (PST) 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:in-reply-to:references :mime-version:content-transfer-encoding; bh=sm8oylN+wibegG576IC3px05Y+1N1dPep4LHHEUGScU=; b=HK/Y6KrRe4sCA8gl0wu8dVQ/5t5TCKBRnu+RW5D+pryFh6qgt3ZA1CG8h1AG4sO58q J2Mxbr/NzoKO1tZsztY3DTEsbc35tCLw+j+5e00wUMTMHELgxSVJD/+KC902eENzEVcz mDB4kRT4DzFM7HQQvWRhMF/9wLxPNGHNr6QEb8wdA2QppY9HvTBTndU4uKmm9Io3D6Kz 7+msuFEJ1H7rgNcozf2U1Ul9MAwaAt0p41AtPsWrFygXrDmCXRBtgsl7TpqzjstZp5sC YeLdOMYwYrApCH3BJ2UYAobEfYd/f2Kd1W9bAhlbcZmPAGxYfGZtOxtVuYMpUOPYjnFp 8tfA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=sm8oylN+wibegG576IC3px05Y+1N1dPep4LHHEUGScU=; b=F62lSd3glWNogqQGseV8B/fM3bdzyqWzyYcUYfjTv8In2HhBdgY0+njH7NzD/Q1jFV s2a1S83xY0i9T7WkGw4HfNDjY3xD8G7z2rJ6TSl8gOnCkI6EWWJJQaJq6fs/EHhMsd5c XRCdxEMNAVrs84KZbSFKWwOE55AcRBMtvKoJMchhIygrvr58PUaDfue/KfLYF/mRblh/ ZgBjSfb4iMG7GUYOYnZIOPKd8z7xFpouNRgSKTw+JoROfafV043Zq7W1cjUvlYW3+0GU 8MoGCa8DG486jYh5BlhuPV8yyreEhW+Sd83+rYh+KQWx196Aw/XJ8DGBtCSS+yGctpLZ qLrg== X-Gm-Message-State: AJcUukdfQQ7bJyLOYOYm6uspTIqdWgGS7z2rJ0YwfMaPCImThJIgyoqg Tg+pggIAcrDVhAKl2N+JBNRN0w== X-Google-Smtp-Source: ALg8bN7EzFCFmRalrkAtyM0iS/qmI5zXG65IeIj1Zp6U3SSd6g/NV3ZN/IaqFL8foHeA30e+aLEmHQ== X-Received: by 2002:a17:902:e085:: with SMTP id cb5mr15880514plb.24.1547238930599; Fri, 11 Jan 2019 12:35:30 -0800 (PST) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id f32sm96610438pgf.80.2019.01.11.12.35.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Jan 2019 12:35:29 -0800 (PST) From: Stephen Hemminger To: keith.wiles@intel.com Cc: dev@dpdk.org, Stephen Hemminger Date: Fri, 11 Jan 2019 12:35:16 -0800 Message-Id: <20190111203520.19944-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190111203520.19944-1-stephen@networkplumber.org> References: <20190111180659.5972-1-stephen@networkplumber.org> <20190111203520.19944-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2 3/7] net/tap: check interface name in kvargs 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: Fri, 11 Jan 2019 20:35:32 -0000 If interface name is passed to remote or iface then check the length and for invalid characters. This avoids problems where name gets truncated or rejected by kernel. Signed-off-by: Stephen Hemminger Acked-by Keith Wiles --- drivers/net/tap/rte_eth_tap.c | 38 +++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c index 11e402e42bd0..d8e9ede7ac7c 100644 --- a/drivers/net/tap/rte_eth_tap.c +++ b/drivers/net/tap/rte_eth_tap.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -1884,6 +1885,24 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name, return -EINVAL; } +/* make sure name is a possible Linux network device name */ +static bool +is_valid_iface(const char *name) +{ + if (*name == '\0') + return false; + + if (strnlen(name, IFNAMSIZ) == IFNAMSIZ) + return false; + + while (*name) { + if (*name == '/' || *name == ':' || isspace(*name)) + return false; + name++; + } + return true; +} + static int set_interface_name(const char *key __rte_unused, const char *value, @@ -1891,12 +1910,17 @@ set_interface_name(const char *key __rte_unused, { char *name = (char *)extra_args; - if (value) + if (value) { + if (!is_valid_iface(value)) { + TAP_LOG(ERR, "TAP invalid remote interface name (%s)", + value); + return -1; + } strlcpy(name, value, RTE_ETH_NAME_MAX_LEN); - else + } else { snprintf(name, RTE_ETH_NAME_MAX_LEN, "%s%d", DEFAULT_TAP_NAME, tap_unit - 1); - + } return 0; } @@ -1907,8 +1931,14 @@ set_remote_iface(const char *key __rte_unused, { char *name = (char *)extra_args; - if (value) + if (value) { + if (!is_valid_iface(value)) { + TAP_LOG(ERR, "TAP invalid remote interface name (%s)", + value); + return -1; + } strlcpy(name, value, RTE_ETH_NAME_MAX_LEN); + } return 0; } -- 2.20.1