Skip to content

Commit 13d500d

Browse files
authored
Merge pull request #17138 from FRRouting/mergify/bp/stable/10.1/pr-17020
zebra: fix heap-use-after free on ns shutdown (backport #17020)
2 parents 4d229b0 + 0ddb53e commit 13d500d

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
@@ -241,7 +241,7 @@ void zebra_finalize(struct event *dummy)
241241
zebra_ns_notify_close();
242242

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

246246
zebra_rib_terminate();
247247
zebra_router_terminate();
@@ -254,6 +254,8 @@ void zebra_finalize(struct event *dummy)
254254

255255
label_manager_terminate();
256256

257+
ns_walk_func(zebra_ns_final_shutdown, NULL, NULL);
258+
257259
ns_terminate();
258260
frr_fini();
259261
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)