File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -375,11 +375,9 @@ func (s *StdNetBind) Closed() bool {
375375}
376376
377377func (s * StdNetBind ) Close () error {
378- if s .closed .Load () {
379- log .W ("wg: bind: %s already closed" , s .id )
380- return nil
381- }
382-
378+ // Do NOT do a pre-lock s.closed.Load() check here.
379+ // Open() writes s.closed under s.mu; a read outside the lock races with it.
380+ // The CAS below (also under s.mu) is the only correct guard.
383381 s .mu .Lock ()
384382 defer s .mu .Unlock ()
385383
@@ -610,8 +608,12 @@ func (s *StdNetBind) BatchSize() int {
610608
611609// from: github.com/WireGuard/wireguard-go/blob/1417a47c8/conn/mark_unix.go
612610func (s * StdNetBind ) SetMark (mark uint32 ) (err error ) {
611+ // s.ipv4 and s.ipv6 are written by Open/Close under s.mu; read them here
612+ // under the same lock to avoid a data race.
613+ s .mu .Lock ()
613614 uc4 , _ := s .ipv4 .(core.ControlConn ) // may be nil
614615 uc6 , _ := s .ipv6 .(core.ControlConn ) // may be nil
616+ s .mu .Unlock ()
615617 var operr error
616618 var raw4 , raw6 syscall.RawConn
617619 fwmarkIoctl := 36 /* unix.SO_MARK */
@@ -641,7 +643,7 @@ func (s *StdNetBind) SetMark(mark uint32) (err error) {
641643 }
642644 } // else: return err
643645 }
644- log .I ("wg: bind: %s set mark; err? %v" , err , s .id )
646+ log .I ("wg: bind: %s set mark; err? %v" , s .id , err )
645647 return nil
646648}
647649
You can’t perform that action at this time.
0 commit comments