Skip to content

Commit

Permalink
bgpd: Ensure that the correct aspath is free'd
Browse files Browse the repository at this point in the history
Currently in subgroup_default_originate the attr.aspath
is set in bgp_attr_default_set, which hashs the aspath
and creates a refcount for it.  If this is a withdraw
the subgroup_announce_check and bgp_adj_out_set_subgroup
is called which will intern the attribute.  This will
cause the the attr.aspath to be set to a new value
finally at the bottom of the function it intentionally
uninterns the aspath which is not the one that was
created for this function.  This reduces the other
aspath's refcount by 1 and if a clear bgp * is issued
fast enough the aspath for that will be removed
and the system will crash.

Signed-off-by: Donald Sharp <[email protected]>
(cherry picked from commit e613e12)
  • Loading branch information
donaldsharp authored and mergify[bot] committed Mar 14, 2024
1 parent d53dc8a commit a131ffb
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion bgpd/bgp_updgrp_adv.c
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ void subgroup_default_originate(struct update_subgroup *subgrp, int withdraw)
struct bgp *bgp;
struct attr attr;
struct attr *new_attr = &attr;
struct aspath *aspath;
struct prefix p;
struct peer *from;
struct bgp_dest *dest;
Expand Down Expand Up @@ -808,6 +809,7 @@ void subgroup_default_originate(struct update_subgroup *subgrp, int withdraw)
/* make coverity happy */
assert(attr.aspath);

aspath = attr.aspath;
attr.med = 0;
attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC);

Expand Down Expand Up @@ -963,7 +965,7 @@ void subgroup_default_originate(struct update_subgroup *subgrp, int withdraw)
}
}

aspath_unintern(&attr.aspath);
aspath_unintern(&aspath);
}

/*
Expand Down

0 comments on commit a131ffb

Please sign in to comment.