Skip to content

Commit

Permalink
Fix for CVE-2017-15133 TCP DOS (#631)
Browse files Browse the repository at this point in the history
serveTCP calls reader.ReadTCP in the accept loop rather than in
the per-connection goroutine. If an attacker opens a connection
and leaves it idle, this will block the accept loop until the
connection times out (2s by default). During this time no other
incoming connections will succeed, preventing legitimate queries
from being answered.

This commit moves the call to reader.ReadTCP into the per-connection
goroutine. It also adds a missing call to Close whose absence allowed
file-descirptors to leak in select cases.

This attack and fix have no impact on serving UDP queries.
  • Loading branch information
miekg authored Jan 25, 2018
1 parent 862243b commit 43913f2
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,11 +472,14 @@ func (srv *Server) serveTCP(l net.Listener) error {
}
return err
}
m, err := reader.ReadTCP(rw, rtimeout)
if err != nil {
continue
}
go srv.serve(rw.RemoteAddr(), handler, m, nil, nil, rw)
go func() {
m, err := reader.ReadTCP(rw, rtimeout)
if err != nil {
rw.Close()
return
}
srv.serve(rw.RemoteAddr(), handler, m, nil, nil, rw)
}()
}
}

Expand Down

0 comments on commit 43913f2

Please sign in to comment.