Skip to content

Commit edec5cc

Browse files
rpigottbluca
authored andcommitted
resolved: clear the AD bit for bypass packets
When the bypass logic is invoked, such as for queries to the stub with the DO bit set, be certain to clear the AD bit in the reply before forwarding it if the answer is not known to be authentic. (cherry picked from commit 13e15da) (cherry picked from commit 3a2be65) (cherry picked from commit 6c243bb)
1 parent 0b6faf9 commit edec5cc

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/resolve/resolved-dns-packet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ static inline uint8_t* DNS_PACKET_DATA(const DnsPacket *p) {
111111
#define DNS_PACKET_AD(p) ((be16toh(DNS_PACKET_HEADER(p)->flags) >> 5) & 1)
112112
#define DNS_PACKET_CD(p) ((be16toh(DNS_PACKET_HEADER(p)->flags) >> 4) & 1)
113113

114+
#define DNS_PACKET_FLAG_AD (UINT16_C(1) << 5)
114115
#define DNS_PACKET_FLAG_TC (UINT16_C(1) << 9)
115116

116117
static inline uint16_t DNS_PACKET_RCODE(DnsPacket *p) {

src/resolve/resolved-dns-stub.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,8 @@ static int dns_stub_send_failure(
685685
static int dns_stub_patch_bypass_reply_packet(
686686
DnsPacket **ret, /* Where to place the patched packet */
687687
DnsPacket *original, /* The packet to patch */
688-
DnsPacket *request) { /* The packet the patched packet shall look like a reply to */
688+
DnsPacket *request, /* The packet the patched packet shall look like a reply to */
689+
bool authenticated) {
689690
_cleanup_(dns_packet_unrefp) DnsPacket *c = NULL;
690691
int r;
691692

@@ -725,6 +726,10 @@ static int dns_stub_patch_bypass_reply_packet(
725726
DNS_PACKET_HEADER(c)->flags = htobe16(be16toh(DNS_PACKET_HEADER(c)->flags) | DNS_PACKET_FLAG_TC);
726727
}
727728

729+
/* Ensure we don't pass along an untrusted ad flag for bypass packets */
730+
if (!authenticated)
731+
DNS_PACKET_HEADER(c)->flags = htobe16(be16toh(DNS_PACKET_HEADER(c)->flags) & ~DNS_PACKET_FLAG_AD);
732+
728733
*ret = TAKE_PTR(c);
729734
return 0;
730735
}
@@ -745,7 +750,8 @@ static void dns_stub_query_complete(DnsQuery *query) {
745750
q->answer_full_packet->protocol == DNS_PROTOCOL_DNS) {
746751
_cleanup_(dns_packet_unrefp) DnsPacket *reply = NULL;
747752

748-
r = dns_stub_patch_bypass_reply_packet(&reply, q->answer_full_packet, q->request_packet);
753+
r = dns_stub_patch_bypass_reply_packet(&reply, q->answer_full_packet, q->request_packet,
754+
FLAGS_SET(q->answer_query_flags, SD_RESOLVED_AUTHENTICATED));
749755
if (r < 0)
750756
log_debug_errno(r, "Failed to patch bypass reply packet: %m");
751757
else

0 commit comments

Comments
 (0)