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

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