frr/staticd
Carmine Scarpitta 6037ea350c staticd: Fix crash that occurs when modifying an SRv6 SID
When the user modifies an SRv6 SID and then removes all SIDs, staticd
crashes:

```
2025/03/23 08:37:22.691860 STATIC: lib/memory.c:74: mt_count_free(): assertion (mt->n_alloc) failed
STATIC: Received signal 6 at 1742715442 (si_addr 0x8200007cf0); aborting...
STATIC: zlog_signal+0x390                  fcc704a844b8     ffffd7450390 /usr/lib/frr/libfrr.so.0 (mapped at 0xfcc704800000)
STATIC: core_handler+0x1f8                 fcc704b79990     ffffd7450590 /usr/lib/frr/libfrr.so.0 (mapped at 0xfcc704800000)
STATIC:     ---- signal ----
STATIC: ?                                  fcc705c008f8     ffffd74507a0 linux-vdso.so.1 (mapped at 0xfcc705c00000)
STATIC: pthread_key_delete+0x1a0           fcc70458f1f0     ffffd7451a00 /lib/aarch64-linux-gnu/libc.so.6 (mapped at 0xfcc704510000)
STATIC: raise+0x1c                         fcc70454a67c     ffffd7451ad0 /lib/aarch64-linux-gnu/libc.so.6 (mapped at 0xfcc704510000)
STATIC: abort+0xe4                         fcc704537130     ffffd7451af0 /lib/aarch64-linux-gnu/libc.so.6 (mapped at 0xfcc704510000)
STATIC: _zlog_assert_failed+0x3c4          fcc704c407c8     ffffd7451c40 /usr/lib/frr/libfrr.so.0 (mapped at 0xfcc704800000)
STATIC: mt_count_free+0x12c                fcc704a93c74     ffffd7451dc0 /usr/lib/frr/libfrr.so.0 (mapped at 0xfcc704800000)
STATIC: qfree+0x28                         fcc704a93fa0     ffffd7451e70 /usr/lib/frr/libfrr.so.0 (mapped at 0xfcc704800000)
STATIC: static_srv6_sid_free+0x1c          adc1df8fa544     ffffd7451e90 /usr/lib/frr/staticd (mapped at 0xadc1df8a0000)
STATIC: delete_static_srv6_sid+0x14        adc1df8faafc     ffffd7451eb0 /usr/lib/frr/staticd (mapped at 0xadc1df8a0000)
STATIC: list_delete_all_node+0x104         fcc704a60eec     ffffd7451ed0 /usr/lib/frr/libfrr.so.0 (mapped at 0xfcc704800000)
STATIC: list_delete+0x8c                   fcc704a61054     ffffd7451f00 /usr/lib/frr/libfrr.so.0 (mapped at 0xfcc704800000)
STATIC: static_srv6_cleanup+0x20           adc1df8fabdc     ffffd7451f20 /usr/lib/frr/staticd (mapped at 0xadc1df8a0000)
STATIC: sigint+0x40                        adc1df8be544     ffffd7451f30 /usr/lib/frr/staticd (mapped at 0xadc1df8a0000)
STATIC: frr_sigevent_process+0x148         fcc704b79460     ffffd7451f40 /usr/lib/frr/libfrr.so.0 (mapped at 0xfcc704800000)
STATIC: event_fetch+0x1c4                  fcc704bc0834     ffffd7451f60 /usr/lib/frr/libfrr.so.0 (mapped at 0xfcc704800000)
STATIC: frr_run+0x650                      fcc704a5d230     ffffd7452080 /usr/lib/frr/libfrr.so.0 (mapped at 0xfcc704800000)
STATIC: main+0x1d0                         adc1df8be75c     ffffd7452270 /usr/lib/frr/staticd (mapped at 0xadc1df8a0000)
STATIC: __libc_init_first+0x7c             fcc7045373fc     ffffd74522b0 /lib/aarch64-linux-gnu/libc.so.6 (mapped at 0xfcc704510000)
STATIC: __libc_start_main+0x98             fcc7045374cc     ffffd74523c0 /lib/aarch64-linux-gnu/libc.so.6 (mapped at 0xfcc704510000)
STATIC: _start+0x30                        adc1df8be0f0     ffffd7452420 /usr/lib/frr/staticd (mapped at 0xadc1df8a0000)
```

Tracking this down, the crash occurs because every time we modify a
SID, staticd executes some callbacks to modify the SID and finally it
calls `apply_finish`, which re-adds the SID to the list `srv6_sids`.

This leads to having the same SID multiple times in the `srv6_sids`
list. When we delete all SIDs, staticd attempts to deallocate the same
SID multiple times, which leads to the crash.

This commit fixes the issue by moving the code that adds the SID to the
list from the `apply_finish` callback to the `create` callback.
This ensures that the SID is inserted into the list only once, when it
is created. For all subsequent modifications, the SID is modified but
not added to the list.

Signed-off-by: Carmine Scarpitta <cscarpit@cisco.com>
2025-03-23 18:46:45 +01:00
..
.gitignore staticd: Start the addition of a staticd 2018-07-29 12:37:24 -04:00
Makefile staticd: Start the addition of a staticd 2018-07-29 12:37:24 -04:00
static_bfd.c staticd: fix NB dependency hack 2024-02-02 00:57:59 +02:00
static_debug.c staticd: Add debug option for SRv6 2025-01-18 10:28:49 +00:00
static_debug.h staticd: Add debug option for SRv6 2025-01-18 10:28:49 +00:00
static_main.c staticd: Initialize/cleanup SRv6 2025-01-18 10:28:49 +00:00
static_nb.c staticd: Add nb callbacks to configure a nexthop for SRv6 uA behavior 2025-02-26 07:19:51 +01:00
static_nb.h staticd: Add no form for static-sids command 2025-02-27 12:17:26 +01:00
static_nb_config.c staticd: Fix crash that occurs when modifying an SRv6 SID 2025-03-23 18:46:45 +01:00
static_nht.c staticd: fix NHT for dst-src routes 2025-01-28 15:40:17 +01:00
static_nht.h staticd: fix NHT for dst-src routes 2025-01-28 15:40:17 +01:00
static_routes.c staticd: Install known nexthops upon connection with zebra 2025-03-12 08:30:43 -04:00
static_routes.h staticd: Install known nexthops upon connection with zebra 2025-03-12 08:30:43 -04:00
static_srv6.c staticd: Install SIDs when a dependent interface goes up/down 2025-01-18 10:28:49 +00:00
static_srv6.h staticd: Install SIDs when a dependent interface goes up/down 2025-01-18 10:28:49 +00:00
static_vrf.c staticd: fix botched staticd YANG for dst-src 2025-01-28 15:40:17 +01:00
static_vrf.h staticd: fix NB dependency hack 2024-02-02 00:57:59 +02:00
static_vty.c staticd: Fix no srv6 command 2025-03-01 23:24:46 +01:00
static_vty.h mgmtd, staticd: output staticd configuration from mgmtd 2023-11-21 13:28:40 +02:00
static_zebra.c staticd: Install known nexthops upon connection with zebra 2025-03-12 08:30:43 -04:00
static_zebra.h staticd: Request/Release SIDs to SID Manager 2025-01-18 10:28:49 +00:00
subdir.am staticd: Add infrastructure for SRv6 2025-01-18 10:28:49 +00:00