Skip to content

Commit 69807d7

Browse files
dleroymergify[bot]
authored andcommitted
nhrpd: cleans up shortcut cache entries on termination
nhrp_shortcut_terminate() previously was just freeing the associated AFI shortcut RIBs and not addressing existing shortcut cache entries. This cause a use after free issue in vrf_terminate() later in the terminate sequence NHRP: Received signal 7 at 1717516286 (si_addr 0x1955d, PC 0x7098786912c0); aborting... NHRP: zlog_signal+0xf5 709878ad1255 7fff3d992eb0 /usr/lib/frr/libfrr.so.0 (mapped at 0x709878a00000) NHRP: core_handler+0xb5 709878b0db85 7fff3d992ff0 /usr/lib/frr/libfrr.so.0 (mapped at 0x709878a00000) NHRP: __sigaction+0x50 709878642520 7fff3d993140 /lib/x86_64-linux-gnu/libc.so.6 (mapped at 0x709878600000) NHRP: ---- signal ---- NHRP: __lll_lock_wait_private+0x90 7098786912c0 7fff3d9936d8 /lib/x86_64-linux-gnu/libc.so.6 (mapped at 0x709878600000) NHRP: pthread_mutex_lock+0x112 709878698002 7fff3d9936e0 /lib/x86_64-linux-gnu/libc.so.6 (mapped at 0x709878600000) NHRP: _event_add_read_write+0x63 709878b1f423 7fff3d993700 /usr/lib/frr/libfrr.so.0 (mapped at 0x709878a00000) NHRP: zclient_send_message+0xd4 709878b37614 7fff3d993770 /usr/lib/frr/libfrr.so.0 (mapped at 0x709878a00000) NHRP: nhrp_route_announce+0x1ad 5ab34d63d39d 7fff3d993790 /usr/lib/frr/nhrpd (mapped at 0x5ab34d621000) NHRP: nhrp_shortcut_cache_notify+0xd8 5ab34d63e758 7fff3d99d4e0 /usr/lib/frr/nhrpd (mapped at 0x5ab34d621000) NHRP: nhrp_cache_free+0x165 5ab34d632f25 7fff3d99d510 /usr/lib/frr/nhrpd (mapped at 0x5ab34d621000) NHRP: hash_iterate+0x4d 709878ab949d 7fff3d99d540 /usr/lib/frr/libfrr.so.0 (mapped at 0x709878a00000) NHRP: nhrp_cache_interface_del+0x37 5ab34d633eb7 7fff3d99d580 /usr/lib/frr/nhrpd (mapped at 0x5ab34d621000) NHRP: nhrp_if_delete_hook+0x26 5ab34d6350d6 7fff3d99d5a0 /usr/lib/frr/nhrpd (mapped at 0x5ab34d621000) NHRP: if_delete_retain+0x3d 709878abcd1d 7fff3d99d5c0 /usr/lib/frr/libfrr.so.0 (mapped at 0x709878a00000) NHRP: if_delete+0x4c 709878abd87c 7fff3d99d600 /usr/lib/frr/libfrr.so.0 (mapped at 0x709878a00000) NHRP: if_terminate+0x53 709878abda83 7fff3d99d630 /usr/lib/frr/libfrr.so.0 (mapped at 0x709878a00000) NHRP: vrf_terminate_single+0x24 709878b23c74 7fff3d99d670 /usr/lib/frr/libfrr.so.0 (mapped at 0x709878a00000) NHRP: nhrp_request_stop+0x34 5ab34d636844 7fff3d99d690 /usr/lib/frr/nhrpd (mapped at 0x5ab34d621000) NHRP: frr_sigevent_process+0x53 709878b0df53 7fff3d99d6a0 /usr/lib/frr/libfrr.so.0 (mapped at 0x709878a00000) NHRP: event_fetch+0x6c5 709878b20405 7fff3d99d6c0 /usr/lib/frr/libfrr.so.0 (mapped at 0x709878a00000) NHRP: frr_run+0xd3 709878ac8163 7fff3d99d840 /usr/lib/frr/libfrr.so.0 (mapped at 0x709878a00000) NHRP: main+0x195 5ab34d631915 7fff3d99d960 /usr/lib/frr/nhrpd (mapped at 0x5ab34d621000) NHRP: __libc_init_first+0x90 709878629d90 7fff3d99d980 /lib/x86_64-linux-gnu/libc.so.6 (mapped at 0x709878600000) NHRP: __libc_start_main+0x80 709878629e40 7fff3d99da20 /lib/x86_64-linux-gnu/libc.so.6 (mapped at 0x709878600000) NHRP: _start+0x25 5ab34d631b65 7fff3d99da70 /usr/lib/frr/nhrpd (mapped at 0x5ab34d621000) Signed-off-by: Dave LeRoy <dleroy@labn.net> (cherry picked from commit 2b7e357)
1 parent 4930253 commit 69807d7

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

