Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PropExperimenter deserialization out-of-bounds read #66

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion openflow15/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (g *GroupMod) UnmarshalBinary(data []byte) (err error) {
g.CommandBucketId = binary.BigEndian.Uint32(data[n:])
n += 4

for n < g.Header.Length {
for n < g.BucketArrayLen+24 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems unrelated to the rest of the PR?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Properties (including experimenter ones) are encoded after buckets. But because of n < g.Header.Length here we're trying to decode property as a bucket and fail.

bkt := new(Bucket)
err = bkt.UnmarshalBinary(data[n:])
if err != nil {
Expand Down
6 changes: 2 additions & 4 deletions openflow15/openflow15.go
Original file line number Diff line number Diff line change
Expand Up @@ -1509,14 +1509,12 @@ func (p *PropExperimenter) Len() uint16 {
n += 8
l := uint16(len(p.Data) * 4)
n += l
//n += uint16((8 - (l % 8)) % 8) // pad to make multiple of 8
n += uint16(8 - (l % 8)) // pad to make multiple of 8
return n
}

func (p *PropExperimenter) MarshalBinary() (data []byte, err error) {
data = make([]byte, int(p.Len()))
p.Header.Length = 8 + uint16(len(p.Data)*4)
p.Header.Length = p.Header.Len() + 8 + uint16(len(p.Data)*4)
b, err := p.Header.MarshalBinary()
if err != nil {
return
Expand Down Expand Up @@ -1547,7 +1545,7 @@ func (p *PropExperimenter) UnmarshalBinary(data []byte) (err error) {
p.ExpType = binary.BigEndian.Uint32(data[n:])
n += 4

for n < p.Header.Length+p.Header.Len() {
for n < p.Header.Length {
d := binary.BigEndian.Uint32(data[n:])
p.Data = append(p.Data, d)
n += 4
Expand Down