good morning!!!!

Skip to content
Snippets Groups Projects
Unverified Commit 129d3035 authored by Anmol Sethi's avatar Anmol Sethi
Browse files

Fix DOS attack from malicious pongs

A double channel close panic was possible if a peer sent back multiple
pongs for every ping.

If the second pong arrived before the ping goroutine deleted its channel
from the map, the channel would be closed twice and so a panic would
ensue.

This fixes that by having the read goroutine send on the ping
goroutine's channel rather than closing it.

Reported via email by Tibor Kálmán @kalmant

Please update to the new release ASAP!
parent e4c3b0f8
No related branches found
No related tags found
No related merge requests found
...@@ -189,7 +189,7 @@ func (c *Conn) Ping(ctx context.Context) error { ...@@ -189,7 +189,7 @@ func (c *Conn) Ping(ctx context.Context) error {
} }
func (c *Conn) ping(ctx context.Context, p string) error { func (c *Conn) ping(ctx context.Context, p string) error {
pong := make(chan struct{}) pong := make(chan struct{}, 1)
c.activePingsMu.Lock() c.activePingsMu.Lock()
c.activePings[p] = pong c.activePings[p] = pong
......
...@@ -271,7 +271,10 @@ func (c *Conn) handleControl(ctx context.Context, h header) (err error) { ...@@ -271,7 +271,10 @@ func (c *Conn) handleControl(ctx context.Context, h header) (err error) {
pong, ok := c.activePings[string(b)] pong, ok := c.activePings[string(b)]
c.activePingsMu.Unlock() c.activePingsMu.Unlock()
if ok { if ok {
close(pong) select {
case pong <- struct{}{}:
default:
}
} }
return nil return nil
} }
......
  • a @elee

    mentioned in commit 7c87cb5f

    ·

    mentioned in commit 7c87cb5f

    Toggle commit list
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment