Skip to content

Commit

Permalink
ospfd: Prevent use after free( and crash of ospf ) when no router ospf
Browse files Browse the repository at this point in the history
Consider this config:

router ospf
  redistribute kernel

Then you issue:

no router ospf

ospf will crash with a use after free.

The problem is that the event's associated with the
ospf pointer were shut off then the ospf_external_delete
was called which rescheduled the event.  Let's just move
event deletion to the end of the no router ospf.

Signed-off-by: Donald Sharp <[email protected]>
  • Loading branch information
donaldsharp committed Aug 30, 2023
1 parent 6ed4740 commit 530be6a
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions ospfd/ospfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -806,25 +806,6 @@ static void ospf_finish_final(struct ospf *ospf)
ospf_area_free(area);
}

/* Cancel all timers. */
EVENT_OFF(ospf->t_read);
EVENT_OFF(ospf->t_write);
EVENT_OFF(ospf->t_spf_calc);
EVENT_OFF(ospf->t_ase_calc);
EVENT_OFF(ospf->t_maxage);
EVENT_OFF(ospf->t_maxage_walker);
EVENT_OFF(ospf->t_abr_task);
EVENT_OFF(ospf->t_abr_fr);
EVENT_OFF(ospf->t_asbr_check);
EVENT_OFF(ospf->t_asbr_redist_update);
EVENT_OFF(ospf->t_distribute_update);
EVENT_OFF(ospf->t_lsa_refresher);
EVENT_OFF(ospf->t_opaque_lsa_self);
EVENT_OFF(ospf->t_sr_update);
EVENT_OFF(ospf->t_default_routemap_timer);
EVENT_OFF(ospf->t_external_aggr);
EVENT_OFF(ospf->gr_info.t_grace_period);

LSDB_LOOP (OPAQUE_AS_LSDB(ospf), rn, lsa)
ospf_discard_from_db(ospf, ospf->lsdb, lsa);
LSDB_LOOP (EXTERNAL_LSDB(ospf), rn, lsa)
Expand Down Expand Up @@ -912,8 +893,26 @@ static void ospf_finish_final(struct ospf *ospf)
}
}

route_table_finish(ospf->rt_aggr_tbl);
/* Cancel all timers. */
EVENT_OFF(ospf->t_read);
EVENT_OFF(ospf->t_write);
EVENT_OFF(ospf->t_spf_calc);
EVENT_OFF(ospf->t_ase_calc);
EVENT_OFF(ospf->t_maxage);
EVENT_OFF(ospf->t_maxage_walker);
EVENT_OFF(ospf->t_abr_task);
EVENT_OFF(ospf->t_abr_fr);
EVENT_OFF(ospf->t_asbr_check);
EVENT_OFF(ospf->t_asbr_redist_update);
EVENT_OFF(ospf->t_distribute_update);
EVENT_OFF(ospf->t_lsa_refresher);
EVENT_OFF(ospf->t_opaque_lsa_self);
EVENT_OFF(ospf->t_sr_update);
EVENT_OFF(ospf->t_default_routemap_timer);
EVENT_OFF(ospf->t_external_aggr);
EVENT_OFF(ospf->gr_info.t_grace_period);

route_table_finish(ospf->rt_aggr_tbl);

ospf_free_refresh_queue(ospf);

Expand Down

0 comments on commit 530be6a

Please sign in to comment.