summaryrefslogtreecommitdiff
path: root/proto/ospf
diff options
context:
space:
mode:
authorMaria Matejka <mq@ucw.cz>2021-09-27 16:40:28 +0200
committerMaria Matejka <mq@ucw.cz>2021-11-22 19:05:44 +0100
commitf0507f05ce57398e135651896dace4cb68eeed54 (patch)
tree44bfd6148689af15f4f5469b2f37bca55c3e7327 /proto/ospf
parent3b20722a1fc777c27ab2e0451d0ea3fee7fa81a2 (diff)
Route sources have an explicit owner
This commit prevents use-after-free of routes belonging to protocols which have been already destroyed, delaying also all the protocols' shutdown until all of their routes have been finally propagated through all the pipes down to the appropriate exports. The use-after-free was somehow hypothetic yet theoretically possible in rare conditions, when one BGP protocol authors a lot of routes and the user deletes that protocol by reconfiguring in the same time as next hop update is requested, causing rte_better() to be called on a not-yet-pruned network prefix while the owner protocol has been already freed. In parallel execution environments, this would happen an inter-thread use-after-free, causing possible heisenbugs or other nasty problems.
Diffstat (limited to 'proto/ospf')
-rw-r--r--proto/ospf/ospf.c13
-rw-r--r--proto/ospf/ospf.h2
2 files changed, 11 insertions, 4 deletions
diff --git a/proto/ospf/ospf.c b/proto/ospf/ospf.c
index 22150590..16774df6 100644
--- a/proto/ospf/ospf.c
+++ b/proto/ospf/ospf.c
@@ -376,8 +376,8 @@ ospf_init(struct proto_config *CF)
P->reload_routes = ospf_reload_routes;
P->feed_begin = ospf_feed_begin;
P->feed_end = ospf_feed_end;
- P->rte_better = ospf_rte_better;
- P->rte_igp_metric = ospf_rte_igp_metric;
+
+ P->sources.class = &ospf_rte_owner_class;
return P;
}
@@ -488,7 +488,7 @@ ospf_preexport(struct channel *c, rte *e)
struct ospf_area *oa = ospf_main_area(p);
/* Reject our own routes */
- if (e->src->proto == c->proto)
+ if (e->sender == c->in_req.hook)
return -1;
/* Do not export routes to stub areas */
@@ -1517,6 +1517,12 @@ ospf_sh_lsadb(struct lsadb_show_data *ld)
}
+struct rte_owner_class ospf_rte_owner_class = {
+ .get_route_info = ospf_get_route_info,
+ .rte_better = ospf_rte_better,
+ .rte_igp_metric = ospf_rte_igp_metric,
+};
+
struct protocol proto_ospf = {
.name = "OSPF",
.template = "ospf%d",
@@ -1532,5 +1538,4 @@ struct protocol proto_ospf = {
.reconfigure = ospf_reconfigure,
.get_status = ospf_get_status,
.get_attr = ospf_get_attr,
- .get_route_info = ospf_get_route_info
};
diff --git a/proto/ospf/ospf.h b/proto/ospf/ospf.h
index 3e704ae8..a5f83e79 100644
--- a/proto/ospf/ospf.h
+++ b/proto/ospf/ospf.h
@@ -1007,6 +1007,8 @@ void ospf_sh_state(struct proto *P, int verbose, int reachable);
void ospf_sh_lsadb(struct lsadb_show_data *ld);
+extern struct rte_owner_class ospf_rte_owner_class;
+
/* iface.c */
void ospf_iface_chstate(struct ospf_iface *ifa, u8 state);
void ospf_iface_sm(struct ospf_iface *ifa, int event);