Commit 5a958129d1 for frr
commit 5a958129d18757e51e7fb6b6aa0bfa61c582eeed
Author: Philippe Guibert <philippe.guibert@6wind.com>
Date: Tue Nov 17 16:43:16 2026 +0100
zebra: resize the Wide LIB array when the Wide LIB changes
Growing the Wide LIB of a format used by a locator makes zebra write
past the end of the Wide LIB array, when an explicit wide SID is
allocated after the end of the former range:
> format usid-f3216
> wide-local-id-block start 65400 end 65535
> wide-local-id-block explicit start 65400
> router bgp 1 vrf vrf10
> address-family ipv6 unicast
> sid vpn export explicit fc00:0:1:ffdc:1::
The SID block allocates its Wide LIB array, one entry per function of
the Wide LIB, when it is created, with the Wide LIB range of the format
at that time: 8 entries with the default 65520-65527 range. Changing
the range does not resize the array, but the explicit allocation and
release paths index it with the offset of the function from the new
Wide LIB start: 65500 - 65400 = 100 here. The block free path also
walks the array with the size of the new range, so a shrunk range
leaks entries, and a grown range frees lists past the end of the array.
When the format changes, zebra_srv6_sid_format_change_start() has
released all the SIDs of the locators using the format. Free and
allocate again the Wide LIB array in
zebra_srv6_sid_format_change_finish(), and keep its size in the block,
so that the free path does not depend on the current range.
Fixes: 51d3cd8a00 ("zebra: CLI to override default SID format config")
Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
diff --git a/zebra/zebra_srv6.c b/zebra/zebra_srv6.c
index df9aecb28d..7797f38a31 100644
--- a/zebra/zebra_srv6.c
+++ b/zebra/zebra_srv6.c
@@ -43,6 +43,8 @@ static struct zebra_srv6 g_srv6;
/* Prototypes */
static void release_srv6_sid_func(const struct zebra_srv6_sid_ctx *zctx);
+static void zebra_srv6_sid_block_wide_lib_alloc(struct zebra_srv6_sid_block *block);
+static void zebra_srv6_sid_block_wide_lib_free(struct zebra_srv6_sid_block *block);
static bool zebra_srv6_sid_compose(struct in6_addr *sid_value, struct srv6_locator *locator,
uint32_t sid_func, uint32_t sid_func_wide, bool is_localonly);
@@ -370,6 +372,8 @@ void zebra_srv6_sid_format_change_finish(struct srv6_sid_format *format)
if (format->type == SRV6_SID_FORMAT_TYPE_USID) {
block->u.usid.lib.first_available_func = format->config.usid.lib_start;
list_delete_all_node(block->u.usid.lib.func_released);
+ zebra_srv6_sid_block_wide_lib_free(block);
+ zebra_srv6_sid_block_wide_lib_alloc(block);
} else {
block->u.uncompressed.first_available_func =
SRV6_SID_FORMAT_UNCOMPRESSED_F4024_FUNC_UNRESERVED_MIN;
@@ -489,6 +493,40 @@ void delete_zebra_srv6_sid_func(void *val)
zebra_srv6_sid_func_free((uint32_t *)val);
}
+/*
+ * The Wide LIB array has one entry per function of the Wide LIB range. Keep
+ * its size, as the range can be changed while the block exists.
+ */
+static void zebra_srv6_sid_block_wide_lib_alloc(struct zebra_srv6_sid_block *block)
+{
+ struct srv6_sid_format *format = block->sid_format;
+ uint32_t func;
+
+ block->u.usid.wide_lib_size = format->config.usid.wlib_end -
+ format->config.usid.wlib_start + 1;
+ block->u.usid.wide_lib = XCALLOC(MTYPE_ZEBRA_SRV6_USID_WLIB,
+ block->u.usid.wide_lib_size * sizeof(struct wide_lib));
+ for (func = 0; func < block->u.usid.wide_lib_size; func++) {
+ block->u.usid.wide_lib[func].func_allocated = list_new();
+ block->u.usid.wide_lib[func].func_allocated->del = delete_zebra_srv6_sid_func;
+ block->u.usid.wide_lib[func].func_released = list_new();
+ block->u.usid.wide_lib[func].func_released->del = delete_zebra_srv6_sid_func;
+ block->u.usid.wide_lib[func].func = func;
+ }
+}
+
+static void zebra_srv6_sid_block_wide_lib_free(struct zebra_srv6_sid_block *block)
+{
+ uint32_t func;
+
+ for (func = 0; func < block->u.usid.wide_lib_size; func++) {
+ list_delete(&block->u.usid.wide_lib[func].func_allocated);
+ list_delete(&block->u.usid.wide_lib[func].func_released);
+ }
+ XFREE(MTYPE_ZEBRA_SRV6_USID_WLIB, block->u.usid.wide_lib);
+ block->u.usid.wide_lib_size = 0;
+}
+
/* --- Zebra SRv6 SID block management functions ---------------------------- */
static struct zebra_srv6_sid_block *zebra_srv6_sid_block_alloc_internal(void)
@@ -516,8 +554,6 @@ zebra_srv6_sid_block_alloc(struct srv6_sid_format *format,
if (format) {
if (format->type == SRV6_SID_FORMAT_TYPE_USID) {
- uint32_t wlib_start, wlib_end, func;
-
/* Init uSID LIB */
block->u.usid.lib.func_allocated = list_new();
block->u.usid.lib.func_allocated->del =
@@ -528,25 +564,7 @@ zebra_srv6_sid_block_alloc(struct srv6_sid_format *format,
block->u.usid.lib.first_available_func =
format->config.usid.lib_start;
- /* Init uSID Wide LIB */
- wlib_start = block->sid_format->config.usid.wlib_start;
- wlib_end = block->sid_format->config.usid.wlib_end;
- block->u.usid.wide_lib =
- XCALLOC(MTYPE_ZEBRA_SRV6_USID_WLIB,
- (wlib_end - wlib_start + 1) *
- sizeof(struct wide_lib));
- for (func = 0; func < wlib_end - wlib_start + 1;
- func++) {
- block->u.usid.wide_lib[func].func_allocated =
- list_new();
- block->u.usid.wide_lib[func].func_allocated->del =
- delete_zebra_srv6_sid_func;
- block->u.usid.wide_lib[func].func_released =
- list_new();
- block->u.usid.wide_lib[func].func_released->del =
- delete_zebra_srv6_sid_func;
- block->u.usid.wide_lib[func].func = func;
- }
+ zebra_srv6_sid_block_wide_lib_alloc(block);
} else if (format->type == SRV6_SID_FORMAT_TYPE_UNCOMPRESSED) {
block->u.uncompressed.func_allocated = list_new();
block->u.uncompressed.func_allocated->del =
@@ -577,24 +595,11 @@ void zebra_srv6_sid_block_free(struct zebra_srv6_sid_block *block)
{
if (block->sid_format) {
if (block->sid_format->type == SRV6_SID_FORMAT_TYPE_USID) {
- uint32_t wlib_start, wlib_end, func;
-
/* Free uSID LIB */
list_delete(&block->u.usid.lib.func_allocated);
list_delete(&block->u.usid.lib.func_released);
- /* Free uSID Wide LIB */
- wlib_start = block->sid_format->config.usid.wlib_start;
- wlib_end = block->sid_format->config.usid.wlib_end;
- for (func = 0; func < wlib_end - wlib_start + 1;
- func++) {
- list_delete(&block->u.usid.wide_lib[func]
- .func_allocated);
- list_delete(&block->u.usid.wide_lib[func]
- .func_released);
- }
- XFREE(MTYPE_ZEBRA_SRV6_USID_WLIB,
- block->u.usid.wide_lib);
+ zebra_srv6_sid_block_wide_lib_free(block);
} else if (block->sid_format->type ==
SRV6_SID_FORMAT_TYPE_UNCOMPRESSED) {
list_delete(&block->u.uncompressed.func_allocated);
diff --git a/zebra/zebra_srv6.h b/zebra/zebra_srv6.h
index 9a57e2cf89..845afe037f 100644
--- a/zebra/zebra_srv6.h
+++ b/zebra/zebra_srv6.h
@@ -105,6 +105,7 @@ struct zebra_srv6_sid_block {
/* uSID Wide LIB */
struct wide_lib *wide_lib;
+ uint32_t wide_lib_size;
} usid;
/* Information/state for uncompressed SID format */