Blame SOURCES/0118-tc-flower-make-use-of-flower_port_attr_type-safe-and.patch

4aca6e
From f4fc39065e5b5f429f158744b4a4e43189b02930 Mon Sep 17 00:00:00 2001
4aca6e
From: Phil Sutter <psutter@redhat.com>
4aca6e
Date: Fri, 17 Mar 2017 13:23:33 +0100
4aca6e
Subject: [PATCH] tc: flower: make use of flower_port_attr_type() safe and
4aca6e
 silent
4aca6e
4aca6e
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1422629
4aca6e
Upstream Status: iproute2.git commit 6bd5b80cdcfbe
4aca6e
4aca6e
commit 6bd5b80cdcfbeb30b79c3ff07ce844f9e4f2c600
4aca6e
Author: Simon Horman <simon.horman@netronome.com>
4aca6e
Date:   Sat Dec 3 09:52:40 2016 +0100
4aca6e
4aca6e
    tc: flower: make use of flower_port_attr_type() safe and silent
4aca6e
4aca6e
    Make use of flower_port_attr_type() safe:
4aca6e
    * flower_port_attr_type() may return a valid index into tb[] or -1.
4aca6e
      Only access tb[] in the case of the former.
4aca6e
    * Do not access null entries in tb[]
4aca6e
4aca6e
    Also make usage silent - it is valid for ip_proto to be invalid,
4aca6e
    for example if it is not specified as part of the filter.
4aca6e
4aca6e
    Fixes: a1fb0d484237 ("tc: flower: Support matching on SCTP ports")
4aca6e
    Signed-off-by: Simon Horman <simon.horman@netronome.com>
4aca6e
---
4aca6e
 tc/f_flower.c | 24 +++++++++++++-----------
4aca6e
 1 file changed, 13 insertions(+), 11 deletions(-)
4aca6e
4aca6e
diff --git a/tc/f_flower.c b/tc/f_flower.c
4aca6e
index cac2802..3f0190f 100644
4aca6e
--- a/tc/f_flower.c
4aca6e
+++ b/tc/f_flower.c
4aca6e
@@ -168,19 +168,17 @@ static int flower_parse_ip_addr(char *str, __be16 eth_type,
4aca6e
 
4aca6e
 static int flower_port_attr_type(__u8 ip_proto, bool is_src)
4aca6e
 {
4aca6e
-	if (ip_proto == IPPROTO_TCP) {
4aca6e
+	if (ip_proto == IPPROTO_TCP)
4aca6e
 		return is_src ? TCA_FLOWER_KEY_TCP_SRC :
4aca6e
 			TCA_FLOWER_KEY_TCP_DST;
4aca6e
-	} else if (ip_proto == IPPROTO_UDP) {
4aca6e
+	else if (ip_proto == IPPROTO_UDP)
4aca6e
 		return is_src ? TCA_FLOWER_KEY_UDP_SRC :
4aca6e
 			TCA_FLOWER_KEY_UDP_DST;
4aca6e
-	} else if (ip_proto == IPPROTO_SCTP) {
4aca6e
+	else if (ip_proto == IPPROTO_SCTP)
4aca6e
 		return is_src ? TCA_FLOWER_KEY_SCTP_SRC :
4aca6e
 			TCA_FLOWER_KEY_SCTP_DST;
4aca6e
-	} else {
4aca6e
-		fprintf(stderr, "Illegal \"ip_proto\" for port\n");
4aca6e
+	else
4aca6e
 		return -1;
4aca6e
-	}
4aca6e
 }
4aca6e
 
4aca6e
 static int flower_parse_port(char *str, __u8 ip_proto, bool is_src,
4aca6e
@@ -562,7 +560,8 @@ static void flower_print_ip_addr(FILE *f, char *name, __be16 eth_type,
4aca6e
 
4aca6e
 static void flower_print_port(FILE *f, char *name, struct rtattr *attr)
4aca6e
 {
4aca6e
-	fprintf(f, "\n  %s %d", name, rta_getattr_be16(attr));
4aca6e
+	if (attr)
4aca6e
+		fprintf(f, "\n  %s %d", name, rta_getattr_be16(attr));
4aca6e
 }
4aca6e
 
4aca6e
 static void flower_print_key_id(FILE *f, const char *name,
4aca6e
@@ -578,6 +577,7 @@ static int flower_print_opt(struct filter_util *qu, FILE *f,
4aca6e
 	struct rtattr *tb[TCA_FLOWER_MAX + 1];
4aca6e
 	__be16 eth_type = 0;
4aca6e
 	__u8 ip_proto = 0xff;
4aca6e
+	int nl_type;
4aca6e
 
4aca6e
 	if (!opt)
4aca6e
 		return 0;
4aca6e
@@ -632,10 +632,12 @@ static int flower_print_opt(struct filter_util *qu, FILE *f,
4aca6e
 			     tb[TCA_FLOWER_KEY_IPV6_SRC],
4aca6e
 			     tb[TCA_FLOWER_KEY_IPV6_SRC_MASK]);
4aca6e
 
4aca6e
-	flower_print_port(f, "dst_port",
4aca6e
-			  tb[flower_port_attr_type(ip_proto, false)]);
4aca6e
-	flower_print_port(f, "src_port",
4aca6e
-			  tb[flower_port_attr_type(ip_proto, true)]);
4aca6e
+	nl_type = flower_port_attr_type(ip_proto, false);
4aca6e
+	if (nl_type >= 0)
4aca6e
+		flower_print_port(f, "dst_port", tb[nl_type]);
4aca6e
+	nl_type = flower_port_attr_type(ip_proto, true);
4aca6e
+	if (nl_type >= 0)
4aca6e
+		flower_print_port(f, "src_port", tb[nl_type]);
4aca6e
 
4aca6e
 	flower_print_ip_addr(f, "enc_dst_ip",
4aca6e
 			     tb[TCA_FLOWER_KEY_ENC_IPV4_DST_MASK] ?
4aca6e
-- 
4aca6e
1.8.3.1
4aca6e