nhrpd/nhrp_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@ static void nhrp_request_stop(void)
8383
debugf(NHRP_DEBUG_COMMON, "Exiting...");
8484
frr_early_fini();
8585

86-
vrf_terminate();
86+
nhrp_shortcut_terminate();
8787
nhrp_nhs_terminate();
8888
nhrp_zebra_terminate();
8989
vici_terminate();
9090
evmgr_terminate();
91+
vrf_terminate();
9192
nhrp_vc_terminate();
92-
nhrp_shortcut_terminate();
9393

9494
debugf(NHRP_DEBUG_COMMON, "Done.");
9595

nhrpd/nhrp_shortcut.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ DEFINE_MTYPE_STATIC(NHRPD, NHRP_SHORTCUT, "NHRP shortcut");
1919
static struct route_table *shortcut_rib[AFI_MAX];
2020

2121
static void nhrp_shortcut_do_purge(struct event *t);
22-
static void nhrp_shortcut_delete(struct nhrp_shortcut *s);
22+
static void nhrp_shortcut_delete(struct nhrp_shortcut *s,
23+
void *arg __attribute__((__unused__)));
2324
static void nhrp_shortcut_send_resolution_req(struct nhrp_shortcut *s);
2425

2526
static void nhrp_shortcut_check_use(struct nhrp_shortcut *s)
@@ -72,7 +73,7 @@ static void nhrp_shortcut_cache_notify(struct notifier_block *n,
7273
s->route_installed = 0;
7374
}
7475
if (cmd == NOTIFY_CACHE_DELETE)
75-
nhrp_shortcut_delete(s);
76+
nhrp_shortcut_delete(s, NULL);
7677
break;
7778
}
7879
}
@@ -132,7 +133,8 @@ static void nhrp_shortcut_update_binding(struct nhrp_shortcut *s,
132133
}
133134
}
134135

135-
static void nhrp_shortcut_delete(struct nhrp_shortcut *s)
136+
static void nhrp_shortcut_delete(struct nhrp_shortcut *s,
137+
void *arg __attribute__((__unused__)))
136138
{
137139
struct route_node *rn;
138140
afi_t afi = family2afi(PREFIX_FAMILY(s->p));
@@ -158,7 +160,7 @@ static void nhrp_shortcut_do_purge(struct event *t)
158160
{
159161
struct nhrp_shortcut *s = EVENT_ARG(t);
160162
s->t_timer = NULL;
161-
nhrp_shortcut_delete(s);
163+
nhrp_shortcut_delete(s, NULL);
162164
}
163165

164166
static struct nhrp_shortcut *nhrp_shortcut_get(struct prefix *p)
@@ -469,6 +471,8 @@ void nhrp_shortcut_init(void)
469471

470472
void nhrp_shortcut_terminate(void)
471473
{
474+
nhrp_shortcut_foreach(AFI_IP, nhrp_shortcut_delete, NULL);
475+
nhrp_shortcut_foreach(AFI_IP6, nhrp_shortcut_delete, NULL);
472476
route_table_finish(shortcut_rib[AFI_IP]);
473477
route_table_finish(shortcut_rib[AFI_IP6]);
474478
}

0 commit comments

Comments
 (0)