Skip to content

Commit

Permalink
Fixed HBH ext parse panic when start >= end (#3674)
Browse files Browse the repository at this point in the history
Authored-by: Alexander Kunze <akgitofficial@gmail.com>
  • Loading branch information
AlexanderKunze authored Mar 12, 2020
1 parent 8309fa8 commit 4f5a93b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions go/border/rpkt/extns.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package rpkt

import (
"github.com/scionproto/scion/go/lib/assert"
"github.com/scionproto/scion/go/lib/common"
"github.com/scionproto/scion/go/lib/scmp"
"github.com/scionproto/scion/go/lib/serrors"
Expand All @@ -36,11 +37,16 @@ type rExtension interface {
const (
// FIXME(kormat): remove when generic header walker is implemented.
ErrExtChainTooLong common.ErrMsg = "Extension header chain longer than packet"
ErrExtChainCorrupt common.ErrMsg = "Extension header specifies invalid size"
)

// extnParseHBH parses a specified hop-by-hop extension in a packet.
func (rp *RtrPkt) extnParseHBH(extType common.ExtnType,
start, end, pos int) (rExtension, error) {
if assert.On {
assert.Must(end-start+common.ExtnSubHdrLen >= common.LineLen,
"Extension must be at least one line length")
}
switch {
case extType == common.ExtnSCMPType:
return rSCMPExtFromRaw(rp, start, end)
Expand Down
11 changes: 10 additions & 1 deletion go/border/rpkt/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,19 @@ func (rp *RtrPkt) parseHopExtns() error {
if currHdr != common.HopByHopClass { // Reached end2end header or L4 protocol
break
}
if *offset+2 >= len(rp.Raw) {
return common.NewBasicError(ErrExtChainTooLong, nil, "curr", *offset, "max",
len(rp.Raw))
}
currExtn := common.ExtnType{Class: currHdr, Type: rp.Raw[*offset+2]}
hdrLen := int(rp.Raw[*offset+1]) * common.LineLen
start := *offset + common.ExtnSubHdrLen
end := *offset + hdrLen
if start >= end || end > len(rp.Raw) {
return common.NewBasicError(ErrExtChainCorrupt, nil, "start", start, "end", end)
}
e, err := rp.extnParseHBH(
currExtn, *offset+common.ExtnSubHdrLen, *offset+hdrLen, len(rp.idxs.hbhExt))
currExtn, start, end, len(rp.idxs.hbhExt))
if err != nil {
return err
}
Expand Down

0 comments on commit 4f5a93b

Please sign in to comment.