Revert "Revert "oran-shell-release: release image for F""
[pti/rtp.git] / meta-starlingx / meta-stx-integ / recipes-support / dnsmasq / dnsmasq / stx / dnsmasq-2.76-CVE-2017-14496.patch
1 From 5ab67e936085a9e584c9b3e43f442ef5bee7f40e Mon Sep 17 00:00:00 2001
2 From: Simon Kelley <simon@thekelleys.org.uk>
3 Date: Mon, 25 Sep 2017 20:11:58 +0100
4 Subject: [PATCH 5/9]     Security fix, CVE-2017-14496, Integer underflow in
5  DNS response creation.
6
7     Fix DoS in DNS. Invalid boundary checks in the
8     add_pseudoheader function allows a memcpy call with negative
9     size An attacker which can send malicious DNS queries
10     to dnsmasq can trigger a DoS remotely.
11     dnsmasq is vulnerable only if one of the following option is
12     specified: --add-mac, --add-cpe-id or --add-subnet.
13 ---
14  src/edns0.c | 13 ++++++++++++-
15  1 file changed, 12 insertions(+), 1 deletion(-)
16
17 diff --git a/src/edns0.c b/src/edns0.c
18 index d2b514b..eed135e 100644
19 --- a/src/edns0.c
20 +++ b/src/edns0.c
21 @@ -144,7 +144,7 @@ size_t add_pseudoheader(struct dns_header *header, size_t plen, unsigned char *l
22           GETSHORT(len, p);
23           
24           /* malformed option, delete the whole OPT RR and start again. */
25 -         if (i + len > rdlen)
26 +         if (i + 4 + len > rdlen)
27             {
28               rdlen = 0;
29               is_last = 0;
30 @@ -193,6 +193,8 @@ size_t add_pseudoheader(struct dns_header *header, size_t plen, unsigned char *l
31                              ntohs(header->ancount) + ntohs(header->nscount) + ntohs(header->arcount), 
32                              header, plen)))
33         return plen;
34 +      if (p + 11 > limit)
35 +       return plen; /* Too big */
36        *p++ = 0; /* empty name */
37        PUTSHORT(T_OPT, p);
38        PUTSHORT(udp_sz, p); /* max packet length, 512 if not given in EDNS0 header */
39 @@ -204,6 +206,11 @@ size_t add_pseudoheader(struct dns_header *header, size_t plen, unsigned char *l
40        /* Copy back any options */
41        if (buff)
42         {
43 +          if (p + rdlen > limit)
44 +          {
45 +            free(buff);
46 +            return plen; /* Too big */
47 +          }
48           memcpy(p, buff, rdlen);
49           free(buff);
50           p += rdlen;
51 @@ -217,8 +224,12 @@ size_t add_pseudoheader(struct dns_header *header, size_t plen, unsigned char *l
52    /* Add new option */
53    if (optno != 0 && replace != 2)
54      {
55 +      if (p + 4 > limit)
56 +       return plen; /* Too big */
57        PUTSHORT(optno, p);
58        PUTSHORT(optlen, p);
59 +      if (p + optlen > limit)
60 +       return plen; /* Too big */
61        memcpy(p, opt, optlen);
62        p += optlen;  
63        PUTSHORT(p - datap, lenp);
64 -- 
65 2.9.5
66