|
|
36cfb7 |
From 74331750f118690ca3c375e52b10272b992320e7 Mon Sep 17 00:00:00 2001
|
|
|
36cfb7 |
From: Andrea Claudi <aclaudi@redhat.com>
|
|
|
36cfb7 |
Date: Mon, 29 Apr 2019 20:09:13 +0200
|
|
|
36cfb7 |
Subject: [PATCH] ip{6, }tunnel: Avoid copying user-supplied interface name
|
|
|
36cfb7 |
around
|
|
|
36cfb7 |
|
|
|
36cfb7 |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1465646
|
|
|
36cfb7 |
Upstream Status: iproute2.git commit 26111ab1dba82
|
|
|
36cfb7 |
|
|
|
36cfb7 |
commit 26111ab1dba820421ccaf283ac097a79b95023a2
|
|
|
36cfb7 |
Author: Phil Sutter <phil@nwl.cc>
|
|
|
36cfb7 |
Date: Mon Oct 2 13:46:35 2017 +0200
|
|
|
36cfb7 |
|
|
|
36cfb7 |
ip{6, }tunnel: Avoid copying user-supplied interface name around
|
|
|
36cfb7 |
|
|
|
36cfb7 |
In both files' parse_args() functions as well as in iptunnel's do_prl()
|
|
|
36cfb7 |
and do_6rd() functions, a user-supplied 'dev' parameter is uselessly
|
|
|
36cfb7 |
copied into a temporary buffer before passing it to ll_name_to_index()
|
|
|
36cfb7 |
or copying into a struct ifreq. Avoid this by just caching the argv
|
|
|
36cfb7 |
pointer value until the later lookup/strcpy.
|
|
|
36cfb7 |
|
|
|
36cfb7 |
Signed-off-by: Phil Sutter <phil@nwl.cc>
|
|
|
36cfb7 |
---
|
|
|
36cfb7 |
ip/ip6tunnel.c | 6 +++---
|
|
|
36cfb7 |
ip/iptunnel.c | 22 +++++++++-------------
|
|
|
36cfb7 |
2 files changed, 12 insertions(+), 16 deletions(-)
|
|
|
36cfb7 |
|
|
|
36cfb7 |
diff --git a/ip/ip6tunnel.c b/ip/ip6tunnel.c
|
|
|
36cfb7 |
index b4a7def144226..c12d700e74189 100644
|
|
|
36cfb7 |
--- a/ip/ip6tunnel.c
|
|
|
36cfb7 |
+++ b/ip/ip6tunnel.c
|
|
|
36cfb7 |
@@ -136,7 +136,7 @@ static void print_tunnel(struct ip6_tnl_parm2 *p)
|
|
|
36cfb7 |
static int parse_args(int argc, char **argv, int cmd, struct ip6_tnl_parm2 *p)
|
|
|
36cfb7 |
{
|
|
|
36cfb7 |
int count = 0;
|
|
|
36cfb7 |
- char medium[IFNAMSIZ] = {};
|
|
|
36cfb7 |
+ const char *medium = NULL;
|
|
|
36cfb7 |
|
|
|
36cfb7 |
while (argc > 0) {
|
|
|
36cfb7 |
if (strcmp(*argv, "mode") == 0) {
|
|
|
36cfb7 |
@@ -180,7 +180,7 @@ static int parse_args(int argc, char **argv, int cmd, struct ip6_tnl_parm2 *p)
|
|
|
36cfb7 |
memcpy(&p->laddr, &laddr.data, sizeof(p->laddr));
|
|
|
36cfb7 |
} else if (strcmp(*argv, "dev") == 0) {
|
|
|
36cfb7 |
NEXT_ARG();
|
|
|
36cfb7 |
- strncpy(medium, *argv, IFNAMSIZ - 1);
|
|
|
36cfb7 |
+ medium = *argv;
|
|
|
36cfb7 |
} else if (strcmp(*argv, "encaplimit") == 0) {
|
|
|
36cfb7 |
NEXT_ARG();
|
|
|
36cfb7 |
if (strcmp(*argv, "none") == 0) {
|
|
|
36cfb7 |
@@ -285,7 +285,7 @@ static int parse_args(int argc, char **argv, int cmd, struct ip6_tnl_parm2 *p)
|
|
|
36cfb7 |
count++;
|
|
|
36cfb7 |
argc--; argv++;
|
|
|
36cfb7 |
}
|
|
|
36cfb7 |
- if (medium[0]) {
|
|
|
36cfb7 |
+ if (medium) {
|
|
|
36cfb7 |
p->link = ll_name_to_index(medium);
|
|
|
36cfb7 |
if (p->link == 0) {
|
|
|
36cfb7 |
fprintf(stderr, "Cannot find device \"%s\"\n", medium);
|
|
|
36cfb7 |
diff --git a/ip/iptunnel.c b/ip/iptunnel.c
|
|
|
36cfb7 |
index 105d0f5576f1a..0acfd0793d3cd 100644
|
|
|
36cfb7 |
--- a/ip/iptunnel.c
|
|
|
36cfb7 |
+++ b/ip/iptunnel.c
|
|
|
36cfb7 |
@@ -60,7 +60,7 @@ static void set_tunnel_proto(struct ip_tunnel_parm *p, int proto)
|
|
|
36cfb7 |
static int parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p)
|
|
|
36cfb7 |
{
|
|
|
36cfb7 |
int count = 0;
|
|
|
36cfb7 |
- char medium[IFNAMSIZ] = {};
|
|
|
36cfb7 |
+ const char *medium = NULL;
|
|
|
36cfb7 |
int isatap = 0;
|
|
|
36cfb7 |
|
|
|
36cfb7 |
memset(p, 0, sizeof(*p));
|
|
|
36cfb7 |
@@ -139,7 +139,7 @@ static int parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p)
|
|
|
36cfb7 |
p->iph.saddr = htonl(INADDR_ANY);
|
|
|
36cfb7 |
} else if (strcmp(*argv, "dev") == 0) {
|
|
|
36cfb7 |
NEXT_ARG();
|
|
|
36cfb7 |
- strncpy(medium, *argv, IFNAMSIZ - 1);
|
|
|
36cfb7 |
+ medium = *argv;
|
|
|
36cfb7 |
} else if (strcmp(*argv, "ttl") == 0 ||
|
|
|
36cfb7 |
strcmp(*argv, "hoplimit") == 0 ||
|
|
|
36cfb7 |
strcmp(*argv, "hlim") == 0) {
|
|
|
36cfb7 |
@@ -216,7 +216,7 @@ static int parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p)
|
|
|
36cfb7 |
}
|
|
|
36cfb7 |
}
|
|
|
36cfb7 |
|
|
|
36cfb7 |
- if (medium[0]) {
|
|
|
36cfb7 |
+ if (medium) {
|
|
|
36cfb7 |
p->link = ll_name_to_index(medium);
|
|
|
36cfb7 |
if (p->link == 0) {
|
|
|
36cfb7 |
fprintf(stderr, "Cannot find device \"%s\"\n", medium);
|
|
|
36cfb7 |
@@ -465,9 +465,8 @@ static int do_prl(int argc, char **argv)
|
|
|
36cfb7 |
{
|
|
|
36cfb7 |
struct ip_tunnel_prl p = {};
|
|
|
36cfb7 |
int count = 0;
|
|
|
36cfb7 |
- int devname = 0;
|
|
|
36cfb7 |
int cmd = 0;
|
|
|
36cfb7 |
- char medium[IFNAMSIZ] = {};
|
|
|
36cfb7 |
+ const char *medium = NULL;
|
|
|
36cfb7 |
|
|
|
36cfb7 |
while (argc > 0) {
|
|
|
36cfb7 |
if (strcmp(*argv, "prl-default") == 0) {
|
|
|
36cfb7 |
@@ -488,8 +487,7 @@ static int do_prl(int argc, char **argv)
|
|
|
36cfb7 |
count++;
|
|
|
36cfb7 |
} else if (strcmp(*argv, "dev") == 0) {
|
|
|
36cfb7 |
NEXT_ARG();
|
|
|
36cfb7 |
- strncpy(medium, *argv, IFNAMSIZ-1);
|
|
|
36cfb7 |
- devname++;
|
|
|
36cfb7 |
+ medium = *argv;
|
|
|
36cfb7 |
} else {
|
|
|
36cfb7 |
fprintf(stderr,
|
|
|
36cfb7 |
"Invalid PRL parameter \"%s\"\n", *argv);
|
|
|
36cfb7 |
@@ -502,7 +500,7 @@ static int do_prl(int argc, char **argv)
|
|
|
36cfb7 |
}
|
|
|
36cfb7 |
argc--; argv++;
|
|
|
36cfb7 |
}
|
|
|
36cfb7 |
- if (devname == 0) {
|
|
|
36cfb7 |
+ if (!medium) {
|
|
|
36cfb7 |
fprintf(stderr, "Must specify device\n");
|
|
|
36cfb7 |
exit(-1);
|
|
|
36cfb7 |
}
|
|
|
36cfb7 |
@@ -513,9 +511,8 @@ static int do_prl(int argc, char **argv)
|
|
|
36cfb7 |
static int do_6rd(int argc, char **argv)
|
|
|
36cfb7 |
{
|
|
|
36cfb7 |
struct ip_tunnel_6rd ip6rd = {};
|
|
|
36cfb7 |
- int devname = 0;
|
|
|
36cfb7 |
int cmd = 0;
|
|
|
36cfb7 |
- char medium[IFNAMSIZ] = {};
|
|
|
36cfb7 |
+ const char *medium = NULL;
|
|
|
36cfb7 |
inet_prefix prefix;
|
|
|
36cfb7 |
|
|
|
36cfb7 |
while (argc > 0) {
|
|
|
36cfb7 |
@@ -537,8 +534,7 @@ static int do_6rd(int argc, char **argv)
|
|
|
36cfb7 |
cmd = SIOCDEL6RD;
|
|
|
36cfb7 |
} else if (strcmp(*argv, "dev") == 0) {
|
|
|
36cfb7 |
NEXT_ARG();
|
|
|
36cfb7 |
- strncpy(medium, *argv, IFNAMSIZ-1);
|
|
|
36cfb7 |
- devname++;
|
|
|
36cfb7 |
+ medium = *argv;
|
|
|
36cfb7 |
} else {
|
|
|
36cfb7 |
fprintf(stderr,
|
|
|
36cfb7 |
"Invalid 6RD parameter \"%s\"\n", *argv);
|
|
|
36cfb7 |
@@ -546,7 +542,7 @@ static int do_6rd(int argc, char **argv)
|
|
|
36cfb7 |
}
|
|
|
36cfb7 |
argc--; argv++;
|
|
|
36cfb7 |
}
|
|
|
36cfb7 |
- if (devname == 0) {
|
|
|
36cfb7 |
+ if (!medium) {
|
|
|
36cfb7 |
fprintf(stderr, "Must specify device\n");
|
|
|
36cfb7 |
exit(-1);
|
|
|
36cfb7 |
}
|
|
|
36cfb7 |
--
|
|
|
e138d9 |
2.21.0
|
|
|
36cfb7 |
|