Avoid panic opportunity for TCP keep-alive timers

There is a panic opportunity if the timer fires but the socket is
going through cleanup. In this case `e.route` might go away but the
timer handler for keep-alive continues to execute and causes panics.
The fix is to return early from the handler if we find out the route
is already removed.

PiperOrigin-RevId: 619268432
This commit is contained in:
Zeling Feng
2024-03-26 12:07:59 -07:00
committed by gVisor bot
parent e902007771
commit ff7dbbfe24
+5
View File
@@ -1292,6 +1292,11 @@ func (e *Endpoint) handleSegmentLocked(s *segment) (cont bool, err tcpip.Error)
func (e *Endpoint) keepaliveTimerExpired() tcpip.Error {
userTimeout := e.userTimeout
// If the route is not ready or already cleaned up, then we don't need to
// send keepalives.
if e.route == nil {
return nil
}
e.keepalive.Lock()
if !e.SocketOptions().GetKeepAlive() || e.keepalive.timer.isUninitialized() || !e.keepalive.timer.checkExpiration() {
e.keepalive.Unlock()