Skip to content

lib: fix use-after-free of src_table in srcdest_srcnode_destroy - #22722

Open
nsoma-cisco wants to merge 1 commit into
FRRouting:masterfrom
nsoma-cisco:nsoma_master_zebra_uaf_src_tbl
Open

lib: fix use-after-free of src_table in srcdest_srcnode_destroy#22722
nsoma-cisco wants to merge 1 commit into
FRRouting:masterfrom
nsoma-cisco:nsoma_master_zebra_uaf_src_tbl

Conversation

@nsoma-cisco

Copy link
Copy Markdown
Contributor

Summary

Fix a use-after-free of src_table in
lib/srcdest_table.c:srcdest_srcnode_destroy().

Root cause

srcdest_srcnode_destroy() freed srn->src_table via route_table_finish()
before nulling the pointer. After route_table_finish() returned,
srn->src_table still held the address of the freed route_table struct.

A subsequent dplane FIB notification for the same destination prefix calls
srcdest_rnode_get() → srcdest_srcnode_get(), which guards new-table creation
with if (!srn->src_table). Because the pointer was non-NULL (dangling), the
guard evaluated false and the freed struct was passed to route_node_get(),
causing a SIGSEGV.

route_table_finish() can also re-enter srcdest_srcnode_destroy() for the
remaining nodes during the finish sweep
(route_table_free → route_node_free → destroy_node); any such re-entrant read
of srn->src_table observed the same dangling pointer.

Fix

Null srn->src_table before calling route_table_finish(), mirroring the
identical null-before-finish pattern already present and commented in
srcdest_rnode_destroy():

struct route_table *src_table = srn->src_table;

srn->src_table = NULL;
route_table_finish(src_table);

With the pointer nulled first, any re-entrant call to
srcdest_srcnode_destroy() during the finish sweep sees NULL and exits
cleanly, and any subsequent call to srcdest_srcnode_get() allocates a fresh,
valid route_table instead of dereferencing freed memory.

Test plan

  • Rebuild and load on an affected setup
  • Exercise EVPN/VXLAN multi-homing route teardown that previously crashed
  • Confirm no zebra core is generated and route state stays consistent

@greptile-apps

greptile-apps Bot commented Jul 21, 2026

Copy link
Copy Markdown

Greptile Summary

This PR prevents a dangling source-table pointer during route teardown. The main changes are:

  • Saves the source table pointer before cleanup.
  • Clears srn->src_table before synchronous table destruction.
  • Preserves the existing reference release after cleanup.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.
  • Re-entrant destruction skips duplicate cleanup after the pointer is cleared.
  • The destination node remains referenced until table cleanup completes.

Important Files Changed

Filename Overview
lib/srcdest_table.c Reorders source-table cleanup so re-entrant destruction observes a null pointer instead of freed storage.

Reviews (1): Last reviewed commit: "lib: Fix use-after-free of src_table in ..." | Re-trigger Greptile

@nsoma-cisco nsoma-cisco changed the title lib: Fix use-after-free of src_table in srcdest_srcnode_destroy lib: fix use-after-free of src_table in srcdest_srcnode_destroy Jul 21, 2026
@nsoma-cisco
nsoma-cisco force-pushed the nsoma_master_zebra_uaf_src_tbl branch 2 times, most recently from 7310525 to be9f1df Compare July 27, 2026 18:50
Null srn->src_table before calling route_table_finish so that
any re-entrant call to srcdest_srcnode_destroy (via route_table_free
→ route_node_free → destroy_node during the finish sweep) reads NULL
rather than a pointer to memory that is already being freed.

Without this, route_table_finish frees the route_table struct while
srn->src_table still points to it.  A subsequent dplane FIB
notification for the same destination prefix calls
srcdest_rnode_get → srcdest_srcnode_get, which checks
`if (!srn->src_table)` — the guard evaluates false because the
pointer is non-NULL (dangling) — and passes the freed struct to
route_node_get, causing a SIGSEGV.

This mirrors the identical null-before-finish pattern already used
in srcdest_rnode_destroy and described in its comment.

Signed-off-by: Nageswara Soma <nsoma@cisco.com>
@nsoma-cisco
nsoma-cisco force-pushed the nsoma_master_zebra_uaf_src_tbl branch from be9f1df to d1b43cd Compare July 30, 2026 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant