Skip to content

fix(connlib): use correct constant for truncating DNS responses#7551

Merged
thomaseizinger merged 7 commits intomainfrom
fix/too-large-datagram
Dec 19, 2024
Merged

fix(connlib): use correct constant for truncating DNS responses#7551
thomaseizinger merged 7 commits intomainfrom
fix/too-large-datagram

Conversation

@thomaseizinger
Copy link
Copy Markdown
Member

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.

@vercel
Copy link
Copy Markdown

vercel bot commented Dec 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
firezone ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 19, 2024 0:53am

@sentry
Copy link
Copy Markdown

sentry bot commented Dec 18, 2024

Sentry Issue: GUI-CLIENT-IPC-SERVICE-14

Copy link
Copy Markdown
Member

@jamilbk jamilbk left a comment

Choose a reason for hiding this comment

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

LGTM, just needs a typo fix I think

Comment thread rust/connlib/tunnel/src/client.rs Outdated
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};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
use ip_packet::{IpPacket, UdpSlice, MAX_UPD_PAYLOAD};
use ip_packet::{IpPacket, UdpSlice, MAX_UDP_PAYLOAD};

Comment thread rust/connlib/tunnel/src/client.rs Outdated
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 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
if message_length <= MAX_UPD_PAYLOAD {
if message_length <= MAX_UDP_PAYLOAD {

Comment thread rust/connlib/tunnel/src/client.rs Outdated

message_bytes = new_message.as_octets().to_vec();
let message_truncation = match message.answer() {
Ok(answer) if answer.pos() <= MAX_UPD_PAYLOAD => answer.pos(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Ok(answer) if answer.pos() <= MAX_UPD_PAYLOAD => answer.pos(),
Ok(answer) if answer.pos() <= MAX_UDP_PAYLOAD => answer.pos(),

Comment thread rust/ip-packet/src/lib.rs Outdated
/// 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;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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;

@thomaseizinger thomaseizinger added this pull request to the merge queue Dec 19, 2024
Merged via the queue into main with commit bc2febe Dec 19, 2024
@thomaseizinger thomaseizinger deleted the fix/too-large-datagram branch December 19, 2024 17:32
github-merge-queue bot pushed a commit that referenced this pull request Dec 22, 2024
This DNS fix is worth mentioning in the changelog.
@sentry
Copy link
Copy Markdown

sentry bot commented Jan 30, 2025

Sentry Issue: GUI-CLIENT-IPC-SERVICE-2G

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