Skip to content

Commit

Permalink
Merge pull request #17139 from FRRouting/mergify/bp/stable/10.0/pr-17020
Browse files Browse the repository at this point in the history
zebra: fix heap-use-after free on ns shutdown (backport #17020)
  • Loading branch information
ton31337 authored Oct 17, 2024
2 parents c6149b5 + 2b22d18 commit 8f07024
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
4 changes: 3 additions & 1 deletion zebra/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ void zebra_finalize(struct event *dummy)
zebra_ns_notify_close();

/* Final shutdown of ns resources */
ns_walk_func(zebra_ns_final_shutdown, NULL, NULL);
ns_walk_func(zebra_ns_kernel_shutdown, NULL, NULL);

zebra_rib_terminate();
zebra_router_terminate();
Expand All @@ -252,6 +252,8 @@ void zebra_finalize(struct event *dummy)

label_manager_terminate();

ns_walk_func(zebra_ns_final_shutdown, NULL, NULL);

ns_terminate();
frr_fini();
exit(0);
Expand Down
20 changes: 17 additions & 3 deletions zebra/zebra_ns.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,22 @@ int zebra_ns_early_shutdown(struct ns *ns,
return NS_WALK_CONTINUE;
}

/* During zebra shutdown, do kernel cleanup
* netlink sockets, ..
*/
int zebra_ns_kernel_shutdown(struct ns *ns, void *param_in __attribute__((unused)),
void **param_out __attribute__((unused)))
{
struct zebra_ns *zns = ns->info;

if (zns == NULL)
return NS_WALK_CONTINUE;

kernel_terminate(zns, true);

return NS_WALK_CONTINUE;
}

/* During zebra shutdown, do final cleanup
* after all dataplane work is complete.
*/
Expand All @@ -185,9 +201,7 @@ int zebra_ns_final_shutdown(struct ns *ns,
struct zebra_ns *zns = ns->info;

if (zns == NULL)
return 0;

kernel_terminate(zns, true);
return NS_WALK_CONTINUE;

zebra_ns_delete(ns);

Expand Down
2 changes: 2 additions & 0 deletions zebra/zebra_ns.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ int zebra_ns_early_shutdown(struct ns *ns,
int zebra_ns_final_shutdown(struct ns *ns,
void *param_in __attribute__((unused)),
void **param_out __attribute__((unused)));
int zebra_ns_kernel_shutdown(struct ns *ns, void *param_in __attribute__((unused)),
void **param_out __attribute__((unused)));

void zebra_ns_startup_continue(struct zebra_dplane_ctx *ctx);

Expand Down

0 comments on commit 8f07024

Please sign in to comment.