Skip to content

Commit dad306f

Browse files
neildgopherbot
authored andcommitted
ipv6: avoid out-of-bounds panic in ICMPFilter
Check that ICMPType is in range [0, 255] before indexing the 8-element filter array in ICMPFilter.Accept, Block, and WillBlock. Change-Id: I39f17e80aff45b2cef9c6aeb2bb84c0c6a6a6964 Reviewed-on: https://go-review.googlesource.com/c/net/+/852828 LUCI-TryBot-Result: [email protected] <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: David Chase <[email protected]> Auto-Submit: Damien Neil <[email protected]>
1 parent 9c0565a commit dad306f

5 files changed

Lines changed: 43 additions & 0 deletions

File tree

‎ipv6/icmp_bsd.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@
77
package ipv6
88

99
func (f *icmpv6Filter) accept(typ ICMPType) {
10+
if typ < 0 || int(typ>>5) >= len(f.Filt) {
11+
return
12+
}
1013
f.Filt[typ>>5] |= 1 << (uint32(typ) & 31)
1114
}
1215

1316
func (f *icmpv6Filter) block(typ ICMPType) {
17+
if typ < 0 || int(typ>>5) >= len(f.Filt) {
18+
return
19+
}
1420
f.Filt[typ>>5] &^= 1 << (uint32(typ) & 31)
1521
}
1622

@@ -25,5 +31,8 @@ func (f *icmpv6Filter) setAll(block bool) {
2531
}
2632

2733
func (f *icmpv6Filter) willBlock(typ ICMPType) bool {
34+
if typ < 0 || int(typ>>5) >= len(f.Filt) {
35+
return false
36+
}
2837
return f.Filt[typ>>5]&(1<<(uint32(typ)&31)) == 0
2938
}

‎ipv6/icmp_linux.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@
55
package ipv6
66

77
func (f *icmpv6Filter) accept(typ ICMPType) {
8+
if typ < 0 || int(typ>>5) >= len(f.Data) {
9+
return
10+
}
811
f.Data[typ>>5] &^= 1 << (uint32(typ) & 31)
912
}
1013

1114
func (f *icmpv6Filter) block(typ ICMPType) {
15+
if typ < 0 || int(typ>>5) >= len(f.Data) {
16+
return
17+
}
1218
f.Data[typ>>5] |= 1 << (uint32(typ) & 31)
1319
}
1420

@@ -23,5 +29,8 @@ func (f *icmpv6Filter) setAll(block bool) {
2329
}
2430

2531
func (f *icmpv6Filter) willBlock(typ ICMPType) bool {
32+
if typ < 0 || int(typ>>5) >= len(f.Data) {
33+
return false
34+
}
2635
return f.Data[typ>>5]&(1<<(uint32(typ)&31)) != 0
2736
}

‎ipv6/icmp_solaris.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@
55
package ipv6
66

77
func (f *icmpv6Filter) accept(typ ICMPType) {
8+
if typ < 0 || int(typ>>5) >= len(f.X__icmp6_filt) {
9+
return
10+
}
811
f.X__icmp6_filt[typ>>5] |= 1 << (uint32(typ) & 31)
912
}
1013

1114
func (f *icmpv6Filter) block(typ ICMPType) {
15+
if typ < 0 || int(typ>>5) >= len(f.X__icmp6_filt) {
16+
return
17+
}
1218
f.X__icmp6_filt[typ>>5] &^= 1 << (uint32(typ) & 31)
1319
}
1420

@@ -23,5 +29,8 @@ func (f *icmpv6Filter) setAll(block bool) {
2329
}
2430

2531
func (f *icmpv6Filter) willBlock(typ ICMPType) bool {
32+
if typ < 0 || int(typ>>5) >= len(f.X__icmp6_filt) {
33+
return false
34+
}
2635
return f.X__icmp6_filt[typ>>5]&(1<<(uint32(typ)&31)) == 0
2736
}

‎ipv6/icmp_test.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ func TestICMPFilter(t *testing.T) {
5757
t.Errorf("ipv6.ICMPFilter.Set(%v, true) failed", typ)
5858
}
5959
}
60+
for _, typ := range []ipv6.ICMPType{-1, 256} {
61+
f.Accept(typ)
62+
f.Block(typ)
63+
if f.WillBlock(typ) {
64+
t.Errorf("ipv6.ICMPFilter.WillBlock(%v) = true; want false", typ)
65+
}
66+
}
6067
}
6168
}
6269

‎ipv6/icmp_zos.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@
55
package ipv6
66

77
func (f *icmpv6Filter) accept(typ ICMPType) {
8+
if typ < 0 || int(typ>>5) >= len(f.Filt) {
9+
return
10+
}
811
f.Filt[typ>>5] |= 1 << (uint32(typ) & 31)
912

1013
}
1114

1215
func (f *icmpv6Filter) block(typ ICMPType) {
16+
if typ < 0 || int(typ>>5) >= len(f.Filt) {
17+
return
18+
}
1319
f.Filt[typ>>5] &^= 1 << (uint32(typ) & 31)
1420

1521
}
@@ -25,5 +31,8 @@ func (f *icmpv6Filter) setAll(block bool) {
2531
}
2632

2733
func (f *icmpv6Filter) willBlock(typ ICMPType) bool {
34+
if typ < 0 || int(typ>>5) >= len(f.Filt) {
35+
return false
36+
}
2837
return f.Filt[typ>>5]&(1<<(uint32(typ)&31)) == 0
2938
}

0 commit comments

Comments
 (0)