Skip to content

Commit 8f07024

Browse files
authored
Merge pull request #17139 from FRRouting/mergify/bp/stable/10.0/pr-17020
zebra: fix heap-use-after free on ns shutdown (backport #17020)
2 parents c6149b5 + 2b22d18 commit 8f07024

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

zebra/main.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ void zebra_finalize(struct event *dummy)
239239
zebra_ns_notify_close();
240240

241241
/* Final shutdown of ns resources */
242-
ns_walk_func(zebra_ns_final_shutdown, NULL, NULL);
242+
ns_walk_func(zebra_ns_kernel_shutdown, NULL, NULL);
243243

244244
zebra_rib_terminate();
245245
zebra_router_terminate();
@@ -252,6 +252,8 @@ void zebra_finalize(struct event *dummy)
252252

253253
label_manager_terminate();
254254

255+
ns_walk_func(zebra_ns_final_shutdown, NULL, NULL);
256+
255257
ns_terminate();
256258
frr_fini();
257259
exit(0);

zebra/zebra_ns.c

+17-3
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,22 @@ int zebra_ns_early_shutdown(struct ns *ns,
175175
return NS_WALK_CONTINUE;
176176
}
177177

178+
/* During zebra shutdown, do kernel cleanup
179+
* netlink sockets, ..
180+
*/
181+
int zebra_ns_kernel_shutdown(struct ns *ns, void *param_in __attribute__((unused)),
182+
void **param_out __attribute__((unused)))
183+
{
184+
struct zebra_ns *zns = ns->info;
185+
186+
if (zns == NULL)
187+
return NS_WALK_CONTINUE;
188+
189+
kernel_terminate(zns, true);
190+
191+
return NS_WALK_CONTINUE;
192+
}
193+
178194
/* During zebra shutdown, do final cleanup
179195
* after all dataplane work is complete.
180196
*/
@@ -185,9 +201,7 @@ int zebra_ns_final_shutdown(struct ns *ns,
185201
struct zebra_ns *zns = ns->info;
186202

187203
if (zns == NULL)
188-
return 0;
189-
190-
kernel_terminate(zns, true);
204+
return NS_WALK_CONTINUE;
191205

192206
zebra_ns_delete(ns);
193207

zebra/zebra_ns.h

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ int zebra_ns_early_shutdown(struct ns *ns,
7070
int zebra_ns_final_shutdown(struct ns *ns,
7171
void *param_in __attribute__((unused)),
7272
void **param_out __attribute__((unused)));
73+
int zebra_ns_kernel_shutdown(struct ns *ns, void *param_in __attribute__((unused)),
74+
void **param_out __attribute__((unused)));
7375

7476
void zebra_ns_startup_continue(struct zebra_dplane_ctx *ctx);
7577

0 commit comments

Comments
 (0)