Skip to content
This repository was archived by the owner on Jun 9, 2024. It is now read-only.

Commit 2882307

Browse files
author
David Haynes
committed
VULN-8286: Prevent oob read when validating IP ranges
1 parent 69bf56a commit 2882307

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

validator/lib/cert.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ func (ipn *IPNet) GetAfi() uint8 {
6262
}
6363

6464
func (ipn *IPNet) GetRange() (net.IP, net.IP, bool) {
65-
min, max := GetRangeIP(ipn.IPNet)
65+
err, min, max := GetRangeIP(ipn.IPNet)
66+
if err != nil {
67+
return nil, nil, false
68+
}
6669
return min, max, false
6770
}
6871

@@ -474,6 +477,9 @@ func ValidateIPCertificateList(list []IPCertificateInformation, parent *RPKICert
474477
valids = append(valids, ip)
475478
continue
476479
}
480+
if min == nil && max == nil {
481+
invalids = append(invalids, ip)
482+
}
477483
valid, checkParent := parent.IsIPRangeInCertificate(min, max)
478484
if valid {
479485
valids = append(valids, ip)

validator/lib/roa.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,21 @@ func EncodeROAEntries(asn int, entries []*ROAEntry) (*ROA, error) {
133133
return roa, nil
134134
}
135135

136-
func GetRangeIP(ipnet *net.IPNet) (net.IP, net.IP) {
136+
func GetRangeIP(ipnet *net.IPNet) (error, net.IP, net.IP) {
137137
ip := ipnet.IP
138138
mask := ipnet.Mask
139139

140140
beginIP := make([]byte, len(ip))
141141
endIP := make([]byte, len(ip))
142142
for i := range []byte(ip) {
143+
// GHSA-w6ww-fmfx-2x22: Prevent oob read
144+
if i >= len(mask) {
145+
return errors.New("Invalid IP address mask"), nil, nil
146+
}
143147
beginIP[i] = ip[i] & mask[i]
144148
endIP[i] = ip[i] | ^mask[i]
145149
}
146-
return net.IP(beginIP), net.IP(endIP)
150+
return nil, net.IP(beginIP), net.IP(endIP)
147151
}
148152

149153
// https://tools.ietf.org/html/rfc6480#section-2.3
@@ -191,7 +195,10 @@ func ValidateIPRoaCertificateList(entries []*ROAEntry, cert *RPKICertificate) ([
191195
invalids := make([]*ROAEntry, 0)
192196
checkParents := make([]*ROAEntry, 0)
193197
for _, entry := range entries {
194-
min, max := GetRangeIP(entry.IPNet)
198+
err, min, max := GetRangeIP(entry.IPNet)
199+
if err != nil {
200+
invalids = append(invalids, entry)
201+
}
195202
valid, checkParent := cert.IsIPRangeInCertificate(min, max)
196203
if valid {
197204
valids = append(valids, entry)

0 commit comments

Comments
 (0)