fix(connlib): use correct constant for truncating DNS responses#7551
Merged
thomaseizinger merged 7 commits intomainfrom Dec 19, 2024
Merged
fix(connlib): use correct constant for truncating DNS responses#7551thomaseizinger merged 7 commits intomainfrom
thomaseizinger merged 7 commits intomainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
Sentry Issue: GUI-CLIENT-IPC-SERVICE-14 |
jamilbk
requested changes
Dec 18, 2024
Member
jamilbk
left a comment
There was a problem hiding this comment.
LGTM, just needs a typo fix I think
| use ip_network::{IpNetwork, Ipv4Network, Ipv6Network}; | ||
| use ip_network_table::IpNetworkTable; | ||
| use ip_packet::{IpPacket, UdpSlice, MAX_DATAGRAM_PAYLOAD}; | ||
| use ip_packet::{IpPacket, UdpSlice, MAX_UPD_PAYLOAD}; |
Member
There was a problem hiding this comment.
Suggested change
| use ip_packet::{IpPacket, UdpSlice, MAX_UPD_PAYLOAD}; | |
| use ip_packet::{IpPacket, UdpSlice, MAX_UDP_PAYLOAD}; |
| tracing::debug!(?message, message_length = %message_bytes.len(), "Too big DNS response, truncating"); | ||
| fn truncate_dns_response(mut message: Message<Vec<u8>>) -> Vec<u8> { | ||
| let message_length = message.as_octets().len(); | ||
| if message_length <= MAX_UPD_PAYLOAD { |
Member
There was a problem hiding this comment.
Suggested change
| if message_length <= MAX_UPD_PAYLOAD { | |
| if message_length <= MAX_UDP_PAYLOAD { |
|
|
||
| message_bytes = new_message.as_octets().to_vec(); | ||
| let message_truncation = match message.answer() { | ||
| Ok(answer) if answer.pos() <= MAX_UPD_PAYLOAD => answer.pos(), |
Member
There was a problem hiding this comment.
Suggested change
| Ok(answer) if answer.pos() <= MAX_UPD_PAYLOAD => answer.pos(), | |
| Ok(answer) if answer.pos() <= MAX_UDP_PAYLOAD => answer.pos(), |
| Message, MessageBuilder, Record, RecordData, ToName, Ttl, | ||
| }; | ||
| use ip_packet::{IpPacket, MAX_DATAGRAM_PAYLOAD}; | ||
| use ip_packet::{IpPacket, MAX_UPD_PAYLOAD}; |
Member
There was a problem hiding this comment.
Suggested change
| use ip_packet::{IpPacket, MAX_UPD_PAYLOAD}; | |
| use ip_packet::{IpPacket, MAX_UDP_PAYLOAD}; |
| let mut message_bytes = message.as_octets().to_vec(); | ||
|
|
||
| if message_bytes.len() > MAX_DATAGRAM_PAYLOAD { | ||
| if message_bytes.len() > MAX_UPD_PAYLOAD { |
Member
There was a problem hiding this comment.
Suggested change
| if message_bytes.len() > MAX_UPD_PAYLOAD { | |
| if message_bytes.len() > MAX_UDP_PAYLOAD { |
|
|
||
| let message_truncation = match message.answer() { | ||
| Ok(answer) if answer.pos() <= MAX_DATAGRAM_PAYLOAD => answer.pos(), | ||
| Ok(answer) if answer.pos() <= MAX_UPD_PAYLOAD => answer.pos(), |
Member
There was a problem hiding this comment.
Suggested change
| Ok(answer) if answer.pos() <= MAX_UPD_PAYLOAD => answer.pos(), | |
| Ok(answer) if answer.pos() <= MAX_UDP_PAYLOAD => answer.pos(), |
| /// The max length of an IPv4 header is > the fixed length of an IPv6 header. | ||
| pub const MAX_IP_PAYLOAD: usize = MAX_IP_SIZE - etherparse::Ipv4Header::MAX_LEN; | ||
| /// The maximum payload a UDP packet can have. | ||
| pub const MAX_UPD_PAYLOAD: usize = MAX_IP_PAYLOAD - etherparse::UdpHeader::LEN; |
Member
There was a problem hiding this comment.
Suggested change
| pub const MAX_UPD_PAYLOAD: usize = MAX_IP_PAYLOAD - etherparse::UdpHeader::LEN; | |
| pub const MAX_UDP_PAYLOAD: usize = MAX_IP_PAYLOAD - etherparse::UdpHeader::LEN; |
jamilbk
approved these changes
Dec 19, 2024
|
Sentry Issue: GUI-CLIENT-IPC-SERVICE-2G |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In case an upstream DNS server responds with a payload that exceeds the available buffer space of an IP packet, we need to truncate the response. Currently, this truncation uses the wrong constant to check for the maximum allowed length. Instead of the
MAX_DATAGRAM_PAYLOAD, we actually need to check against a limit that is less than the MTU as the IP layer and the UDP layer both add an overhead.To fix this, we introduce such a constant and provide additional documentation on the remaining ones to hopefully avoid future errors.