diff options
author | Maria Matejka <mq@ucw.cz> | 2021-09-27 16:40:28 +0200 |
---|---|---|
committer | Maria Matejka <mq@ucw.cz> | 2021-11-22 19:05:44 +0100 |
commit | f0507f05ce57398e135651896dace4cb68eeed54 (patch) | |
tree | 44bfd6148689af15f4f5469b2f37bca55c3e7327 /sysdep | |
parent | 3b20722a1fc777c27ab2e0451d0ea3fee7fa81a2 (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 'sysdep')
-rw-r--r-- | sysdep/unix/krt.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/sysdep/unix/krt.c b/sysdep/unix/krt.c index 609ee921..5431bebe 100644 --- a/sysdep/unix/krt.c +++ b/sysdep/unix/krt.c @@ -294,8 +294,9 @@ krt_rte_better(rte *a, rte *b) static void krt_learn_rte(struct krt_proto *p, rte *e) { - e->src = rt_get_source(&p->p, krt_metric(e)); + struct rte_src *src = e->src = rt_get_source(&p->p, krt_metric(e)); rte_update(p->p.main_channel, e->net, e, e->src); + rt_unlock_source(src); } static void @@ -674,7 +675,7 @@ krt_scan_timer_kick(struct krt_proto *p) static int krt_preexport(struct channel *c, rte *e) { - if (e->src->proto == c->proto) + if (e->src->owner == &c->proto->sources) return -1; if (!krt_capable(e)) |