From: "Wiles, Keith" <keith.wiles@intel.com>
To: Stephen Hemminger <stephen@networkplumber.org>
Cc: "dev@dpdk.org" <dev@dpdk.org>
Subject: Re: [dpdk-dev] [PATCH 3/6] net/tap: check interface name in kvargs
Date: Fri, 11 Jan 2019 19:37:00 +0000 [thread overview]
Message-ID: <14FED5CB-5C2B-452D-BD47-6303EF67F90A@intel.com> (raw)
In-Reply-To: <20190111180659.5972-4-stephen@networkplumber.org>
> On Jan 11, 2019, at 12:06 PM, Stephen Hemminger <stephen@networkplumber.org> wrote:
>
> 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 <stephen@networkplumber.org>
> ---
> 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 <linux/if_tun.h>
> #include <linux/if_ether.h>
> #include <fcntl.h>
> +#include <ctype.h>
>
> #include <tap_rss.h>
> #include <rte_eth_tap.h>
> @@ -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)
I am sorry, but the function name must be on the next line as per the style. I know you do not like it, but that is what the style states.
> +{
> + 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);
> -
> + }
This is also a one line else and the style states to remove the {}.
> 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
>
I hate having to be the style police, but until we use something to validate the DPDK coding style (as I posted the uncrustify config last month) we have to keep the style the same or change the DPDK coding standard.
Regards,
Keith
next prev parent reply other threads:[~2019-01-11 19:37 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-11 18:06 [dpdk-dev] [PATCH 0/6] net/tap: fixes and cleanups Stephen Hemminger
2019-01-11 18:06 ` [dpdk-dev] [PATCH 1/6] net/tap: use strlcpy for interface name Stephen Hemminger
2019-01-11 18:06 ` [dpdk-dev] [PATCH 2/6] net/tap: allow full length names Stephen Hemminger
2019-01-11 19:32 ` Wiles, Keith
2019-01-11 19:48 ` Stephen Hemminger
2019-01-11 19:49 ` Wiles, Keith
2019-01-11 18:06 ` [dpdk-dev] [PATCH 3/6] net/tap: check interface name in kvargs Stephen Hemminger
2019-01-11 19:37 ` Wiles, Keith [this message]
2019-01-11 19:49 ` Stephen Hemminger
2019-01-11 19:50 ` Wiles, Keith
2019-01-15 2:01 ` Thomas Monjalon
2019-01-11 22:20 ` Luse, Paul E
2019-01-11 18:06 ` [dpdk-dev] [PATCH 4/6] net/tap: lower the priority of log messages Stephen Hemminger
2019-01-11 18:06 ` [dpdk-dev] [PATCH 5/6] net/tap: let kernel choose tun device name Stephen Hemminger
2019-01-11 19:43 ` Wiles, Keith
2019-01-11 18:06 ` [dpdk-dev] [PATCH 6/6] net/tap: get rid of global tuntap_name Stephen Hemminger
2019-01-11 19:47 ` [dpdk-dev] [PATCH 0/6] net/tap: fixes and cleanups Wiles, Keith
2019-01-11 20:35 ` [dpdk-dev] [PATCH v2 " Stephen Hemminger
2019-01-11 20:35 ` [dpdk-dev] [PATCH v2 1/7] net/tap: use strlcpy for interface name Stephen Hemminger
2019-01-11 20:35 ` [dpdk-dev] [PATCH v2 2/7] net/tap: allow full length names Stephen Hemminger
2019-01-11 20:35 ` [dpdk-dev] [PATCH v2 3/7] net/tap: check interface name in kvargs Stephen Hemminger
2019-01-11 20:35 ` [dpdk-dev] [PATCH v2 4/7] net/tap: lower the priority of log messages Stephen Hemminger
2019-01-11 20:35 ` [dpdk-dev] [PATCH v2 5/7] net/tap: let kernel choose tun device name Stephen Hemminger
2019-01-11 20:35 ` [dpdk-dev] [PATCH v2 6/7] net/tap: get rid of global tuntap_name Stephen Hemminger
2019-01-11 20:35 ` [dpdk-dev] [PATCH v2 7/7] net/tap: don't print pointer in info message Stephen Hemminger
2019-01-14 14:10 ` Ferruh Yigit
2019-01-14 15:07 ` Wiles, Keith
2019-01-14 14:10 ` [dpdk-dev] [PATCH v2 0/6] net/tap: fixes and cleanups Ferruh Yigit
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=14FED5CB-5C2B-452D-BD47-6303EF67F90A@intel.com \
--to=keith.wiles@intel.com \
--cc=dev@dpdk.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).