Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zebra: fix table heap-after-free crash #16614

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

tests: zebra_rib, test vrf change

4b620e6
Select commit
Loading
Failed to load commit list.
Open

zebra: fix table heap-after-free crash #16614

tests: zebra_rib, test vrf change
4b620e6
Select commit
Loading
Failed to load commit list.
frrbot / frrbot completed Oct 16, 2024 in 11s

Style and/or linter errors found

Style and/or linter errors found

Details

Thanks for your contribution to FRR!

Click for style suggestions

diff --git a/zebra/zebra_nhg.c b/zebra/zebra_nhg.c
index 0dbf7a24e..e114a9d20 100644
--- a/zebra/zebra_nhg.c
+++ b/zebra/zebra_nhg.c
@@ -2923,8 +2923,7 @@ static uint32_t proto_nhg_nexthop_active_update(struct nexthop_group *nhg)
 	return curr_active;
 }
 
-void nexthop_vrf_update(struct route_node *rn, struct route_entry *re,
-			vrf_id_t vrf_id)
+void nexthop_vrf_update(struct route_node *rn, struct route_entry *re, vrf_id_t vrf_id)
 {
 	struct nhg_hash_entry *curr_nhe, *new_nhe;
 	afi_t rt_afi = family2afi(rn->p.family);
@@ -2938,8 +2937,8 @@ void nexthop_vrf_update(struct route_node *rn, struct route_entry *re,
 	curr_nhe = zebra_nhe_copy(re->nhe, re->nhe->id);
 
 	if (IS_ZEBRA_DEBUG_NHG_DETAIL)
-		zlog_debug("%s: re %p nhe %p (%pNG), curr_nhe %p", __func__, re,
-			   re->nhe, re->nhe, curr_nhe);
+		zlog_debug("%s: re %p nhe %p (%pNG), curr_nhe %p", __func__, re, re->nhe, re->nhe,
+			   curr_nhe);
 
 	/* Clear the existing id, if any: this will avoid any confusion
 	 * if the id exists, and will also force the creation
@@ -2973,8 +2972,8 @@ void nexthop_vrf_update(struct route_node *rn, struct route_entry *re,
 	new_nhe = zebra_nhg_rib_find_nhe(curr_nhe, rt_afi);
 
 	if (IS_ZEBRA_DEBUG_NHG_DETAIL)
-		zlog_debug("%s: re %p CHANGED: nhe %p (%pNG) => new_nhe %p (%pNG)",
-			   __func__, re, re->nhe, re->nhe, new_nhe, new_nhe);
+		zlog_debug("%s: re %p CHANGED: nhe %p (%pNG) => new_nhe %p (%pNG)", __func__, re,
+			   re->nhe, re->nhe, new_nhe, new_nhe);
 
 	route_entry_update_nhe(re, new_nhe);
 
diff --git a/zebra/zebra_nhg.h b/zebra/zebra_nhg.h
index e773b1779..de6f6123a 100644
--- a/zebra/zebra_nhg.h
+++ b/zebra/zebra_nhg.h
@@ -401,8 +401,7 @@ extern void zebra_nhg_mark_keep(void);
 
 /* Nexthop resolution processing */
 struct route_entry; /* Forward ref to avoid circular includes */
-extern void nexthop_vrf_update(struct route_node *rn, struct route_entry *re,
-			       vrf_id_t vrf_id);
+extern void nexthop_vrf_update(struct route_node *rn, struct route_entry *re, vrf_id_t vrf_id);
 extern int nexthop_active_update(struct route_node *rn, struct route_entry *re,
 				 struct route_entry *old_re);
 
diff --git a/zebra/zebra_vrf.c b/zebra/zebra_vrf.c
index 2d0b0f0d8..988e135f6 100644
--- a/zebra/zebra_vrf.c
+++ b/zebra/zebra_vrf.c
@@ -155,8 +155,7 @@ static int zebra_vrf_enable(struct vrf *vrf)
 }
 
 /* update the VRF ID of a routing table and their routing entries */
-static void zebra_vrf_disable_update_vrfid(struct zebra_vrf *zvrf, afi_t afi,
-					   safi_t safi)
+static void zebra_vrf_disable_update_vrfid(struct zebra_vrf *zvrf, afi_t afi, safi_t safi)
 {
 	struct rib_table_info *info;
 	struct route_entry *re, *nre;
@@ -280,10 +279,8 @@ static int zebra_vrf_disable(struct vrf *vrf)
 		 * we no-longer need this pointer.
 		 */
 		for (safi = SAFI_UNICAST; safi <= SAFI_MULTICAST; safi++) {
-			if (!zvrf->table[afi][safi] ||
-			    vrf->vrf_id == VRF_DEFAULT) {
-				zebra_router_release_table(zvrf, zvrf->table_id,
-							   afi, safi);
+			if (!zvrf->table[afi][safi] || vrf->vrf_id == VRF_DEFAULT) {
+				zebra_router_release_table(zvrf, zvrf->table_id, afi, safi);
 				zvrf->table[afi][safi] = NULL;
 				continue;
 			}
diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c
index 2dfb397db..0b18a9190 100644
--- a/zebra/zebra_vty.c
+++ b/zebra/zebra_vty.c
@@ -945,11 +945,9 @@ static void do_show_route_helper(struct vty *vty, struct zebra_vrf *zvrf,
 							zvrf_name(zvrf),
 							tableid);
 					else if (tableid)
-						vty_out(vty, "Table %u:\n",
-							tableid);
+						vty_out(vty, "Table %u:\n", tableid);
 					else
-						vty_out(vty, "VRF %s:\n",
-							zvrf_name(zvrf));
+						vty_out(vty, "VRF %s:\n", zvrf_name(zvrf));
 				}
 				ctx->header_done = true;
 				first = 0;

To apply the style suggestions:

curl https://gist.githubusercontent.com/polychaeta/1bdd57a041f96487f28cd1120a642526/raw/77dd070f07dc7ea2fabfbebafd18a2d6cf7bfbd8/style.diff | git apply -

If you are a new contributor to FRR, please see our contributing guidelines.

After making changes, you do not need to create a new PR. You should perform an amend or interactive rebase followed by a force push.