Skip to content

check UDP packet length before checksumming it in valid_udp_packet()#8

Closed
maciejsszmigiero wants to merge 1 commit intoNetworkConfiguration:masterfrom
maciejsszmigiero:dhcp-udp-length-check
Closed

check UDP packet length before checksumming it in valid_udp_packet()#8
maciejsszmigiero wants to merge 1 commit intoNetworkConfiguration:masterfrom
maciejsszmigiero:dhcp-udp-length-check

Conversation

@maciejsszmigiero
Copy link
Contributor

dhcpcd sometimes crashes on Linux when it reads a truncated UDP packet,
causing valid_udp_packet() to read past the buffer when checksumming it.
This issue can be fixed by adding explicit packet length checks to this
function.

The BPF filter code loaded into the OS kernel checks the received packet
length, but it looks like reading a truncated packet from the kernel is
still possible.

…ket()

dhcpcd sometimes crashes on Linux when it reads a truncated UDP packet,
causing valid_udp_packet() to read past the buffer when checksumming it.
This issue can be fixed by adding explicit packet length checks to this
function.

The BPF filter code loaded into the OS kernel checks the received packet
length, but it looks like reading a truncated packet from the kernel is
still possible.
@rsmarples
Copy link
Member

Thanks for the excellent patch and commentary. This fixes a recently reported crash I was unable to solve and is a better fix from another submitter.

I've adjusted your patch slightly to move the length check before the don't checksum check as well because we don't want to skip it for sure! I've given you credit in commit c9fc5a5

Many thanks!

@rsmarples rsmarples closed this Sep 13, 2019
@maciejsszmigiero
Copy link
Contributor Author

Thank you for your kind words.

I see that you dropped the check for ip_hlen. Is it safe to do so?
My worry is that in the next line the code calculates a checksum of up to ip_hlen bytes
(I know it is limited to 64 bytes but still it seems otherwise unchecked).

@rsmarples
Copy link
Member

Totally my bad. I have no idea how that got lost!
Added in c8491e1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants