From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by dpdk.org (Postfix) with ESMTP id BA8B21BA83 for ; Fri, 11 Jan 2019 19:07:11 +0100 (CET) Received: by mail-pf1-f196.google.com with SMTP id i12so7297236pfo.7 for ; Fri, 11 Jan 2019 10:07:11 -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=OnIijkWFM48+8790vJHj6LYQ6HgJunH3QAcQ5Xu8RJA=; b=oy/00x/ROgL6aEgSkyxruCufKStuZ5GcFGOKmLrAEDj2sJAUx7cM4EKhdumVbqZMwL 2N+nlvcM3WZGo/5w9RetLaFDRVfM8re+uLRrb7HNoHprI1E23TT67tS2JHMfx1j0bnZB ZoLSeSEBGqPqJwxntXuyJj5ZSy2/GP2po7OuvAlUQF0/gB0wnN+G+PS857gYO418sD8k XhpTANIA4TrOQB80LCPunqw0tGPxLftpy8UjUgKtuGXorIzDxX11a1VH5mpOLbvZMIRO B72jPkaoaj4VLy/77TD+FAhSwvqWApkRCxJPQykJ8UJB0hlSe04gFtK+bz++ozGQA88r dVVA== 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=OnIijkWFM48+8790vJHj6LYQ6HgJunH3QAcQ5Xu8RJA=; b=YMqMuJ3rZCe/HN1pwzjaR8dD0qnuc/6Ou3MOp8yMoxPE8f5Ts9EFrIYJHNd9TZKbWO a8W0i6XB+qOYTcBjVoxXKNYQYF2ARJb8Nc3XJ6rFyf20uvhxQoWMEPdExpyk9mCE4+uN P427zrJE2b2qQqpIkNuW22amneKKUynj0z/Dl3mZJUZWhzXOqPJFa30b+flGnJTUF8cp Vbms8EskBlm0fhI1IrjwkKHtJi6EPNSVTHZ9EXOCXoqcxzcnExjyV0PuV+MrsWPSC7mj XYoGvxyg8oWpOnoZls4K55t7G8iR6Rdt4568ilrstY1u63b+lhr6gktUFb92uBSxfLWq S1gw== X-Gm-Message-State: AJcUukd6t0rX4ODKo3gv9B9wSIjlcKKIYPg0OOYXxP01p/qKfgGffRAg DT84aquOhxiuG8wR3tNWOTJpnONTVEg= X-Google-Smtp-Source: ALg8bN5QNVM1mpO1mQCOmlhc+LKLdGzhtNzV+1XBC0jHeIrYOC/aQwo3wPA2qdh4wcV+ftMGeJ0iqg== X-Received: by 2002:a63:8c0d:: with SMTP id m13mr14391479pgd.422.1547230030258; Fri, 11 Jan 2019 10:07:10 -0800 (PST) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id n186sm107213303pfn.137.2019.01.11.10.07.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Jan 2019 10:07:09 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Fri, 11 Jan 2019 10:06:56 -0800 Message-Id: <20190111180659.5972-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190111180659.5972-1-stephen@networkplumber.org> References: <20190111180659.5972-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH 3/6] 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 18:07:12 -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 --- drivers/net/tap/rte_eth_tap.c | 37 +++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c index d7f77d664502..6a388eed0dd4 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,23 @@ 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 +1909,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, tun_unit - 1); - + } return 0; } @@ -1907,8 +1930,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