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

dhcpd: fix malformed link-layer address packet #5841

Open
wants to merge 2 commits into
base: master
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
28 changes: 16 additions & 12 deletions internal/dhcpd/routeradv.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,20 @@ func hwAddrToLinkLayerAddr(hwa net.HardwareAddr) (lla []byte, err error) {
return nil, err
}

if len(hwa) == 6 || len(hwa) == 8 {
lla = make([]byte, 8)
copy(lla, hwa)

return lla, nil
switch len(hwa) {
// EUI-48 are 6 bytes, so 6 + 2 prefix bytes is divisible by 8
case 6:
lla = make([]byte, 6)

// EUI-64 are 8 bytes, so pad to 14 so that with the prefix, it's divisible by 8
case 8:
lla = make([]byte, 14)

// The last validated type by netutil.ValidateMAC is 20 byte InfiniBand link-layer address
default:
lla = make([]byte, 22)
}

// Assume that netutil.ValidateMAC prevents lengths other than 20 by
// now.
lla = make([]byte, 24)
copy(lla, hwa)

return lla, nil
}

Expand Down Expand Up @@ -92,7 +94,9 @@ func hwAddrToLinkLayerAddr(hwa net.HardwareAddr) (lla []byte, err error) {
// - Reserved[2]
// - MTU[4]
// - Option=Source link-layer address(1):
// - Link-Layer Address[8/24]
// - Type[1]
// - Length * 8bytes[1]
// - Link-Layer Address[6/14/22]
// - Option=Recursive DNS Server(25):
// - Type[1]
// - Length * 8bytes[1]
Expand Down Expand Up @@ -175,7 +179,7 @@ func createICMPv6RAPacket(params icmpv6RA) (data []byte, err error) {
// Option=Source link-layer address:

data[i] = 1 // Type
data[i+1] = 1 // Length
data[i+1] = byte((len(lla) + 2) / 8) // Length of this entire option in bytes
i += 2

copy(data[i:], lla) // Link-Layer Address[8/24]
Expand Down
7 changes: 3 additions & 4 deletions internal/dhcpd/routeradv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ func TestCreateICMPv6RAPacket(t *testing.T) {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x05, 0x01, 0x00, 0x00, 0x00, 0x00, 0x05, 0xdc,
0x01, 0x01, 0x0a, 0x00, 0x27, 0x00, 0x00, 0x00,
0x00, 0x00, 0x19, 0x03, 0x00, 0x00, 0x00, 0x00,
0x0e, 0x10, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x08, 0x00, 0x27, 0xff, 0xfe, 0x00,
0x00, 0x00,
0x19, 0x03, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x10,
0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x00, 0x27, 0xff, 0xfe, 0x00, 0x00, 0x00,
}

gotData, err := createICMPv6RAPacket(icmpv6RA{
Expand Down