google / gvisor

Application Kernel for Containers
https://gvisor.dev
Apache License 2.0
15.81k stars 1.3k forks source link

Netstack data race between Stack.RemoveAddress() and Route.WritePacket() #789

Closed windom closed 5 years ago

windom commented 5 years ago

Hi! Just found this data race, using 24ecce5dbf7673ab09669aae06d78d455862d47a:

==================
WARNING: DATA RACE
Write at 0x00c00016cbf8 by goroutine 22:
  github.com/google/netstack/tcpip/stack.(*NIC).removePermanentAddressLocked()
      github.com/google/netstack/tcpip/stack/nic.go:472 +0xe6
  github.com/google/netstack/tcpip/stack.(*NIC).RemoveAddress()
      github.com/google/netstack/tcpip/stack/nic.go:482 +0x98
  github.com/google/netstack/tcpip/stack.(*Stack).RemoveAddress()
      github.com/google/netstack/tcpip/stack/stack.go:853 +0x109
.....

Previous read at 0x00c00016cbf8 by goroutine 114:
  github.com/google/netstack/tcpip/stack.(*Route).WritePacket()
      github.com/google/netstack/tcpip/stack/nic.go:769 +0x82
  github.com/google/netstack/tcpip/transport/tcp.sendTCP()
      github.com/google/netstack/tcpip/transport/tcp/connect.go:632 +0x5a5
  github.com/google/netstack/tcpip/transport/tcp.(*endpoint).sendRaw()
      github.com/google/netstack/tcpip/transport/tcp/connect.go:681 +0x27b
  github.com/google/netstack/tcpip/transport/tcp.(*endpoint).protocolMainLoop.func4()
      github.com/google/netstack/tcpip/transport/tcp/connect.go:727 +0x412
  github.com/google/netstack/tcpip/transport/tcp.(*endpoint).protocolMainLoop()
      github.com/google/netstack/tcpip/transport/tcp/connect.go:1069 +0x933
hbhasker commented 5 years ago

Thanks for reporting this. I believe this was introduced in a recent change to fix behaviour around adding/removing addresses.

hbhasker commented 5 years ago

To be precise I believe it might have been introduced in this commit https://github.com/google/gvisor/commit/ac2200b8a9c269926d2eb98a7c23be79b4738fcf

tamird commented 5 years ago

@ckuiper