-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
x/net/route: ParseRIB fails with errMessageTooShort on an AF_ROUTE message from Darwin #44740
Milestone
Comments
dmitshur
added
the
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
label
Mar 2, 2021
This was referenced Aug 29, 2024
Change https://go.dev/cl/609577 mentions this issue: |
hurricanehrndz
added a commit
to hurricanehrndz/golang-net
that referenced
this issue
Sep 5, 2024
partial fix golang/go#44740 sizeofSockaddrInet is 16, but first byte of sockaddr specifies the size of the address. 16 works for most cases, except Netmasks addresses, on Darwin where only the significant bits are in the msg. Take this route message as an example ``` 88 00 05 01 00 00 00 00 41 08 00 00 07 00 00 00 92 7b 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 DST 10 02 00 00 64 71 00 00 00 00 00 00 00 00 00 00 // 100.113.0.0 GW 14 12 21 00 01 08 00 00 75 74 75 6e 34 33 31 39 00 00 00 00 // !utun4319 MASK 06 02 00 00 ff ff // 255.255.0.0 NULL 00 00 ``` i.e. ipv4 ``` 06 02 00 00 ff ff ``` The above byte sequence is for a sockaddr that is 6 bytes long representing an ipv4 for address that is 255.255.0.0. i.e. ipv6 netmask ``` 0e 1e 00 00 00 00 00 00 ff ff ff ff ff ff 00 00 ``` The above is /48 netmask that should also be parsed using b[0] of the sockaddr that contains the lenght. Confirmed by using `route monitor`. sources: https://github.com/apple/darwin-xnu/blob/main/bsd/net/route.h https://github.com/apple/darwin-xnu/blob/main/bsd/sys/socket.h#L603
hurricanehrndz
added a commit
to hurricanehrndz/golang-net
that referenced
this issue
Sep 5, 2024
sizeofSockaddrInet is 16, but first byte of sockaddr specifies actual size of sockaddr. Although, 16 works for most cases, it fails for Netmasks addresses. On Darwin only the significant bits of the netmask are in the msg. Take this route message as an example ``` // rt_msg_hdr 88 00 05 01 00 00 00 00 41 08 00 00 07 00 00 00 92 7b 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 // metrics 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 // SOCKADDRS - DST (100.113.0.0) 10 02 00 00 64 71 00 00 00 00 00 00 00 00 00 00 // GW utun4319 14 12 21 00 01 08 00 00 75 74 75 6e 34 33 31 39 00 00 00 00 // NETMASK 255.255.0.0 06 02 00 00 ff ff // NULL 00 00 ``` i.e. ipv4 ``` 06 02 00 00 ff ff ``` The above byte sequence is for a sockaddr that is 6 bytes long representing an ipv4 for address that is 255.255.0.0. i.e. ipv6 netmask ``` 0e 1e 00 00 00 00 00 00 ff ff ff ff ff ff 00 00 ``` The above is `/48` netmask that should also be parsed using `b[0]` of the sockaddr that contains the length. Confirmed by using `route monitor`. Fixes golang/go#44740 sources: https://github.com/apple/darwin-xnu/blob/main/bsd/net/route.h https://github.com/apple/darwin-xnu/blob/main/bsd/sys/socket.h#L603
dmitshur
added
NeedsFix
The path to resolution is known, but the work has not been done.
and removed
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
labels
Sep 6, 2024
This was referenced Nov 22, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have a macOS program which listens to route changes from the kernel.
It opens an AF_ROUTE socket:
Then reads messages in a loop:
It works in general, until it hit this 50 byte message from the kernel:
Adding some logging and a panic where it was returning the error:
Notably, that LinkAddr (
0x91, 0xe0, 0xf0, 0x1, 0x0, 0x0
) in the final 6 bytes of the 50 byte message.But
parseAddrs
is expecting some padding at the end? TheerrMessageTooShort
case it's hitting:Maybe this package was designed purely for getting the RIBs via sysctl (with https://pkg.go.dev/golang.org/x/net/route#FetchRIB) where they differ from the format sent over AF_ROUTE sockets? Maybe?
/cc @ianlancetaylor @mikioh @tklauser @danderson @DentonGentry
The text was updated successfully, but these errors were encountered: