Skip to content

Commit cc63dbb

Browse files
authored
Merge pull request #17020 from pguibert6WIND/asan_shutdown
zebra: fix heap-use-after free on ns shutdown
2 parents 80dc863 + 7ae70eb commit cc63dbb

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
@@ -238,7 +238,7 @@ void zebra_finalize(struct event *dummy)
238238
zebra_ns_notify_close();
239239

240240
/* Final shutdown of ns resources */
241-
ns_walk_func(zebra_ns_final_shutdown, NULL, NULL);
241+
ns_walk_func(zebra_ns_kernel_shutdown, NULL, NULL);
242242

243243
zebra_rib_terminate();
244244
zebra_router_terminate();
@@ -251,6 +251,8 @@ void zebra_finalize(struct event *dummy)
251251

252252
label_manager_terminate();
253253

254+
ns_walk_func(zebra_ns_final_shutdown, NULL, NULL);
255+
254256
ns_terminate();
255257
frr_fini();
256258
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)