From: Phil Sutter <phil@nwl.cc>
To: Stephen Hemminger <stephen@networkplumber.org>
Cc: netdev@vger.kernel.org
Subject: [iproute PATCH] ip-route: Propagate errors from parse_one_nh()
Date: Tue, 23 Jan 2018 17:40:47 +0100 [thread overview]
Message-ID: <20180123164047.28661-1-phil@nwl.cc> (raw)
The following command segfaults if enp0s31f6 does not exist:
| # ip -6 route add default proto ra metric 20100 \
| nexthop via fe80:52:0:2040::1fc dev enp0s31f6 weight 1 \
| nexthop via fe80:52:0:2040::1fe dev enp0s31f6 weight 1
Since the non-zero return code from parse_one_nh() is ignored,
parse_nexthops() continues iterating over the the same fields in argv
until buffer space is exhausted and eventually accesses unallocated
memory.
Fix this by aborting on error in parse_nexthops() and make
iproute_modify() fail if parse_nexthops() did.
Reported-by: Lennart Poettering <lpoetter@redhat.com>
Fixes: 2f406f2d0b4ef ("ip route: replace exits with returns")
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
ip/iproute.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/ip/iproute.c b/ip/iproute.c
index bf886fda9d761..d7accf57ac8d1 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -871,7 +871,8 @@ static int parse_nexthops(struct nlmsghdr *n, struct rtmsg *r,
memset(rtnh, 0, sizeof(*rtnh));
rtnh->rtnh_len = sizeof(*rtnh);
rta->rta_len += rtnh->rtnh_len;
- parse_one_nh(n, r, rta, rtnh, &argc, &argv);
+ if (parse_one_nh(n, r, rta, rtnh, &argc, &argv) < 0)
+ return -1;
rtnh = RTNH_NEXT(rtnh);
}
@@ -1318,8 +1319,8 @@ static int iproute_modify(int cmd, unsigned int flags, int argc, char **argv)
addattr_l(&req.n, sizeof(req), RTA_METRICS, RTA_DATA(mxrta), RTA_PAYLOAD(mxrta));
}
- if (nhs_ok)
- parse_nexthops(&req.n, &req.r, argc, argv);
+ if (nhs_ok && parse_nexthops(&req.n, &req.r, argc, argv) < 0)
+ return -1;
if (req.r.rtm_family == AF_UNSPEC)
req.r.rtm_family = AF_INET;
--
2.15.1
next reply other threads:[~2018-01-23 16:40 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-23 16:40 Phil Sutter [this message]
2018-01-23 22:44 ` [iproute PATCH] ip-route: Propagate errors from parse_one_nh() Stephen Hemminger
2018-01-24 9:19 ` Phil Sutter
2018-01-24 15:44 ` Stephen Hemminger
2018-02-08 13:26 ` Élie Bouttier
2018-02-08 14:11 ` Phil Sutter
2018-01-24 11:08 ` Phil Sutter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180123164047.28661-1-phil@nwl.cc \
--to=phil@nwl.cc \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).