From 8105dbbcc533ef802a4f29178dda6263b992883e Mon Sep 17 00:00:00 2001 From: Marcelo Balbinot Date: Thu, 12 Nov 2026 02:07:35 -0300 Subject: [PATCH] Table: Do not keep the next hop update sentinel on stack rt_next_hop_update_net() publishes a stack-allocated spinlock sentinel into n->routes. A lockless reader (e.g. rt_feed_net_best()) may load that pointer just before the writer restores n->routes and returns. The reader then checks REF_OBSOLETE on a stack frame which may already be reused, misses the flag and copies garbage as the best route. Observed in production as SIGSEGV in bgp_preexport() (rte with src == NULL) and in rt_export_release() (feed->ni computed from net == NULL). The copied block[0] was either all zeros or exactly { flags = REF_OBSOLETE, rest zero }, i.e. an image of the sentinel. Use a thread-local static sentinel, as rte_recalculate() already does, so the memory stays valid and always carries REF_OBSOLETE. Co-Authored-By: Claude Opus 5.5 --- nest/rt-table.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/nest/rt-table.c b/nest/rt-table.c index dee6167..ad6a7ab 100644 --- a/nest/rt-table.c +++ b/nest/rt-table.c @@ -4731,11 +4731,11 @@ rt_next_hop_update_net(struct rtable_private *tab, struct netindex *ni, net *n) if (!mod) return; - /* We add a spinlock sentinel to the beginning */ - struct rte_storage local_sentinel = { - .flags = REF_OBSOLETE, - .next = old_best, - }; + /* We add a spinlock sentinel to the beginning. It must not live on stack: + * lockless readers may still hold its pointer after we release the net + * and return, and they rely on it staying REF_OBSOLETE to retry. */ + _Thread_local static struct rte_storage local_sentinel = { .flags = REF_OBSOLETE, }; + atomic_store_explicit(&local_sentinel.next, old_best, memory_order_release); atomic_store_explicit(&n->routes, &local_sentinel, memory_order_release); /* Now we mark all the old routes obsolete */ -- 2.50.1 (Apple Git-155)