Skip to content

Commit

Permalink
Clone OriginInfo in Path Clone
Browse files Browse the repository at this point in the history
OriginInfo assigned to Path objects is a pointer to the originating
peer's info, which is populated by the FSM goroutine handling the peer's
connection. This value is typically protected by the FSM lock, but in
the event a path watch is running, it gets converted to a protobuf
object in toPathAPI in a separate goroutine. This method reads from this
same structure without any data synchronisation, leading to a data
race.

To ensure this cannot happen, this commit adds a line to clone the field
before it is passed to the event watcher, ensuring the data race cannot
occur.
  • Loading branch information
dawn-minion committed Oct 3, 2023
1 parent 146b2b8 commit fc95068
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/pkg/table/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,14 @@ func (path *Path) IsIBGP() bool {

// create new PathAttributes
func (path *Path) Clone(isWithdraw bool) *Path {
newOriginInfo := *path.info

return &Path{
parent: path,
IsWithdraw: isWithdraw,
IsNexthopInvalid: path.IsNexthopInvalid,
attrsHash: path.attrsHash,
info: &newOriginInfo,
}
}

Expand Down

0 comments on commit fc95068

Please sign in to comment.