0002-resolved-simplify-alloc-size-calculation.patch 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. From db848813bae4d28c524b3b6a7dad135e426659ce Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
  3. Date: Sun, 18 Jun 2017 16:07:57 -0400
  4. Subject: [PATCH] resolved: simplify alloc size calculation
  5. The allocation size was calculated in a complicated way, and for values
  6. close to the page size we would actually allocate less than requested.
  7. Reported by Chris Coulson <chris.coulson@canonical.com>.
  8. CVE-2017-9445
  9. [Upstream commit: https://github.com/systemd/systemd/commit/db848813bae4d28c524b3b6a7dad135e426659ce]
  10. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  11. ---
  12. src/resolve/resolved-dns-packet.c | 8 +-------
  13. src/resolve/resolved-dns-packet.h | 2 --
  14. 2 files changed, 1 insertion(+), 9 deletions(-)
  15. diff --git a/src/resolve/resolved-dns-packet.c b/src/resolve/resolved-dns-packet.c
  16. index 240ee448f4..821b66e266 100644
  17. --- a/src/resolve/resolved-dns-packet.c
  18. +++ b/src/resolve/resolved-dns-packet.c
  19. @@ -47,13 +47,7 @@ int dns_packet_new(DnsPacket **ret, DnsProtocol protocol, size_t mtu) {
  20. assert(ret);
  21. - if (mtu <= UDP_PACKET_HEADER_SIZE)
  22. - a = DNS_PACKET_SIZE_START;
  23. - else
  24. - a = mtu - UDP_PACKET_HEADER_SIZE;
  25. -
  26. - if (a < DNS_PACKET_HEADER_SIZE)
  27. - a = DNS_PACKET_HEADER_SIZE;
  28. + a = MAX(mtu, DNS_PACKET_HEADER_SIZE);
  29. /* round up to next page size */
  30. a = PAGE_ALIGN(ALIGN(sizeof(DnsPacket)) + a) - ALIGN(sizeof(DnsPacket));
  31. diff --git a/src/resolve/resolved-dns-packet.h b/src/resolve/resolved-dns-packet.h
  32. index 2c92392e4d..3abcaf8cf3 100644
  33. --- a/src/resolve/resolved-dns-packet.h
  34. +++ b/src/resolve/resolved-dns-packet.h
  35. @@ -66,8 +66,6 @@ struct DnsPacketHeader {
  36. /* With EDNS0 we can use larger packets, default to 4096, which is what is commonly used */
  37. #define DNS_PACKET_UNICAST_SIZE_LARGE_MAX 4096
  38. -#define DNS_PACKET_SIZE_START 512
  39. -
  40. struct DnsPacket {
  41. int n_ref;
  42. DnsProtocol protocol;