From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matthias Fischer To: development@lists.ipfire.org Subject: [PATCH] dnsmasq 2.75: latest patches from upstream Date: Thu, 24 Dec 2015 10:17:16 +0100 Message-ID: <1450948636-31650-1-git-send-email-matthias.fischer@ipfire.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============3286943821881763409==" List-Id: --===============3286943821881763409== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Same procedure as... :-) Best to all for xmas and 2016! Matthias Signed-off-by: Matthias Fischer --- lfs/dnsmasq | 5 + ...EDNS0_handling_and_computation_use_of_udp.patch | 643 +++++++++++++++++++= ++ ...aks_in_handling_unknown_DNSSEC_algorithms.patch | 262 +++++++++ ...obscure_off-by-one_in_DNSSEC_hostname_cmp.patch | 27 + .../028-Minor_tweak_to_previous_commit.patch | 39 ++ .../dnsmasq/029-NSEC3_check_RFC5155_para_8_2.patch | 39 ++ 6 files changed, 1015 insertions(+) create mode 100644 src/patches/dnsmasq/025-Major_tidy_up_of_EDNS0_handling_a= nd_computation_use_of_udp.patch create mode 100644 src/patches/dnsmasq/026-More_tweaks_in_handling_unknown_D= NSSEC_algorithms.patch create mode 100644 src/patches/dnsmasq/027-Nasty_rare_and_obscure_off-by-one= _in_DNSSEC_hostname_cmp.patch create mode 100644 src/patches/dnsmasq/028-Minor_tweak_to_previous_commit.pa= tch create mode 100644 src/patches/dnsmasq/029-NSEC3_check_RFC5155_para_8_2.patch diff --git a/lfs/dnsmasq b/lfs/dnsmasq index c8fd7db..8058663 100644 --- a/lfs/dnsmasq +++ b/lfs/dnsmasq @@ -97,6 +97,11 @@ $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects)) cd $(DIR_APP) && patch -Np1 -i $(DIR_SRC)/src/patches/dnsmasq/022-Tidy_up_D= NSSEC_non-existence_code_Check_zone_status_is_NSEC_proof_bad.patch cd $(DIR_APP) && patch -Np1 -i $(DIR_SRC)/src/patches/dnsmasq/023-Fix_brace= _botch_in_dnssec_validate_ds.patch cd $(DIR_APP) && patch -Np1 -i $(DIR_SRC)/src/patches/dnsmasq/024-Do_a_bett= er_job_of_determining_which_DNSSEC_sig_algos_are_supported.patch + cd $(DIR_APP) && patch -Np1 -i $(DIR_SRC)/src/patches/dnsmasq/025-Major_tid= y_up_of_EDNS0_handling_and_computation_use_of_udp.patch + cd $(DIR_APP) && patch -Np1 -i $(DIR_SRC)/src/patches/dnsmasq/026-More_twea= ks_in_handling_unknown_DNSSEC_algorithms.patch + cd $(DIR_APP) && patch -Np1 -i $(DIR_SRC)/src/patches/dnsmasq/027-Nasty_rar= e_and_obscure_off-by-one_in_DNSSEC_hostname_cmp.patch + cd $(DIR_APP) && patch -Np1 -i $(DIR_SRC)/src/patches/dnsmasq/028-Minor_twe= ak_to_previous_commit.patch + cd $(DIR_APP) && patch -Np1 -i $(DIR_SRC)/src/patches/dnsmasq/029-NSEC3_che= ck_RFC5155_para_8_2.patch cd $(DIR_APP) && patch -Np1 -i $(DIR_SRC)/src/patches/dnsmasq-Add-support-t= o-read-ISC-DHCP-lease-file.patch =20 cd $(DIR_APP) && sed -i src/config.h \ diff --git a/src/patches/dnsmasq/025-Major_tidy_up_of_EDNS0_handling_and_comp= utation_use_of_udp.patch b/src/patches/dnsmasq/025-Major_tidy_up_of_EDNS0_han= dling_and_computation_use_of_udp.patch new file mode 100644 index 0000000..c016e73 --- /dev/null +++ b/src/patches/dnsmasq/025-Major_tidy_up_of_EDNS0_handling_and_computation= _use_of_udp.patch @@ -0,0 +1,643 @@ +From fa14bec83b2db010fd076910fddab56957b9375d Mon Sep 17 00:00:00 2001 +From: Simon Kelley +Date: Sun, 20 Dec 2015 17:12:16 +0000 +Subject: [PATCH] Major tidy up of EDNS0 handling and computation/use of udp + packet size. + +--- + src/auth.c | 8 ++- + src/dnsmasq.h | 7 ++- + src/dnssec.c | 1 - + src/forward.c | 184 ++++++++++++++++++++++++++++++++++++++++-------------= --- + src/netlink.c | 3 +- + src/rfc1035.c | 81 +++++++------------------ + src/rrfilter.c | 2 +- + 7 files changed, 168 insertions(+), 118 deletions(-) + +diff --git a/src/auth.c b/src/auth.c +index 2b0b7d6..85bd5e7 100644 +--- a/src/auth.c ++++ b/src/auth.c +@@ -81,7 +81,8 @@ int in_zone(struct auth_zone *zone, char *name, char **cut) + } +=20 +=20 +-size_t answer_auth(struct dns_header *header, char *limit, size_t qlen, tim= e_t now, union mysockaddr *peer_addr, int local_query)=20 ++size_t answer_auth(struct dns_header *header, char *limit, size_t qlen, tim= e_t now, union mysockaddr *peer_addr,=20 ++ int local_query, int do_bit, int have_pseudoheader)=20 + { + char *name =3D daemon->namebuff; + unsigned char *p, *ansp; +@@ -820,6 +821,11 @@ size_t answer_auth(struct dns_header *header, char *lim= it, size_t qlen, time_t n + header->ancount =3D htons(anscount); + header->nscount =3D htons(authcount); + header->arcount =3D htons(0); ++ ++ /* Advertise our packet size limit in our reply */ ++ if (have_pseudoheader) ++ return add_pseudoheader(header, ansp - (unsigned char *)header, (unsig= ned char *)limit, daemon->edns_pktsz, 0, NULL, 0, do_bit); ++ + return ansp - (unsigned char *)header; + } + =20 +diff --git a/src/dnsmasq.h b/src/dnsmasq.h +index 39a930c..abb34c5 100644 +--- a/src/dnsmasq.h ++++ b/src/dnsmasq.h +@@ -1113,7 +1113,7 @@ int extract_addresses(struct dns_header *header, size_= t qlen, char *namebuff, + int no_cache, int secure, int *doctored); + size_t answer_request(struct dns_header *header, char *limit, size_t qlen, = =20 + struct in_addr local_addr, struct in_addr local_netmask,=20 +- time_t now, int *ad_reqd, int *do_bit); ++ time_t now, int ad_reqd, int do_bit, int have_pseudoheader); + int check_for_bogus_wildcard(struct dns_header *header, size_t qlen, char *= name,=20 + struct bogus_addr *addr, time_t now); + int check_for_ignored_address(struct dns_header *header, size_t qlen, struc= t bogus_addr *baddr); +@@ -1123,6 +1123,8 @@ int check_for_local_domain(char *name, time_t now); + unsigned int questions_crc(struct dns_header *header, size_t plen, char *bu= ff); + size_t resize_packet(struct dns_header *header, size_t plen,=20 + unsigned char *pheader, size_t hlen); ++size_t add_pseudoheader(struct dns_header *header, size_t plen, unsigned ch= ar *limit,=20 ++ unsigned short udp_sz, int optno, unsigned char *opt, size_t optlen, int= set_do); + size_t add_mac(struct dns_header *header, size_t plen, char *limit, union m= ysockaddr *l3); + size_t add_source_addr(struct dns_header *header, size_t plen, char *limit,= union mysockaddr *source); + #ifdef HAVE_DNSSEC +@@ -1141,7 +1143,8 @@ int private_net(struct in_addr addr, int ban_localhost= ); + /* auth.c */ + #ifdef HAVE_AUTH + size_t answer_auth(struct dns_header *header, char *limit, size_t qlen,=20 +- time_t now, union mysockaddr *peer_addr, int local_query); ++ time_t now, union mysockaddr *peer_addr, int local_query, ++ int do_bit, int have_pseudoheader); + int in_zone(struct auth_zone *zone, char *name, char **cut); + #endif +=20 +diff --git a/src/dnssec.c b/src/dnssec.c +index 82394ee..299ca64 100644 +--- a/src/dnssec.c ++++ b/src/dnssec.c +@@ -67,7 +67,6 @@ static char *algo_digest_name(int algo) + case 12: return "gosthash94"; + case 13: return "sha256"; + case 14: return "sha384"; +- + default: return NULL; + } + } +diff --git a/src/forward.c b/src/forward.c +index 3e801c8..041353c 100644 +--- a/src/forward.c ++++ b/src/forward.c +@@ -244,7 +244,6 @@ static int forward_query(int udpfd, union mysockaddr *ud= paddr, + void *hash =3D &crc; + #endif + unsigned int gotname =3D extract_request(header, plen, daemon->namebuff, N= ULL); +- unsigned char *pheader; +=20 + (void)do_bit; +=20 +@@ -264,7 +263,8 @@ static int forward_query(int udpfd, union mysockaddr *ud= paddr, + there's no point retrying the query, retry the key query instead...... */ + if (forward->blocking_query) + { +- int fd; ++ int fd, is_sign; ++ unsigned char *pheader; + =20 + forward->flags &=3D ~FREC_TEST_PKTSZ; + =20 +@@ -276,8 +276,8 @@ static int forward_query(int udpfd, union mysockaddr *ud= paddr, + blockdata_retrieve(forward->stash, forward->stash_len, (void *)header); + plen =3D forward->stash_len; + =20 +- if (find_pseudoheader(header, plen, NULL, &pheader, NULL)) +- PUTSHORT((forward->flags & FREC_TEST_PKTSZ) ? SAFE_PKTSZ : forward->se= ntto->edns_pktsz, pheader); ++ if (find_pseudoheader(header, plen, NULL, &pheader, &is_sign) && !is_sig= n) ++ PUTSHORT(SAFE_PKTSZ, pheader); +=20 + if (forward->sentto->addr.sa.sa_family =3D=3D AF_INET)=20 + log_query(F_NOEXTRA | F_DNSSEC | F_IPV4, "retry", (struct all_addr *)&= forward->sentto->addr.in.sin_addr, "dnssec"); +@@ -394,32 +394,40 @@ static int forward_query(int udpfd, union mysockaddr *= udpaddr, + forward->log_id =3D daemon->log_id; + =20 + if (option_bool(OPT_ADD_MAC)) +- plen =3D add_mac(header, plen, ((char *) header) + daemon->packet_buff_sz,= &forward->source); +- =20 ++ { ++ size_t new =3D add_mac(header, plen, ((char *) header) + daemon->packet_= buff_sz, &forward->source); ++ if (new !=3D plen) ++ { ++ plen =3D new; ++ forward->flags |=3D FREC_ADDED_PHEADER; ++ } ++ } ++ + if (option_bool(OPT_CLIENT_SUBNET)) + { + size_t new =3D add_source_addr(header, plen, ((char *) header) + daemon-= >packet_buff_sz, &forward->source);=20 + if (new !=3D plen) + { + plen =3D new; +- forward->flags |=3D FREC_HAS_SUBNET; ++ forward->flags |=3D FREC_HAS_SUBNET | FREC_ADDED_PHEADER; + } + } +=20 + #ifdef HAVE_DNSSEC + if (option_bool(OPT_DNSSEC_VALID)) + { +- size_t new_plen =3D add_do_bit(header, plen, ((char *) header) + daemon-= >packet_buff_sz); ++ size_t new =3D add_do_bit(header, plen, ((char *) header) + daemon->pack= et_buff_sz); + =20 ++ if (new !=3D plen) ++ forward->flags |=3D FREC_ADDED_PHEADER; ++ ++ plen =3D new; ++ =20 + /* For debugging, set Checking Disabled, otherwise, have the upstream ch= eck too, + this allows it to select auth servers when one is returning bad data.= */ + if (option_bool(OPT_DNSSEC_DEBUG)) + header->hb4 |=3D HB4_CD; +=20 +- if (new_plen !=3D plen) +- forward->flags |=3D FREC_ADDED_PHEADER; +- +- plen =3D new_plen; + } + #endif + =20 +@@ -469,10 +477,23 @@ static int forward_query(int udpfd, union mysockaddr *= udpaddr, + } + #endif + } +- +- if (find_pseudoheader(header, plen, NULL, &pheader, NULL)) +- PUTSHORT((forward->flags & FREC_TEST_PKTSZ) ? SAFE_PKTSZ : start->edns_pk= tsz, pheader); + =20 ++#ifdef HAVE_DNSSEC ++ if (option_bool(OPT_DNSSEC_VALID) && !do_bit) ++ { ++ /* Difficult one here. If our client didn't send EDNS0, we will have se= t the UDP ++ packet size to 512. But that won't provide space for the RRSIGS in m= any cases. ++ The RRSIGS will be stripped out before the answer goes back, so the = packet should ++ shrink again. So, if we added a do-bit, bump the udp packet size to = the value ++ known to be OK for this server. Maybe check returned size after stri= pping and set ++ the truncated bit? */ =20 ++ unsigned char *pheader; ++ int is_sign; ++ if (find_pseudoheader(header, plen, NULL, &pheader, &is_sign)) ++ PUTSHORT(start->edns_pktsz, pheader); ++ } ++#endif ++ + if (retry_send(sendto(fd, (char *)header, plen, 0, + &start->addr.sa, + sa_len(&start->addr)))) +@@ -563,30 +584,34 @@ static size_t process_reply(struct dns_header *header,= time_t now, struct server + } + #endif + =20 +- /* If upstream is advertising a larger UDP packet size +- than we allow, trim it so that we don't get overlarge +- requests for the client. We can't do this for signed packets. */ +- + if ((pheader =3D find_pseudoheader(header, n, &plen, &sizep, &is_sign))) + { +- unsigned short udpsz; +- unsigned char *psave =3D sizep; +- =20 +- GETSHORT(udpsz, sizep); +- +- if (!is_sign && udpsz > daemon->edns_pktsz) +- PUTSHORT(daemon->edns_pktsz, psave); +- =20 + if (check_subnet && !check_source(header, plen, pheader, query_source= )) + { + my_syslog(LOG_WARNING, _("discarding DNS reply: subnet option mismatch")= ); + return 0; + } + =20 +- if (added_pheader) ++ if (!is_sign) + { +- pheader =3D 0;=20 +- header->arcount =3D htons(0); ++ if (added_pheader) ++ { ++ /* client didn't send EDNS0, we added one, strip it off before retur= ning answer. */ ++ n =3D rrfilter(header, n, 0); ++ pheader =3D NULL; ++ } ++ else ++ { ++ /* If upstream is advertising a larger UDP packet size ++ than we allow, trim it so that we don't get overlarge ++ requests for the client. We can't do this for signed packets. */ ++ unsigned short udpsz; ++ unsigned char *psave =3D sizep; ++ =20 ++ GETSHORT(udpsz, sizep); ++ if (udpsz > daemon->edns_pktsz) ++ PUTSHORT(daemon->edns_pktsz, psave); ++ } + } + } + =20 +@@ -655,14 +680,16 @@ static size_t process_reply(struct dns_header *header,= time_t now, struct server + } +=20 + if (option_bool(OPT_DNSSEC_VALID)) +- header->hb4 &=3D ~HB4_AD; +- =20 +- if (!(header->hb4 & HB4_CD) && ad_reqd && cache_secure) +- header->hb4 |=3D HB4_AD; +- +- /* If the requestor didn't set the DO bit, don't return DNSSEC info. */ +- if (!do_bit) +- n =3D rrfilter(header, n, 1); ++ { ++ header->hb4 &=3D ~HB4_AD; ++ =20 ++ if (!(header->hb4 & HB4_CD) && ad_reqd && cache_secure) ++ header->hb4 |=3D HB4_AD; ++ =20 ++ /* If the requestor didn't set the DO bit, don't return DNSSEC info. = */ ++ if (!do_bit) ++ n =3D rrfilter(header, n, 1); ++ } + #endif +=20 + /* do this after extract_addresses. Ensure NODATA reply and remove +@@ -761,8 +788,14 @@ void reply_query(int fd, int family, time_t now) + if ((nn =3D resize_packet(header, (size_t)n, pheader, plen))) + { + header->hb3 &=3D ~(HB3_QR | HB3_AA | HB3_TC); +- header->hb4 &=3D ~(HB4_RA | HB4_RCODE); +- forward_query(-1, NULL, NULL, 0, header, nn, now, forward, 0, 0); ++ header->hb4 &=3D ~(HB4_RA | HB4_RCODE | HB4_CD | HB4_AD); ++ if (forward->flags |=3D FREC_CHECKING_DISABLED) ++ header->hb4 |=3D HB4_CD; ++ if (forward->flags |=3D FREC_AD_QUESTION) ++ header->hb4 |=3D HB4_AD; ++ if (forward->flags & FREC_DO_QUESTION) ++ add_do_bit(header, nn, (char *)pheader + plen); ++ forward_query(-1, NULL, NULL, 0, header, nn, now, forward, forward->= flags & FREC_AD_QUESTION, forward->flags & FREC_DO_QUESTION); + return; + } + } +@@ -1007,12 +1040,13 @@ void receive_query(struct listener *listen, time_t n= ow) + { + struct dns_header *header =3D (struct dns_header *)daemon->packet; + union mysockaddr source_addr; +- unsigned short type; ++ unsigned char *pheader; ++ unsigned short type, udp_size =3D PACKETSZ; /* default if no EDNS0 */ + struct all_addr dst_addr; + struct in_addr netmask, dst_addr_4; + size_t m; + ssize_t n; +- int if_index =3D 0, auth_dns =3D 0; ++ int if_index =3D 0, auth_dns =3D 0, do_bit =3D 0, have_pseudoheader =3D 0; + #ifdef HAVE_AUTH + int local_auth =3D 0; + #endif +@@ -1279,10 +1313,30 @@ void receive_query(struct listener *listen, time_t n= ow) + #endif + } + =20 ++ if (find_pseudoheader(header, (size_t)n, NULL, &pheader, NULL)) ++ {=20 ++ unsigned short flags; ++ =20 ++ have_pseudoheader =3D 1; ++ GETSHORT(udp_size, pheader); ++ pheader +=3D 2; /* ext_rcode */ ++ GETSHORT(flags, pheader); ++ =20 ++ if (flags & 0x8000) ++ do_bit =3D 1;/* do bit */=20 ++=09 ++ /* If the client provides an EDNS0 UDP size, use that to limit our re= ply. ++ (bounded by the maximum configured). If no EDNS0, then it ++ defaults to 512 */ ++ if (udp_size > daemon->edns_pktsz) ++ udp_size =3D daemon->edns_pktsz; ++ } ++ + #ifdef HAVE_AUTH + if (auth_dns) + { +- m =3D answer_auth(header, ((char *) header) + daemon->packet_buff_sz,= (size_t)n, now, &source_addr, local_auth); ++ m =3D answer_auth(header, ((char *) header) + udp_size, (size_t)n, no= w, &source_addr,=20 ++ local_auth, do_bit, have_pseudoheader); + if (m >=3D 1) + { + send_from(listen->fd, option_bool(OPT_NOWILD) || option_bool(OPT_CLEVERB= IND), +@@ -1293,9 +1347,13 @@ void receive_query(struct listener *listen, time_t no= w) + else + #endif + { +- int ad_reqd, do_bit; +- m =3D answer_request(header, ((char *) header) + daemon->packet_buff_= sz, (size_t)n,=20 +- dst_addr_4, netmask, now, &ad_reqd, &do_bit); ++ int ad_reqd =3D do_bit; ++ /* RFC 6840 5.7 */ ++ if (header->hb4 & HB4_AD) ++ ad_reqd =3D 1; ++ ++ m =3D answer_request(header, ((char *) header) + udp_size, (size_t)n,= =20 ++ dst_addr_4, netmask, now, ad_reqd, do_bit, have_pseudoheader); + =20 + if (m >=3D 1) + { +@@ -1397,7 +1455,7 @@ unsigned char *tcp_request(int confd, time_t now, + #ifdef HAVE_AUTH + int local_auth =3D 0; + #endif +- int checking_disabled, ad_question, do_bit, added_pheader =3D 0; ++ int checking_disabled, do_bit, added_pheader =3D 0, have_pseudoheader =3D= 0; + int check_subnet, no_cache_dnssec =3D 0, cache_secure =3D 0, bogusanswer = =3D 0; + size_t m; + unsigned short qtype; +@@ -1414,6 +1472,7 @@ unsigned char *tcp_request(int confd, time_t now, + union mysockaddr peer_addr; + socklen_t peer_len =3D sizeof(union mysockaddr); + int query_count =3D 0; ++ unsigned char *pheader; +=20 + if (getpeername(confd, (struct sockaddr *)&peer_addr, &peer_len) =3D=3D -= 1) + return packet; +@@ -1508,15 +1567,35 @@ unsigned char *tcp_request(int confd, time_t now, + else + dst_addr_4.s_addr =3D 0; + =20 ++ do_bit =3D 0; ++ ++ if (find_pseudoheader(header, (size_t)size, NULL, &pheader, NULL)) ++ {=20 ++ unsigned short flags; ++ =20 ++ have_pseudoheader =3D 1; ++ pheader +=3D 4; /* udp_size, ext_rcode */ ++ GETSHORT(flags, pheader); ++ =20 ++ if (flags & 0x8000) ++ do_bit =3D 1;/* do bit */=20 ++ } ++ + #ifdef HAVE_AUTH + if (auth_dns) +- m =3D answer_auth(header, ((char *) header) + 65536, (size_t)size, now, &p= eer_addr, local_auth); ++ m =3D answer_auth(header, ((char *) header) + 65536, (size_t)size, now, &p= eer_addr,=20 ++ local_auth, do_bit, have_pseudoheader); + else + #endif + { +- /* m > 0 if answered from cache */ +- m =3D answer_request(header, ((char *) header) + 65536, (size_t)size,=20 +- dst_addr_4, netmask, now, &ad_question, &do_bit); ++ int ad_reqd =3D do_bit; ++ /* RFC 6840 5.7 */ ++ if (header->hb4 & HB4_AD) ++ ad_reqd =3D 1; ++ =20 ++ /* m > 0 if answered from cache */ ++ m =3D answer_request(header, ((char *) header) + 65536, (size_t)size,=20 ++ dst_addr_4, netmask, now, ad_reqd, do_bit, have_pseudoheader); + =20 + /* Do this by steam now we're not in the select() loop */ + check_log_writer(1);=20 +@@ -1615,6 +1694,7 @@ unsigned char *tcp_request(int confd, time_t now, + } + =20 + #ifdef HAVE_DNSSEC ++ added_pheader =3D 0; =20 + if (option_bool(OPT_DNSSEC_VALID)) + { + size_t new_size =3D add_do_bit(header, size, ((char *) header) + 6= 5536); +@@ -1719,7 +1799,7 @@ unsigned char *tcp_request(int confd, time_t now, +=20 + m =3D process_reply(header, now, last_server, (unsigned int)m,=20 + option_bool(OPT_NO_REBIND) && !norebind, no_cache_dnssec, cache_secure= , bogusanswer, +- ad_question, do_bit, added_pheader, check_subnet, &peer_addr);=20 ++ ad_reqd, do_bit, added_pheader, check_subnet, &peer_addr);=20 + =20 + break; + } +diff --git a/src/netlink.c b/src/netlink.c +index 753784d..3376d68 100644 +--- a/src/netlink.c ++++ b/src/netlink.c +@@ -288,7 +288,8 @@ int iface_enumerate(int family, void *parm, int (*callba= ck)()) + rta =3D RTA_NEXT(rta, len1); + } +=20 +- if (inaddr && mac && callback_ok) ++ if (!(neigh->ndm_state & (NUD_NOARP | NUD_INCOMPLETE | NUD_FAILED)) && ++ inaddr && mac && callback_ok) + if (!((*callback)(neigh->ndm_family, inaddr, mac, maclen, parm))) + callback_ok =3D 0; + } +diff --git a/src/rfc1035.c b/src/rfc1035.c +index 188d05f..18858a8 100644 +--- a/src/rfc1035.c ++++ b/src/rfc1035.c +@@ -489,8 +489,8 @@ struct macparm { + union mysockaddr *l3; + }; + =20 +-static size_t add_pseudoheader(struct dns_header *header, size_t plen, unsi= gned char *limit,=20 +- int optno, unsigned char *opt, size_t optlen, int set_do) ++size_t add_pseudoheader(struct dns_header *header, size_t plen, unsigned ch= ar *limit,=20 ++ unsigned short udp_sz, int optno, unsigned char *opt, size_t optlen, int= set_do) + {=20 + unsigned char *lenp, *datap, *p; + int rdlen, is_sign; +@@ -508,7 +508,7 @@ static size_t add_pseudoheader(struct dns_header *header= , size_t plen, unsigned + return plen; + *p++ =3D 0; /* empty name */ + PUTSHORT(T_OPT, p); +- PUTSHORT(SAFE_PKTSZ, p); /* max packet length, this will be overwritt= en */ ++ PUTSHORT(udp_sz, p); /* max packet length, 512 if not given in EDNS0 = header */ + PUTSHORT(0, p); /* extended RCODE and version */ + PUTSHORT(set_do ? 0x8000 : 0, p); /* DO flag */ + lenp =3D p; +@@ -594,7 +594,7 @@ static int filter_mac(int family, char *addrp, char *mac= , size_t maclen, void *p + if (!match) + return 1; /* continue */ +=20 +- parm->plen =3D add_pseudoheader(parm->header, parm->plen, parm->limit, E= DNS0_OPTION_MAC, (unsigned char *)mac, maclen, 0); ++ parm->plen =3D add_pseudoheader(parm->header, parm->plen, parm->limit, PA= CKETSZ, EDNS0_OPTION_MAC, (unsigned char *)mac, maclen, 0); + =20 + return 0; /* done */ + } =20 +@@ -603,12 +603,6 @@ size_t add_mac(struct dns_header *header, size_t plen, = char *limit, union mysock + { + struct macparm parm; + =20 +-/* Must have an existing pseudoheader as the only ar-record,=20 +- or have no ar-records. Must also not be signed */ +- =20 +- if (ntohs(header->arcount) > 1) +- return plen; +- + parm.header =3D header; + parm.limit =3D (unsigned char *)limit; + parm.plen =3D plen; +@@ -699,13 +693,13 @@ size_t add_source_addr(struct dns_header *header, size= _t plen, char *limit, unio + struct subnet_opt opt; + =20 + len =3D calc_subnet_opt(&opt, source); +- return add_pseudoheader(header, plen, (unsigned char *)limit, EDNS0_OPTIO= N_CLIENT_SUBNET, (unsigned char *)&opt, len, 0); ++ return add_pseudoheader(header, plen, (unsigned char *)limit, PACKETSZ, E= DNS0_OPTION_CLIENT_SUBNET, (unsigned char *)&opt, len, 0); + } +=20 + #ifdef HAVE_DNSSEC + size_t add_do_bit(struct dns_header *header, size_t plen, char *limit) + { +- return add_pseudoheader(header, plen, (unsigned char *)limit, 0, NULL, 0,= 1); ++ return add_pseudoheader(header, plen, (unsigned char *)limit, PACKETSZ, 0= , NULL, 0, 1); + } + #endif +=20 +@@ -1525,16 +1519,16 @@ static unsigned long crec_ttl(struct crec *crecp, ti= me_t now) + /* return zero if we can't answer from cache, or packet size if we can */ + size_t answer_request(struct dns_header *header, char *limit, size_t qlen, = =20 + struct in_addr local_addr, struct in_addr local_netmask,=20 +- time_t now, int *ad_reqd, int *do_bit)=20 ++ time_t now, int ad_reqd, int do_bit, int have_pseudoheader)=20 + { + char *name =3D daemon->namebuff; +- unsigned char *p, *ansp, *pheader; ++ unsigned char *p, *ansp; + unsigned int qtype, qclass; + struct all_addr addr; + int nameoffset; + unsigned short flag; + int q, ans, anscount =3D 0, addncount =3D 0; +- int dryrun =3D 0, sec_reqd =3D 0, have_pseudoheader =3D 0; ++ int dryrun =3D 0; + struct crec *crecp; + int nxdomain =3D 0, auth =3D 1, trunc =3D 0, sec_data =3D 1; + struct mx_srv_record *rec; +@@ -1550,35 +1544,11 @@ size_t answer_request(struct dns_header *header, cha= r *limit, size_t qlen, + if (header->hb4 & HB4_CD) + sec_data =3D 0; + =20 +- /* RFC 6840 5.7 */ +- *ad_reqd =3D header->hb4 & HB4_AD; +- *do_bit =3D 0; +- + /* If there is an additional data section then it will be overwritten by + partial replies, so we have to do a dry run to see if we can answer + the query. */ +- + if (ntohs(header->arcount) !=3D 0) +- { +- dryrun =3D 1; +- +- /* If there's an additional section, there might be an EDNS(0) pseudo= header */ +- if (find_pseudoheader(header, qlen, NULL, &pheader, NULL)) +- {=20 +- unsigned short flags; +- =20 +- have_pseudoheader =3D 1; +- =20 +- pheader +=3D 4; /* udp size, ext_rcode */ +- GETSHORT(flags, pheader); +- =20 +- if ((sec_reqd =3D flags & 0x8000)) +- { +- *do_bit =3D 1;/* do bit */=20 +- *ad_reqd =3D 1; +- } +- } +- } ++ dryrun =3D 1; +=20 + for (rec =3D daemon->mxnames; rec; rec =3D rec->next) + rec->offset =3D 0; +@@ -1603,11 +1573,6 @@ size_t answer_request(struct dns_header *header, char= *limit, size_t qlen, + GETSHORT(qtype, p);=20 + GETSHORT(qclass, p); +=20 +- /* Don't filter RRSIGS from answers to ANY queries, even if do-bit +- not set. */ +- if (qtype =3D=3D T_ANY) +- *do_bit =3D 1; +- + ans =3D 0; /* have we answered this question */ + =20 + if (qtype =3D=3D T_TXT || qtype =3D=3D T_ANY) +@@ -1739,7 +1704,7 @@ size_t answer_request(struct dns_header *header, char = *limit, size_t qlen, + the zone is unsigned, which implies that we're doing + validation. */ + if ((crecp->flags & (F_HOSTS | F_DHCP | F_CONFIG)) ||=20 +- !sec_reqd ||=20 ++ !do_bit ||=20 + (option_bool(OPT_DNSSEC_VALID) && !(crecp->flags & F_DNSSECOK))) + { + do=20 +@@ -1927,7 +1892,7 @@ size_t answer_request(struct dns_header *header, char = *limit, size_t qlen, + } +=20 + /* If the client asked for DNSSEC don't use cached data. */ +- if ((crecp->flags & (F_HOSTS | F_DHCP | F_CONFIG)) || !sec_reqd || !(cr= ecp->flags & F_DNSSECOK)) ++ if ((crecp->flags & (F_HOSTS | F_DHCP | F_CONFIG)) || !do_bit || !(crec= p->flags & F_DNSSECOK)) + do + {=20 + /* don't answer wildcard queries with data not from /etc/hosts +@@ -1961,17 +1926,12 @@ size_t answer_request(struct dns_header *header, cha= r *limit, size_t qlen, + =09 + if (crecp->flags & F_NEG) + { +- /* We don't cache NSEC records, so if a DNSSEC-validated negative an= swer +- is cached and the client wants DNSSEC, forward rather than answer= ing from the cache */ +- if (!sec_reqd || !(crecp->flags & F_DNSSECOK)) +- { +- ans =3D 1; +- auth =3D 0; +- if (crecp->flags & F_NXDOMAIN) +- nxdomain =3D 1; +- if (!dryrun) +- log_query(crecp->flags, name, NULL, NULL); +- } ++ ans =3D 1; ++ auth =3D 0; ++ if (crecp->flags & F_NXDOMAIN) ++ nxdomain =3D 1; ++ if (!dryrun) ++ log_query(crecp->flags, name, NULL, NULL); + } + else=20 + { +@@ -2209,10 +2169,11 @@ size_t answer_request(struct dns_header *header, cha= r *limit, size_t qlen, +=20 + len =3D ansp - (unsigned char *)header; + =20 ++ /* Advertise our packet size limit in our reply */ + if (have_pseudoheader) +- len =3D add_pseudoheader(header, len, (unsigned char *)limit, 0, NULL, = 0, sec_reqd); ++ len =3D add_pseudoheader(header, len, (unsigned char *)limit, daemon->e= dns_pktsz, 0, NULL, 0, do_bit); + =20 +- if (*ad_reqd && sec_data) ++ if (ad_reqd && sec_data) + header->hb4 |=3D HB4_AD; + else + header->hb4 &=3D ~HB4_AD; +diff --git a/src/rrfilter.c b/src/rrfilter.c +index ae12261..b26b39f 100644 +--- a/src/rrfilter.c ++++ b/src/rrfilter.c +@@ -243,7 +243,7 @@ size_t rrfilter(struct dns_header *header, size_t plen, = int mode) + for (p =3D rrs[0], i =3D 1; i < rr_found; i +=3D 2) + { + unsigned char *start =3D rrs[i]; +- unsigned char *end =3D (i !=3D rr_found - 1) ? rrs[i+1] : ((unsigned = char *)(header+1)) + plen; ++ unsigned char *end =3D (i !=3D rr_found - 1) ? rrs[i+1] : ((unsigned = char *)header) + plen; + =20 + memmove(p, start, end-start); + p +=3D end-start; +--=20 +1.7.10.4 + diff --git a/src/patches/dnsmasq/026-More_tweaks_in_handling_unknown_DNSSEC_a= lgorithms.patch b/src/patches/dnsmasq/026-More_tweaks_in_handling_unknown_DNS= SEC_algorithms.patch new file mode 100644 index 0000000..910921b --- /dev/null +++ b/src/patches/dnsmasq/026-More_tweaks_in_handling_unknown_DNSSEC_algorith= ms.patch @@ -0,0 +1,262 @@ +From d67ecac59d58f249707d26e38d49c29b552af4d8 Mon Sep 17 00:00:00 2001 +From: Simon Kelley +Date: Sun, 20 Dec 2015 20:44:23 +0000 +Subject: [PATCH] More tweaks in handling unknown DNSSEC algorithms. + +--- + src/dnssec.c | 128 +++++++++++++++++++++++++++++--------------------------= --- + 1 file changed, 63 insertions(+), 65 deletions(-) + +diff --git a/src/dnssec.c b/src/dnssec.c +index 299ca64..e09f304 100644 +--- a/src/dnssec.c ++++ b/src/dnssec.c +@@ -70,7 +70,17 @@ static char *algo_digest_name(int algo) + default: return NULL; + } + } +- =20 ++ =20 ++/* http://www.iana.org/assignments/dnssec-nsec3-parameters/dnssec-nsec3-par= ameters.xhtml */ ++static char *nsec3_digest_name(int digest) ++{ ++ switch (digest) ++ { ++ case 1: return "sha1"; ++ default: return NULL; ++ } ++} ++=20 + /* Find pointer to correct hash function in nettle library */ + static const struct nettle_hash *hash_find(char *name) + { +@@ -667,7 +677,6 @@ static int explore_rrset(struct dns_header *header, size= _t plen, int class, int + static int rrset_sz =3D 0, sig_sz =3D 0;=20 + unsigned char *p; + int rrsetidx, sigidx, j, rdlen, res; +- int name_labels =3D count_labels(name); /* For 4035 5.3.2 check */ + int gotkey =3D 0; +=20 + if (!(p =3D skip_questions(header, plen))) +@@ -678,7 +687,7 @@ static int explore_rrset(struct dns_header *header, size= _t plen, int class, int + j !=3D 0; j--)=20 + { + unsigned char *pstart, *pdata; +- int stype, sclass, algo, type_covered, labels, sig_expiration, sig_in= ception; ++ int stype, sclass, type_covered; +=20 + pstart =3D p; + =20 +@@ -712,12 +721,7 @@ static int explore_rrset(struct dns_header *header, siz= e_t plen, int class, int + return 0; /* bad packet */=20 + =20 + GETSHORT(type_covered, p); +- algo =3D *p++; +- labels =3D *p++; +- p +=3D 4; /* orig_ttl */ +- GETLONG(sig_expiration, p); +- GETLONG(sig_inception, p); +- p +=3D 2; /* key_tag */ ++ p +=3D 16; /* algo, labels, orig_ttl, sig_expiration, sig_inception,= key_tag */ + =20 + if (gotkey) + { +@@ -749,11 +753,8 @@ static int explore_rrset(struct dns_header *header, siz= e_t plen, int class, int + } + } + =20 +- /* Don't count signatures for algos we don't support */ +- if (check_date_range(sig_inception, sig_expiration) && +- labels <=3D name_labels && +- type_covered =3D=3D type &&=20 +- verify_func(algo)) ++ =20 ++ if (type_covered =3D=3D type) + { + if (!expand_workspace(&sigs, &sig_sz, sigidx)) + return 0;=20 +@@ -795,7 +796,7 @@ static int validate_rrset(time_t now, struct dns_header = *header, size_t plen, in + char *name, char *keyname, char **wildcard_out, struct blockdata *key,= int keylen, int algo_in, int keytag_in) + { + unsigned char *p; +- int rdlen, j, name_labels; ++ int rdlen, j, name_labels, sig_expiration, sig_inception; + struct crec *crecp =3D NULL; + int algo, labels, orig_ttl, key_tag; + u16 *rr_desc =3D rrfilter_desc(type); +@@ -828,13 +829,16 @@ static int validate_rrset(time_t now, struct dns_heade= r *header, size_t plen, in + algo =3D *p++; + labels =3D *p++; + GETLONG(orig_ttl, p); +- p +=3D 8; /* sig_expiration, sig_inception already checked */ ++ GETLONG(sig_expiration, p); ++ GETLONG(sig_inception, p); + GETSHORT(key_tag, p); + =20 + if (!extract_name(header, plen, &p, keyname, 1, 0)) + return STAT_BOGUS; +=20 +- if (!(hash =3D hash_find(algo_digest_name(algo))) || ++ if (!check_date_range(sig_inception, sig_expiration) || ++ labels > name_labels || ++ !(hash =3D hash_find(algo_digest_name(algo))) || + !hash_init(hash, &ctx, &digest)) + continue; + =20 +@@ -1112,7 +1116,10 @@ int dnssec_validate_by_ds(time_t now, struct dns_head= er *header, size_t plen, ch + else + { + a.addr.keytag =3D keytag; +- log_query(F_NOEXTRA | F_KEYTAG | F_UPSTREAM, name, &a, "DNSKEY keytag = %u"); ++ if (verify_func(algo)) ++ log_query(F_NOEXTRA | F_KEYTAG | F_UPSTREAM, name, &a, "DNSKEY keyta= g %u"); ++ else ++ log_query(F_NOEXTRA | F_KEYTAG | F_UPSTREAM, name, &a, "DNSKEY keyta= g %u (not supported)"); + =20 + recp1->addr.key.keylen =3D rdlen - 4; + recp1->addr.key.keydata =3D key; +@@ -1235,7 +1242,11 @@ int dnssec_validate_ds(time_t now, struct dns_header = *header, size_t plen, char + else + { + a.addr.keytag =3D keytag; +- log_query(F_NOEXTRA | F_KEYTAG | F_UPSTREAM, name, &a, "DS keytag %= u"); ++ if (hash_find(ds_digest_name(digest)) && verify_func(algo)) ++ log_query(F_NOEXTRA | F_KEYTAG | F_UPSTREAM, name, &a, "DS keytag %u"); ++ else ++ log_query(F_NOEXTRA | F_KEYTAG | F_UPSTREAM, name, &a, "DS keytag %u (no= t supported)"); ++ =20 + crecp->addr.ds.digest =3D digest; + crecp->addr.ds.keydata =3D key; + crecp->addr.ds.algo =3D algo; +@@ -1660,7 +1671,7 @@ static int prove_non_existence_nsec3(struct dns_header= *header, size_t plen, uns + *nons =3D 1; + =20 + /* Look though the NSEC3 records to find the first one with=20 +- an algorithm we support (currently only algo =3D=3D 1). ++ an algorithm we support. +=20 + Take the algo, iterations, and salt of that record + as the ones we're going to use, and prune any=20 +@@ -1674,7 +1685,7 @@ static int prove_non_existence_nsec3(struct dns_header= *header, size_t plen, uns + p +=3D 10; /* type, class, TTL, rdlen */ + algo =3D *p++; + =20 +- if (algo =3D=3D 1) ++ if ((hash =3D hash_find(nsec3_digest_name(algo)))) + break; /* known algo */ + } +=20 +@@ -1724,10 +1735,6 @@ static int prove_non_existence_nsec3(struct dns_heade= r *header, size_t plen, uns + nsecs[i] =3D nsec3p; + } +=20 +- /* Algo is checked as 1 above */ +- if (!(hash =3D hash_find("sha1"))) +- return 0; +- + if ((digest_len =3D hash_name(name, &digest, hash, salt, salt_len, iterat= ions)) =3D=3D 0) + return 0; + =20 +@@ -1843,8 +1850,10 @@ static int prove_non_existence(struct dns_header *hea= der, size_t plen, char *key + =20 + if (type_found =3D=3D T_NSEC) + return prove_non_existence_nsec(header, plen, nsecset, nsecs_found, dae= mon->workspacename, keyname, name, qtype, nons); +- else ++ else if (type_found =3D=3D T_NSEC3) + return prove_non_existence_nsec3(header, plen, nsecset, nsecs_found, da= emon->workspacename, keyname, name, qtype, wildname, nons); ++ else ++ return 0; + } +=20 + /* Check signing status of name. +@@ -1857,7 +1866,7 @@ static int prove_non_existence(struct dns_header *head= er, size_t plen, char *key + */ + static int zone_status(char *name, int class, char *keyname, time_t now) + { +- int secure_ds, name_start =3D strlen(name); ++ int name_start =3D strlen(name); + struct crec *crecp; + char *p; + =20 +@@ -1867,51 +1876,40 @@ static int zone_status(char *name, int class, char *= keyname, time_t now) + =20 + if (!(crecp =3D cache_find_by_name(NULL, keyname, now, F_DS))) + return STAT_NEED_DS; ++ =20 ++ /* F_DNSSECOK misused in DS cache records to non-existance of NS rec= ord. ++ F_NEG && !F_DNSSECOK implies that we've proved there's no DS record here, ++ but that's because there's no NS record either, ie this isn't the start ++ of a zone. We only prove that the DNS tree below a node is unsigned when ++ we prove that we're at a zone cut AND there's no DS record. */ ++ if (crecp->flags & F_NEG) ++ { ++ if (crecp->flags & F_DNSSECOK) ++ return STAT_INSECURE; /* proved no DS here */ ++ } + else + { +- secure_ds =3D 0; +- =20 ++ int gotone =3D 0; ++ ++ /* If all the DS records have digest and/or sig algos we don't support, ++ then the zone is insecure. Note that if an algo ++ appears in the DS, then RRSIGs for that algo MUST ++ exist for each RRset: 4035 para 2.2 So if we find ++ a DS here with digest and sig we can do, we're entitled ++ to assume we can validate the zone and if we can't later, ++ because an RRSIG is missing we return BOGUS. ++ */ + do=20 + { +- if (crecp->uid =3D=3D (unsigned int)class) +- { +- /* F_DNSSECOK misused in DS cache records to non-existance of NS record. +- F_NEG && !F_DNSSECOK implies that we've proved there's no DS record = here, +- but that's because there's no NS record either, ie this isn't the st= art +- of a zone. We only prove that the DNS tree below a node is unsigned = when +- we prove that we're at a zone cut AND there's no DS record. +- */ =20 +- if (crecp->flags & F_NEG) +- { +- if (crecp->flags & F_DNSSECOK) +- return STAT_INSECURE; /* proved no DS here */ +- } +- else if (!hash_find(ds_digest_name(crecp->addr.ds.digest)) || !verify_f= unc(crecp->addr.ds.algo)) +- return STAT_INSECURE; /* algo we can't use - insecure */ +- else +- secure_ds =3D 1; +- } ++ if (crecp->uid =3D=3D (unsigned int)class && ++ hash_find(ds_digest_name(crecp->addr.ds.digest)) && ++ verify_func(crecp->addr.ds.algo)) ++ gotone =3D 1; + } + while ((crecp =3D cache_find_by_name(crecp, keyname, now, F_DS))); +- } +- +- if (secure_ds) +- { +- /* We've found only DS records that attest to the DNSKEY RRset in the zo= ne, so we believe +- that RRset is good. Furthermore the DNSKEY whose hash is proved by th= e DS record is +- one we can use. However the DNSKEY RRset may contain more than one ke= y and +- one of the other keys may use an algorithm we don't support. If that'= s=20 +- the case the zone is insecure for us. */ +- =20 +- if (!(crecp =3D cache_find_by_name(NULL, keyname, now, F_DNSKEY))) +- return STAT_NEED_KEY; +=20 +- do=20 +- { +- if (crecp->uid =3D=3D (unsigned int)class && !verify_func(crecp->add= r.key.algo)) +- return STAT_INSECURE; +- } +- while ((crecp =3D cache_find_by_name(crecp, keyname, now, F_DNSKEY))); ++ if (!gotone) ++ return STAT_INSECURE; + } +=20 + if (name_start =3D=3D 0) +--=20 +1.7.10.4 + diff --git a/src/patches/dnsmasq/027-Nasty_rare_and_obscure_off-by-one_in_DNS= SEC_hostname_cmp.patch b/src/patches/dnsmasq/027-Nasty_rare_and_obscure_off-b= y-one_in_DNSSEC_hostname_cmp.patch new file mode 100644 index 0000000..031339e --- /dev/null +++ b/src/patches/dnsmasq/027-Nasty_rare_and_obscure_off-by-one_in_DNSSEC_hos= tname_cmp.patch @@ -0,0 +1,27 @@ +From 3e86d316c4bb406ed813aa5256615c8a95cac6d8 Mon Sep 17 00:00:00 2001 +From: Simon Kelley +Date: Sun, 20 Dec 2015 20:50:05 +0000 +Subject: [PATCH] Nasty, rare and obscure off-by-one in DNSSEC hostname_cmp(). + +--- + src/dnssec.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/src/dnssec.c b/src/dnssec.c +index e09f304..29848e1 100644 +--- a/src/dnssec.c ++++ b/src/dnssec.c +@@ -1394,8 +1394,8 @@ static int hostname_cmp(const char *a, const char *b) + if (sb =3D=3D b) + return 1; + =20 +- ea =3D sa--; +- eb =3D sb--; ++ ea =3D --sa; ++ eb =3D --sb; + } + } +=20 +--=20 +1.7.10.4 + diff --git a/src/patches/dnsmasq/028-Minor_tweak_to_previous_commit.patch b/s= rc/patches/dnsmasq/028-Minor_tweak_to_previous_commit.patch new file mode 100644 index 0000000..f3758fc --- /dev/null +++ b/src/patches/dnsmasq/028-Minor_tweak_to_previous_commit.patch @@ -0,0 +1,39 @@ +From a86fdf437ecc29398f9715ceb5240442a17ac014 Mon Sep 17 00:00:00 2001 +From: Simon Kelley +Date: Sun, 20 Dec 2015 21:19:20 +0000 +Subject: [PATCH] Minor tweak to previous commit. + +--- + src/dnssec.c | 6 ++---- + 1 file changed, 2 insertions(+), 4 deletions(-) + +diff --git a/src/dnssec.c b/src/dnssec.c +index 29848e1..9fa64b6 100644 +--- a/src/dnssec.c ++++ b/src/dnssec.c +@@ -1889,8 +1889,6 @@ static int zone_status(char *name, int class, char *ke= yname, time_t now) + } + else + { +- int gotone =3D 0; +- + /* If all the DS records have digest and/or sig algos we don't support, + then the zone is insecure. Note that if an algo + appears in the DS, then RRSIGs for that algo MUST +@@ -1904,11 +1902,11 @@ static int zone_status(char *name, int class, char *= keyname, time_t now) + if (crecp->uid =3D=3D (unsigned int)class && + hash_find(ds_digest_name(crecp->addr.ds.digest)) && + verify_func(crecp->addr.ds.algo)) +- gotone =3D 1; ++ break; + } + while ((crecp =3D cache_find_by_name(crecp, keyname, now, F_DS))); +=20 +- if (!gotone) ++ if (!crecp) + return STAT_INSECURE; + } +=20 +--=20 +1.7.10.4 + diff --git a/src/patches/dnsmasq/029-NSEC3_check_RFC5155_para_8_2.patch b/src= /patches/dnsmasq/029-NSEC3_check_RFC5155_para_8_2.patch new file mode 100644 index 0000000..33219d2 --- /dev/null +++ b/src/patches/dnsmasq/029-NSEC3_check_RFC5155_para_8_2.patch @@ -0,0 +1,39 @@ +From ce5732e84fc46d7f99c152f736cfb4ef5ec98a01 Mon Sep 17 00:00:00 2001 +From: Simon Kelley +Date: Sun, 20 Dec 2015 21:39:19 +0000 +Subject: [PATCH] NSEC3 check: RFC5155 para 8.2 + +--- + src/dnssec.c | 8 ++++++-- + 1 file changed, 6 insertions(+), 2 deletions(-) + +diff --git a/src/dnssec.c b/src/dnssec.c +index 9fa64b6..486e422 100644 +--- a/src/dnssec.c ++++ b/src/dnssec.c +@@ -1704,7 +1704,7 @@ static int prove_non_existence_nsec3(struct dns_header= *header, size_t plen, uns + for (i =3D 0; i < nsec_count; i++) + { + unsigned char *nsec3p =3D nsecs[i]; +- int this_iter; ++ int this_iter, flags; +=20 + nsecs[i] =3D NULL; /* Speculative, will be restored if OK. */ + =20 +@@ -1716,8 +1716,12 @@ static int prove_non_existence_nsec3(struct dns_heade= r *header, size_t plen, uns + if (*p++ !=3D algo) + continue; + =20 +- p++; /* flags */ ++ flags =3D *p++; /* flags */ + =20 ++ /* 5155 8.2 */ ++ if (flags !=3D 0 && flags !=3D 1) ++ continue; ++ + GETSHORT(this_iter, p); + if (this_iter !=3D iterations) + continue; +--=20 +1.7.10.4 + --=20 2.6.4 --===============3286943821881763409==--