Message ID | 20180928171339.4332-1-vlad@dumitrescu.ro |
---|---|
State | Accepted, archived |
Delegated to: | stephen hemminger |
Headers | show |
Series | [iproute2] lib/libnetlink: fix response seq check | expand |
Hi, On Fri, Sep 28, 2018 at 10:14 AM <vlad@dumitrescu.ro> wrote: > > From: Vlad Dumitrescu <vladum@google.com> > > Taking a one-iovec example, with rtnl->seq at 42. iovlen == 1, seq > becomes 43 on line 604, and a message is sent with nlmsg_seq == 43. If > a response with nlmsg_seq of 42 is received, the condition being fixed > in this patch would incorrectly accept it. > > Fixes: 72a2ff3916e5 ("lib/libnetlink: Add a new function rtnl_talk_iov") > Signed-off-by: Vlad Dumitrescu <vladum@google.com> > --- > lib/libnetlink.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/lib/libnetlink.c b/lib/libnetlink.c > index f18dceac..4d2416bf 100644 > --- a/lib/libnetlink.c > +++ b/lib/libnetlink.c > @@ -647,7 +647,7 @@ static int __rtnl_talk_iov(struct rtnl_handle *rtnl, struct iovec *iov, > > if (nladdr.nl_pid != 0 || > h->nlmsg_pid != rtnl->local.nl_pid || > - h->nlmsg_seq > seq || h->nlmsg_seq < seq - iovlen) { > + h->nlmsg_seq > seq || h->nlmsg_seq < seq - iovlen + 1) { > /* Don't forget to skip that message. */ > status -= NLMSG_ALIGN(len); > h = (struct nlmsghdr *)((char *)h + NLMSG_ALIGN(len)); > -- > 2.19.0.605.g01d371f741-goog Did anybody get a chance to review this? I'm not 100% sure I'm fixing the right thing. Thanks, Vlad
On Wed, 3 Oct 2018 16:01:40 -0700 Vlad Dumitrescu <vlad@dumitrescu.ro> wrote: > Hi, > > On Fri, Sep 28, 2018 at 10:14 AM <vlad@dumitrescu.ro> wrote: > > > > From: Vlad Dumitrescu <vladum@google.com> > > > > Taking a one-iovec example, with rtnl->seq at 42. iovlen == 1, seq > > becomes 43 on line 604, and a message is sent with nlmsg_seq == 43. If > > a response with nlmsg_seq of 42 is received, the condition being fixed > > in this patch would incorrectly accept it. > > > > Fixes: 72a2ff3916e5 ("lib/libnetlink: Add a new function rtnl_talk_iov") > > Signed-off-by: Vlad Dumitrescu <vladum@google.com> > > --- > > lib/libnetlink.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/lib/libnetlink.c b/lib/libnetlink.c > > index f18dceac..4d2416bf 100644 > > --- a/lib/libnetlink.c > > +++ b/lib/libnetlink.c > > @@ -647,7 +647,7 @@ static int __rtnl_talk_iov(struct rtnl_handle *rtnl, struct iovec *iov, > > > > if (nladdr.nl_pid != 0 || > > h->nlmsg_pid != rtnl->local.nl_pid || > > - h->nlmsg_seq > seq || h->nlmsg_seq < seq - iovlen) { > > + h->nlmsg_seq > seq || h->nlmsg_seq < seq - iovlen + 1) { > > /* Don't forget to skip that message. */ > > status -= NLMSG_ALIGN(len); > > h = (struct nlmsghdr *)((char *)h + NLMSG_ALIGN(len)); > > -- > > 2.19.0.605.g01d371f741-goog > > Did anybody get a chance to review this? I'm not 100% sure I'm fixing > the right thing. > > Thanks, > Vlad Could you give an example where this failed. Better yet one of the tests.
diff --git a/lib/libnetlink.c b/lib/libnetlink.c index f18dceac..4d2416bf 100644 --- a/lib/libnetlink.c +++ b/lib/libnetlink.c @@ -647,7 +647,7 @@ static int __rtnl_talk_iov(struct rtnl_handle *rtnl, struct iovec *iov, if (nladdr.nl_pid != 0 || h->nlmsg_pid != rtnl->local.nl_pid || - h->nlmsg_seq > seq || h->nlmsg_seq < seq - iovlen) { + h->nlmsg_seq > seq || h->nlmsg_seq < seq - iovlen + 1) { /* Don't forget to skip that message. */ status -= NLMSG_ALIGN(len); h = (struct nlmsghdr *)((char *)h + NLMSG_ALIGN(len));