mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-04-29 02:16:07 +00:00

Prevent a use after free and tell the bfd subsystem we are shutting down in staticd. ./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460:==2264460==ERROR: AddressSanitizer: heap-use-after-free on address 0x61f000004698 at pc 0x7f65d1eb11b2 bp 0x7ffdbface490 sp 0x7ffdbface488 ./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460-READ of size 4 at 0x61f000004698 thread T0 ./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460- #0 0x7f65d1eb11b1 in zclient_bfd_command lib/bfd.c:307 ./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460- #1 0x7f65d1eb20f5 in _bfd_sess_send lib/bfd.c:507 ./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460- #2 0x7f65d20510aa in thread_call lib/thread.c:1989 ./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460- #3 0x7f65d2051f0a in _thread_execute lib/thread.c:2081 ./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460- #4 0x7f65d1eb271b in _bfd_sess_remove lib/bfd.c:544 ./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460- #5 0x7f65d1eb278d in bfd_sess_free lib/bfd.c:553 ./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460- #6 0x7f65d1eb5400 in bfd_protocol_integration_finish lib/bfd.c:1029 ./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460- #7 0x7f65d1f42f77 in hook_call_frr_fini lib/libfrr.c:41 ./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460- #8 0x7f65d1f494a1 in frr_fini lib/libfrr.c:1199 ./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460- #9 0x563b7abefd76 in sigint staticd/static_main.c:70 ./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460- #10 0x7f65d200ef91 in frr_sigevent_process lib/sigevent.c:115 ./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460- #11 0x7f65d204fac6 in thread_fetch lib/thread.c:1758 ./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460- #12 0x7f65d1f49377 in frr_run lib/libfrr.c:1184 ./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460- #13 0x563b7abefed1 in main staticd/static_main.c:160 ./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460- #14 0x7f65d1b92d09 in __libc_start_main ../csu/libc-start.c:308 ./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460- #15 0x563b7abefa99 in _start (/usr/lib/frr/staticd+0x15a99) ./bfd_topo3.test_bfd_topo3/r4.staticd.asan.2264460- Signed-off-by: Donald Sharp <sharpd@nvidia.com>
168 lines
3.0 KiB
C
168 lines
3.0 KiB
C
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
/*
|
|
* STATICd - main code
|
|
* Copyright (C) 2018 Cumulus Networks, Inc.
|
|
* Donald Sharp
|
|
*/
|
|
#include <zebra.h>
|
|
|
|
#include <lib/version.h>
|
|
#include "getopt.h"
|
|
#include "thread.h"
|
|
#include "command.h"
|
|
#include "log.h"
|
|
#include "memory.h"
|
|
#include "privs.h"
|
|
#include "sigevent.h"
|
|
#include "libfrr.h"
|
|
#include "vrf.h"
|
|
#include "nexthop.h"
|
|
#include "filter.h"
|
|
#include "routing_nb.h"
|
|
|
|
#include "static_vrf.h"
|
|
#include "static_vty.h"
|
|
#include "static_routes.h"
|
|
#include "static_zebra.h"
|
|
#include "static_debug.h"
|
|
#include "static_nb.h"
|
|
|
|
char backup_config_file[256];
|
|
|
|
bool mpls_enabled;
|
|
|
|
zebra_capabilities_t _caps_p[] = {
|
|
};
|
|
|
|
struct zebra_privs_t static_privs = {
|
|
#if defined(FRR_USER) && defined(FRR_GROUP)
|
|
.user = FRR_USER,
|
|
.group = FRR_GROUP,
|
|
#endif
|
|
#if defined(VTY_GROUP)
|
|
.vty_group = VTY_GROUP,
|
|
#endif
|
|
.caps_p = _caps_p,
|
|
.cap_num_p = array_size(_caps_p),
|
|
.cap_num_i = 0};
|
|
|
|
struct option longopts[] = { { 0 } };
|
|
|
|
/* Master of threads. */
|
|
struct thread_master *master;
|
|
|
|
static struct frr_daemon_info staticd_di;
|
|
/* SIGHUP handler. */
|
|
static void sighup(void)
|
|
{
|
|
zlog_info("SIGHUP received");
|
|
vty_read_config(NULL, staticd_di.config_file, config_default);
|
|
}
|
|
|
|
/* SIGINT / SIGTERM handler. */
|
|
static void sigint(void)
|
|
{
|
|
zlog_notice("Terminating on signal");
|
|
|
|
/* Disable BFD events to avoid wasting processing. */
|
|
bfd_protocol_integration_set_shutdown(true);
|
|
|
|
static_vrf_terminate();
|
|
|
|
static_zebra_stop();
|
|
frr_fini();
|
|
|
|
exit(0);
|
|
}
|
|
|
|
/* SIGUSR1 handler. */
|
|
static void sigusr1(void)
|
|
{
|
|
zlog_rotate();
|
|
}
|
|
|
|
struct frr_signal_t static_signals[] = {
|
|
{
|
|
.signal = SIGHUP,
|
|
.handler = &sighup,
|
|
},
|
|
{
|
|
.signal = SIGUSR1,
|
|
.handler = &sigusr1,
|
|
},
|
|
{
|
|
.signal = SIGINT,
|
|
.handler = &sigint,
|
|
},
|
|
{
|
|
.signal = SIGTERM,
|
|
.handler = &sigint,
|
|
},
|
|
};
|
|
|
|
static const struct frr_yang_module_info *const staticd_yang_modules[] = {
|
|
&frr_filter_info,
|
|
&frr_interface_info,
|
|
&frr_vrf_info,
|
|
&frr_routing_info,
|
|
&frr_staticd_info,
|
|
};
|
|
|
|
#define STATIC_VTY_PORT 2616
|
|
|
|
FRR_DAEMON_INFO(staticd, STATIC, .vty_port = STATIC_VTY_PORT,
|
|
|
|
.proghelp = "Implementation of STATIC.",
|
|
|
|
.signals = static_signals,
|
|
.n_signals = array_size(static_signals),
|
|
|
|
.privs = &static_privs, .yang_modules = staticd_yang_modules,
|
|
.n_yang_modules = array_size(staticd_yang_modules),
|
|
);
|
|
|
|
int main(int argc, char **argv, char **envp)
|
|
{
|
|
frr_preinit(&staticd_di, argc, argv);
|
|
frr_opt_add("", longopts, "");
|
|
|
|
while (1) {
|
|
int opt;
|
|
|
|
opt = frr_getopt(argc, argv, NULL);
|
|
|
|
if (opt == EOF)
|
|
break;
|
|
|
|
switch (opt) {
|
|
case 0:
|
|
break;
|
|
default:
|
|
frr_help_exit(1);
|
|
}
|
|
}
|
|
|
|
master = frr_init();
|
|
|
|
static_debug_init();
|
|
static_vrf_init();
|
|
|
|
static_zebra_init();
|
|
static_vty_init();
|
|
|
|
hook_register(routing_conf_event,
|
|
routing_control_plane_protocols_name_validate);
|
|
|
|
routing_control_plane_protocols_register_vrf_dependency();
|
|
|
|
snprintf(backup_config_file, sizeof(backup_config_file),
|
|
"%s/zebra.conf", frr_sysconfdir);
|
|
staticd_di.backup_config_file = backup_config_file;
|
|
|
|
frr_config_fork();
|
|
frr_run(master);
|
|
|
|
/* Not reached. */
|
|
return 0;
|
|
}
|