Commit 48d3703289 for frr
commit 48d37032899ef1c8d5dd06f144700ff44c2eea38
Author: Floatato <2264667392@qq.com>
Date: Tue Nov 10 15:14:47 2026 +0800
ospfd: fix opaque per-type cleanup use-after-free
list_delete() of an area, link, or AS opaque_lsa_self list frees each
node after its destructor returns, without unlinking it first. The
destructor flushed every self-originated LSA through
ospf_opaque_lsa_flush_schedule(), which looks the opaque type up by
walking that same list from the head. The second and later types then
read list nodes freed for the earlier types.
Flush from the per-type object the destructor already holds, and keep
the public lookup path for callers that still have a live owner list.
Signed-off-by: Floatato <2264667392@qq.com>
diff --git a/ospfd/ospf_opaque.c b/ospfd/ospf_opaque.c
index 633eb46a8e..6ebd47bcfb 100644
--- a/ospfd/ospf_opaque.c
+++ b/ospfd/ospf_opaque.c
@@ -550,6 +550,8 @@ register_opaque_info_per_id(struct opaque_info_per_type *oipt,
static struct opaque_info_per_id *
lookup_opaque_info_by_id(struct opaque_info_per_type *oipt,
struct ospf_lsa *lsa);
+static void ospf_opaque_lsa_flush_oipt(struct opaque_info_per_type *oipt,
+ struct ospf_lsa *lsa0);
static struct opaque_info_per_id *register_opaque_lsa(struct ospf_lsa *new);
@@ -621,7 +623,12 @@ static void free_opaque_info_per_type(struct opaque_info_per_type *oipt,
continue;
if (IS_LSA_MAXAGE(lsa))
continue;
- ospf_opaque_lsa_flush_schedule(lsa);
+ /*
+ * Flush from the per-type object we already hold. Looking the
+ * type up again walks the owner list, which list_delete() is
+ * in the middle of freeing.
+ */
+ ospf_opaque_lsa_flush_oipt(oipt, lsa);
}
event_cancel(&oipt->t_opaque_lsa_self);
@@ -2121,17 +2128,16 @@ static void ospf_opaque_lsa_refresh_timer(struct event *t)
(*functab->lsa_refresher)(lsa);
}
-void ospf_opaque_lsa_flush_schedule(struct ospf_lsa *lsa0)
+static void ospf_opaque_lsa_flush_oipt(struct opaque_info_per_type *oipt,
+ struct ospf_lsa *lsa0)
{
- struct opaque_info_per_type *oipt;
struct opaque_info_per_id *oipi;
struct ospf_lsa *lsa;
struct ospf *top;
top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
- if ((oipt = lookup_opaque_info_by_type(lsa0)) == NULL
- || (oipi = lookup_opaque_info_by_id(oipt, lsa0)) == NULL) {
+ if ((oipi = lookup_opaque_info_by_id(oipt, lsa0)) == NULL) {
flog_warn(EC_OSPF_LSA, "%s: Invalid parameter?", __func__);
goto out;
}
@@ -2190,6 +2196,19 @@ out:
return;
}
+void ospf_opaque_lsa_flush_schedule(struct ospf_lsa *lsa0)
+{
+ struct opaque_info_per_type *oipt;
+
+ oipt = lookup_opaque_info_by_type(lsa0);
+ if (oipt == NULL) {
+ flog_warn(EC_OSPF_LSA, "%s: Invalid parameter?", __func__);
+ return;
+ }
+
+ ospf_opaque_lsa_flush_oipt(oipt, lsa0);
+}
+
void ospf_opaque_self_originated_lsa_received(struct ospf_neighbor *nbr,
struct ospf_lsa *lsa)
{