|
|
7e752c |
From 3ec32595e21849de3165d52e1af48ca3bdf51fab Mon Sep 17 00:00:00 2001
|
|
|
7e752c |
From: Phil Sutter <psutter@redhat.com>
|
|
|
7e752c |
Date: Thu, 25 Oct 2018 12:24:30 +0200
|
|
|
7e752c |
Subject: [PATCH] libnetlink: fix leak and using unused memory on error
|
|
|
7e752c |
|
|
|
7e752c |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1602555
|
|
|
7e752c |
Upstream Status: iproute2.git commit c60389e4f9ea8
|
|
|
7e752c |
|
|
|
7e752c |
commit c60389e4f9ea88d7246dbb148d28791d577fe5b4
|
|
|
7e752c |
Author: Stephen Hemminger <stephen@networkplumber.org>
|
|
|
7e752c |
Date: Thu Sep 13 12:33:38 2018 -0700
|
|
|
7e752c |
|
|
|
7e752c |
libnetlink: fix leak and using unused memory on error
|
|
|
7e752c |
|
|
|
7e752c |
If an error happens in multi-segment message (tc only)
|
|
|
7e752c |
then report the error and stop processing further responses.
|
|
|
7e752c |
This also fixes refering to the buffer after free.
|
|
|
7e752c |
|
|
|
7e752c |
The sequence check is not necessary here because the
|
|
|
7e752c |
response message has already been validated to be in
|
|
|
7e752c |
the window of the sequence number of the iov.
|
|
|
7e752c |
|
|
|
7e752c |
Reported-by: Mahesh Bandewar <mahesh@bandewar.net>
|
|
|
7e752c |
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
|
|
|
7e752c |
Acked-by: Mahesh Bandewar <maheshb@google.com>
|
|
|
7e752c |
---
|
|
|
7e752c |
lib/libnetlink.c | 23 +++++++++--------------
|
|
|
7e752c |
1 file changed, 9 insertions(+), 14 deletions(-)
|
|
|
7e752c |
|
|
|
7e752c |
diff --git a/lib/libnetlink.c b/lib/libnetlink.c
|
|
|
7e752c |
index 928de1d..5868092 100644
|
|
|
7e752c |
--- a/lib/libnetlink.c
|
|
|
7e752c |
+++ b/lib/libnetlink.c
|
|
|
7e752c |
@@ -617,7 +617,6 @@ static int __rtnl_talk_iov(struct rtnl_handle *rtnl, struct iovec *iov,
|
|
|
7e752c |
msg.msg_iovlen = 1;
|
|
|
7e752c |
i = 0;
|
|
|
7e752c |
while (1) {
|
|
|
7e752c |
-next:
|
|
|
7e752c |
status = rtnl_recvmsg(rtnl->fd, &msg, &buf;;
|
|
|
7e752c |
++i;
|
|
|
7e752c |
|
|
|
7e752c |
@@ -660,27 +659,23 @@ next:
|
|
|
7e752c |
|
|
|
7e752c |
if (l < sizeof(struct nlmsgerr)) {
|
|
|
7e752c |
fprintf(stderr, "ERROR truncated\n");
|
|
|
7e752c |
- } else if (!err->error) {
|
|
|
7e752c |
+ free(buf);
|
|
|
7e752c |
+ return -1;
|
|
|
7e752c |
+ }
|
|
|
7e752c |
+
|
|
|
7e752c |
+ if (!err->error)
|
|
|
7e752c |
/* check messages from kernel */
|
|
|
7e752c |
nl_dump_ext_ack(h, errfn);
|
|
|
7e752c |
|
|
|
7e752c |
- if (answer)
|
|
|
7e752c |
- *answer = (struct nlmsghdr *)buf;
|
|
|
7e752c |
- else
|
|
|
7e752c |
- free(buf);
|
|
|
7e752c |
- if (h->nlmsg_seq == seq)
|
|
|
7e752c |
- return 0;
|
|
|
7e752c |
- else if (i < iovlen)
|
|
|
7e752c |
- goto next;
|
|
|
7e752c |
- return 0;
|
|
|
7e752c |
- }
|
|
|
7e752c |
-
|
|
|
7e752c |
if (rtnl->proto != NETLINK_SOCK_DIAG &&
|
|
|
7e752c |
show_rtnl_err)
|
|
|
7e752c |
rtnl_talk_error(h, err, errfn);
|
|
|
7e752c |
|
|
|
7e752c |
errno = -err->error;
|
|
|
7e752c |
- free(buf);
|
|
|
7e752c |
+ if (answer)
|
|
|
7e752c |
+ *answer = (struct nlmsghdr *)buf;
|
|
|
7e752c |
+ else
|
|
|
7e752c |
+ free(buf);
|
|
|
7e752c |
return -i;
|
|
|
7e752c |
}
|
|
|
7e752c |
|
|
|
7e752c |
--
|
|
|
7e752c |
1.8.3.1
|
|
|
7e752c |
|