Blame SOURCES/0020-iplink-check-for-message-truncation-in-iplink_get.patch

be97f7
From 8372b7bb8f7211563d888fdd30e473c161f7d0a0 Mon Sep 17 00:00:00 2001
be97f7
From: Hangbin Liu <haliu@redhat.com>
be97f7
Date: Wed, 8 Nov 2017 14:39:10 +0800
be97f7
Subject: [PATCH] iplink: check for message truncation in iplink_get()
be97f7
be97f7
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1380803
be97f7
Upstream Status: iproute2.git commit 6599162b958e
be97f7
be97f7
commit 6599162b958ea5a43d729df4f30aad515db26ff4
be97f7
Author: Michal Kubecek <mkubecek@suse.cz>
be97f7
Date:   Fri Sep 1 18:39:11 2017 +0200
be97f7
be97f7
    iplink: check for message truncation in iplink_get()
be97f7
be97f7
    If message length exceeds maxlen argument of rtnl_talk(), it is truncated
be97f7
    to maxlen but unlike in the case of truncation to the length of local
be97f7
    buffer in rtnl_talk(), the caller doesn't get any indication of a problem.
be97f7
be97f7
    In particular, iplink_get() passes the truncated message on and parsing it
be97f7
    results in various warnings and sometimes even a segfault (observed with
be97f7
    "ip link show dev ..." for a NIC with 125 VFs).
be97f7
be97f7
    Handle message truncation in iplink_get() the same way as truncation in
be97f7
    rtnl_talk() would be handled: return an error.
be97f7
be97f7
    Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
be97f7
be97f7
Signed-off-by: Hangbin Liu <haliu@redhat.com>
be97f7
---
be97f7
 ip/iplink.c | 5 +++++
be97f7
 1 file changed, 5 insertions(+)
be97f7
be97f7
diff --git a/ip/iplink.c b/ip/iplink.c
be97f7
index da3f9a7..2b2421f 100644
be97f7
--- a/ip/iplink.c
be97f7
+++ b/ip/iplink.c
be97f7
@@ -1031,6 +1031,11 @@ int iplink_get(unsigned int flags, char *name, __u32 filt_mask)
be97f7
 
be97f7
 	if (rtnl_talk(&rth, &req.n, &answer.n, sizeof(answer)) < 0)
be97f7
 		return -2;
be97f7
+	if (answer.n.nlmsg_len > sizeof(answer.buf)) {
be97f7
+		fprintf(stderr, "Message truncated from %u to %lu\n",
be97f7
+			answer.n.nlmsg_len, sizeof(answer.buf));
be97f7
+		return -2;
be97f7
+	}
be97f7
 
be97f7
 	if (brief)
be97f7
 		print_linkinfo_brief(NULL, &answer.n, stdout);
be97f7
-- 
be97f7
1.8.3.1
be97f7