Skip to content

Commit f30598d

Browse files
joneskoobradfitz
authored andcommitted
crypto/tls: Add mutex to protect KeyLogWriter
Concurrent use of tls.Config is allowed, and may lead to KeyLogWriter being written to concurrently. Without a mutex to protect it, corrupted output may occur. A mutex is added for correctness. The mutex is made global to save size of the config struct as KeyLogWriter is rarely enabled. Related to #13057. Change-Id: I5ee55b6d8b43a191ec21f06e2aaae5002a71daef Reviewed-on: https://go-review.googlesource.com/29016 Reviewed-by: Brad Fitzpatrick <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent c564aeb commit f30598d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/crypto/tls/common.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,10 +643,16 @@ func (c *Config) writeKeyLog(clientRandom, masterSecret []byte) error {
643643
if c.KeyLogWriter == nil {
644644
return nil
645645
}
646+
writerMutex.Lock()
646647
_, err := fmt.Fprintf(c.KeyLogWriter, "CLIENT_RANDOM %x %x\n", clientRandom, masterSecret)
648+
writerMutex.Unlock()
647649
return err
648650
}
649651

652+
// writerMutex protects all KeyLogWriters globally. It is rarely enabled,
653+
// and is only for debugging, so a global mutex saves space.
654+
var writerMutex sync.Mutex
655+
650656
// A Certificate is a chain of one or more certificates, leaf first.
651657
type Certificate struct {
652658
Certificate [][]byte

0 commit comments

Comments
 (0)