lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1477510208-20292-2-git-send-email-gorcunov@gmail.com>
Date:   Wed, 26 Oct 2016 22:30:07 +0300
From:   Cyrill Gorcunov <gorcunov@...il.com>
To:     netdev@...r.kernel.org
Cc:     Stephen Hemminger <stephen@...workplumber.org>,
        Eric Dumazet <eric.dumazet@...il.com>,
        David Ahern <dsa@...ulusnetworks.com>,
        Andrey Vagin <avagin@...nvz.org>,
        Cyrill Gorcunov <gorcunov@...il.com>
Subject: [RFC net-next iproute2 1/2] libnetlink: Add test for error code returned from netlink reply

In case if some diag module is not present in the system,
say the kernel is not modern enough, we simply skip the
error code reported. Instead we should check for data
length in NLMSG_DONE and process unsupported case.

Signed-off-by: Cyrill Gorcunov <gorcunov@...il.com>
---
 lib/libnetlink.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/lib/libnetlink.c b/lib/libnetlink.c
index 2279935..a397c07 100644
--- a/lib/libnetlink.c
+++ b/lib/libnetlink.c
@@ -312,6 +312,27 @@ int rtnl_dump_filter_l(struct rtnl_handle *rth,
 					dump_intr = 1;
 
 				if (h->nlmsg_type == NLMSG_DONE) {
+					int len;
+
+					/*
+					 * The kernel reports if there is
+					 * no inet-diag module present in
+					 * the system via negative length
+					 * as error code.
+					 */
+					if (h->nlmsg_len < NLMSG_LENGTH(sizeof(int))) {
+						fprintf(stderr, "Truncated length reply\n");
+						return -1;
+					}
+					len = *(int *)NLMSG_DATA(h);
+					if (len < 0) {
+						errno = -len;
+						if (errno == ENOENT ||
+						    errno == EOPNOTSUPP)
+							return -1;
+						perror("RTNETLINK answers");
+						return len;
+					}
 					found_done = 1;
 					break; /* process next filter */
 				}
-- 
2.7.4

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