Skip to content

Commit 82e7868

Browse files
neildgopherbot
authored andcommitted
dns/dnsmessage: avoid panic when parsing SVCB record with truncated data
Thanks to Mundur (https://github.com/M0nd0R) for reporting this issue. Fixes golang/go#79795 Fixes CVE-2026-46600 Change-Id: Ie32a9dae6789eb98c816bc7508feba686a6a6964 Reviewed-on: https://go-review.googlesource.com/c/net/+/786345 LUCI-TryBot-Result: [email protected] <[email protected]> Auto-Submit: Damien Neil <[email protected]> Reviewed-by: Nicholas Husin <[email protected]> Reviewed-by: Nicholas Husin <[email protected]>
1 parent b64f1fa commit 82e7868

2 files changed

Lines changed: 50 additions & 11 deletions

File tree

‎dns/dnsmessage/message_test.go‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,3 +1924,39 @@ func TestBuilderCompressionInAppendMode(t *testing.T) {
19241924
t.Fatalf("msg[maxPtr:] = %v, want: %v", msg[maxPtr:], expect)
19251925
}
19261926
}
1927+
1928+
func TestInvalidMessages(t *testing.T) {
1929+
for _, test := range []struct {
1930+
name string
1931+
in []byte
1932+
}{
1933+
{
1934+
name: "invalid SVCB",
1935+
in: []byte{
1936+
0x12, 0x34, 0x81, 0x80, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
1937+
0x00, 0x00, 0x41, 0x00, 0x01,
1938+
0x00, 0x00, 0x41, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
1939+
0x00, 0x64,
1940+
0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x5d,
1941+
},
1942+
},
1943+
} {
1944+
t.Run(test.name, func(t *testing.T) {
1945+
var p Parser
1946+
_, err := p.Start(test.in)
1947+
if err != nil {
1948+
return
1949+
}
1950+
_, err = p.AllQuestions()
1951+
if err != nil {
1952+
return
1953+
}
1954+
_, err = p.AllAnswers()
1955+
if err != nil {
1956+
return
1957+
}
1958+
t.Errorf("successfully parsed message: want error")
1959+
t.Errorf("message: {%x}", test.in)
1960+
})
1961+
}
1962+
}

‎dns/dnsmessage/svcb.go‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func unpackSVCBResource(msg []byte, off int, length uint16) (SVCBResource, error
205205
off = paramsOff
206206
var previousKey uint16
207207
for off < bodyEnd {
208-
var key, len uint16
208+
var key, size uint16
209209
if key, off, err = unpackUint16(msg, off); err != nil {
210210
return SVCBResource{}, &nestedError{"Params key", err}
211211
}
@@ -214,14 +214,14 @@ func unpackSVCBResource(msg []byte, off int, length uint16) (SVCBResource, error
214214
// consider the RR malformed if the SvcParamKeys are not in strictly increasing numeric order
215215
return SVCBResource{}, &nestedError{"Params", errParamOutOfOrder}
216216
}
217-
if len, off, err = unpackUint16(msg, off); err != nil {
217+
if size, off, err = unpackUint16(msg, off); err != nil {
218218
return SVCBResource{}, &nestedError{"Params value length", err}
219219
}
220-
if off+int(len) > bodyEnd {
220+
if off+int(size) > bodyEnd {
221221
return SVCBResource{}, errResourceLen
222222
}
223-
totalValueLen += len
224-
off += int(len)
223+
totalValueLen += size
224+
off += int(size)
225225
n++
226226
}
227227
if off != bodyEnd {
@@ -236,20 +236,23 @@ func unpackSVCBResource(msg []byte, off int, length uint16) (SVCBResource, error
236236
off = paramsOff
237237
for i := 0; i < n; i++ {
238238
p := &r.Params[i]
239-
var key, len uint16
239+
var key, size uint16
240240
if key, off, err = unpackUint16(msg, off); err != nil {
241241
return SVCBResource{}, &nestedError{"param key", err}
242242
}
243243
p.Key = SVCParamKey(key)
244-
if len, off, err = unpackUint16(msg, off); err != nil {
244+
if size, off, err = unpackUint16(msg, off); err != nil {
245245
return SVCBResource{}, &nestedError{"param length", err}
246246
}
247-
if copy(valuesBuf, msg[off:off+int(len)]) != int(len) {
247+
if len(msg[off:]) < int(size) {
248248
return SVCBResource{}, &nestedError{"param value", errCalcLen}
249249
}
250-
p.Value = valuesBuf[:len:len]
251-
valuesBuf = valuesBuf[len:]
252-
off += int(len)
250+
if copy(valuesBuf, msg[off:][:int(size)]) != int(size) {
251+
return SVCBResource{}, &nestedError{"param value", errCalcLen}
252+
}
253+
p.Value = valuesBuf[:size:size]
254+
valuesBuf = valuesBuf[size:]
255+
off += int(size)
253256
}
254257

255258
return r, nil

0 commit comments

Comments
 (0)