Blame SOURCES/0124-ip-6-tunnel-Avoid-copying-user-supplied-interface-na.patch

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