Enable CFI (Control Flow Integrity)

Enable Control Flow Integrity in DNS resolver

There is no significant difference in PSS (Proportional Set Size) between
non-CFI and CFI binaries. Th performance overhead is also negligible
according to [1][2].

non-CFI (netd + DNS resolver):
+-----------+---------+---------+---------+---------+
|           | round#1 | round#2 | round#3 |   Avg   |
+-----------+---------+---------+---------+---------+
| RssAnon   | 1556 kB | 1528 kB | 1592 kB | 1559 kB |
| RssFile   | 4792 kB | 4872 kB | 4648 kB | 4771 kB |
| RssShmem  | 176 kB  | 176 kB  | 172 kB  | 175 kB  |
| Total PSS | 4381 kB | 4386 kB | 4437 kB | 4401 kB |
+-----------+---------+---------+---------+---------+

CFI (netd + DNS resolver):
+-----------+---------+---------+---------+---------+
|           | round#1 | round#2 | round#3 |   Avg   |
+-----------+---------+---------+---------+---------+
| RssAnon   | 1604 kB | 1608 kB | 1592 kB | 1601 kB |
| RssFile   | 4528 kB | 4892 kB | 4916 kB | 4779 kB |
| RssShmem  | 176 kB  | 176 kB  | 176 kB  | 176 kB  |
| Total PSS | 3962 kB | 4523 kB | 4483 kB | 4323 kB |
+-----------+---------+---------+---------+---------+

Binary size of aarch64 (bytes)
+----------------------+---------+--------+
|                      | non-CFI |  CFI   |
+----------------------+---------+--------+
| libnetd_resolv       |  668584 | 734552 |
+----------------------+---------+--------+

[1] https://source.android.com/devices/tech/debug/cfi
[2] http://clang.llvm.org/docs/ControlFlowIntegrity.html#performance

Bug: 146408702
Test: AOSP master:
      1. patch commit to enable CFI on both netd and resolver.
      2. m
      3. flash ROM.
      4. atest under system/netd/

      Compatibility:
      1. flash Android Q ROM.
      2. patch commit enabling CFI on both netd and resolver in branch
         qt-aml-resolv-release.
      3. build com.android.resolv in branch qt-aml-resolv-release.
      4. adb install CFI enabled resolver apex into Q device (non-CFI
         netd).
      5. atest under packages/modules/DnsResolver.


Change-Id: I65ce931d57bd285e1c49c34b4231f8151380eae3
1 file changed
tree: 261165427317a2fb8dd267561e5f7cded0b1d550
  1. aidl_api/
  2. apex/
  3. binder/
  4. include/
  5. tests/
  6. .editorconfig
  7. Android.bp
  8. Dns64Configuration.cpp
  9. Dns64Configuration.h
  10. DnsProxyListener.cpp
  11. DnsProxyListener.h
  12. DnsQueryLog.cpp
  13. DnsQueryLog.h
  14. DnsQueryLogTest.cpp
  15. DnsResolver.cpp
  16. DnsResolver.h
  17. DnsResolverService.cpp
  18. DnsResolverService.h
  19. DnsStats.cpp
  20. DnsStats.h
  21. DnsStatsTest.cpp
  22. DnsTlsDispatcher.cpp
  23. DnsTlsDispatcher.h
  24. DnsTlsQueryMap.cpp
  25. DnsTlsQueryMap.h
  26. DnsTlsServer.cpp
  27. DnsTlsServer.h
  28. DnsTlsSessionCache.cpp
  29. DnsTlsSessionCache.h
  30. DnsTlsSocket.cpp
  31. DnsTlsSocket.h
  32. DnsTlsSocketFactory.h
  33. DnsTlsTransport.cpp
  34. DnsTlsTransport.h
  35. getaddrinfo.cpp
  36. getaddrinfo.h
  37. gethnamaddr.cpp
  38. gethnamaddr.h
  39. hostent.h
  40. IDnsTlsSocket.h
  41. IDnsTlsSocketFactory.h
  42. IDnsTlsSocketObserver.h
  43. libnetd_resolv.map.txt
  44. LockedQueue.h
  45. NOTICE
  46. OWNERS
  47. params.h
  48. PREUPLOAD.cfg
  49. PrivateDnsConfiguration.cpp
  50. PrivateDnsConfiguration.h
  51. README-DoT.md
  52. README.md
  53. res_cache.cpp
  54. res_comp.cpp
  55. res_debug.cpp
  56. res_debug.h
  57. res_init.cpp
  58. res_init.h
  59. res_mkquery.cpp
  60. res_query.cpp
  61. res_send.cpp
  62. res_send.h
  63. res_stats.cpp
  64. resolv_cache.h
  65. resolv_cache_unit_test.cpp
  66. resolv_callback_unit_test.cpp
  67. resolv_private.h
  68. resolv_tls_unit_test.cpp
  69. resolv_unit_test.cpp
  70. ResolverController.cpp
  71. ResolverController.h
  72. ResolverEventReporter.cpp
  73. ResolverEventReporter.h
  74. ResolverStats.h
  75. sethostent.cpp
  76. stats.h
  77. stats.proto
  78. TEST_MAPPING
  79. util.cpp
  80. util.h
README.md

Logging

This code uses LOG(X) for logging. Log levels are VERBOSE,DEBUG,INFO,WARNING and ERROR. The default setting is WARNING and logs relate to WARNING and ERROR will be shown. If you want to enable the DEBUG level logs, using following command. adb shell service call dnsresolver 10 i32 1 VERBOSE 0 DEBUG 1 INFO 2 WARNING 3 ERROR 4 Verbose resolver logs could contain PII -- do NOT enable in production builds.