From ccaeae4261bc7d35d48a511f71cfc25728786b24 Mon Sep 17 00:00:00 2001
From: Ilya Maximets <i.maximets@ovn.org>
Date: Tue, 5 May 2020 13:08:50 +0200
Subject: [PATCH 2/4] ovn-northd: Fix memory leak and incorrect limiting of
ECMP routes.
If route count reaches UINT16_MAX, ecmp_groups_add_route() will leak the
allocated route structure. Also, since group->route_count incremented
unconditionally, next attempt to add new route will succeed, because the
value of 'route_count' is zero now and out of sync with the real number
of routes.
Fixes: 4e53974bdc4e ("ovn-northd: Support ECMP routes.")
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
Acked-by: Mark Michelson <mmichels@redhat.com>
Signed-off-by: Han Zhou <hzhou@ovn.org>
---
northd/ovn-northd.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c
index ec77ae1a8..dc647d7c5 100644
--- a/northd/ovn-northd.c
+++ b/northd/ovn-northd.c
@@ -7188,15 +7188,15 @@ static void
ecmp_groups_add_route(struct ecmp_groups_node *group,
const struct parsed_route *route)
{
- struct ecmp_route_list_node *er = xmalloc(sizeof *er);
- er->route = route;
- er->id = ++group->route_count;
- if (er->id == 0) {
+ if (group->route_count == UINT16_MAX) {
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 1);
VLOG_WARN_RL(&rl, "too many routes in a single ecmp group.");
return;
}
+ struct ecmp_route_list_node *er = xmalloc(sizeof *er);
+ er->route = route;
+ er->id = ++group->route_count;
ovs_list_insert(&group->route_list, &er->list_node);
}
--
2.26.2