vulnerabilities.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. .. SPDX-License-Identifier: CC-BY-SA-2.0-UK
  2. Checking for Vulnerabilities
  3. ****************************
  4. Vulnerabilities in Poky and OE-Core
  5. ===================================
  6. The Yocto Project has an infrastructure to track and address unfixed
  7. known security vulnerabilities, as tracked by the public
  8. :wikipedia:`Common Vulnerabilities and Exposures (CVE) <Common_Vulnerabilities_and_Exposures>`
  9. database.
  10. The Yocto Project maintains a `list of known vulnerabilities
  11. <https://autobuilder.yocto.io/pub/non-release/patchmetrics/>`__
  12. for packages in Poky and OE-Core, tracking the evolution of the number of
  13. unpatched CVEs and the status of patches. Such information is available for
  14. the current development version and for each supported release.
  15. Security is a process, not a product, and thus at any time, a number of security
  16. issues may be impacting Poky and OE-Core. It is up to the maintainers, users,
  17. contributors and anyone interested in the issues to investigate and possibly fix them by
  18. updating software components to newer versions or by applying patches to address them.
  19. It is recommended to work with Poky and OE-Core upstream maintainers and submit
  20. patches to fix them, see ":ref:`dev-manual/changes:submitting a change to the yocto project`" for details.
  21. Vulnerability check at build time
  22. =================================
  23. To enable a check for CVE security vulnerabilities using :ref:`cve-check <ref-classes-cve-check>` in the specific image
  24. or target you are building, add the following setting to your configuration::
  25. INHERIT += "cve-check"
  26. The CVE database contains some old incomplete entries which have been
  27. deemed not to impact Poky or OE-Core. These CVE entries can be excluded from the
  28. check using build configuration::
  29. include conf/distro/include/cve-extra-exclusions.inc
  30. With this CVE check enabled, BitBake build will try to map each compiled software component
  31. recipe name and version information to the CVE database and generate recipe and
  32. image specific reports. These reports will contain:
  33. - metadata about the software component like names and versions
  34. - metadata about the CVE issue such as description and NVD link
  35. - for each software component, a list of CVEs which are possibly impacting this version
  36. - status of each CVE: ``Patched``, ``Unpatched`` or ``Ignored``
  37. The status ``Patched`` means that a patch file to address the security issue has been
  38. applied. ``Unpatched`` status means that no patches to address the issue have been
  39. applied and that the issue needs to be investigated. ``Ignored`` means that after
  40. analysis, it has been deemed to ignore the issue as it for example affects
  41. the software component on a different operating system platform.
  42. After a build with CVE check enabled, reports for each compiled source recipe will be
  43. found in ``build/tmp/deploy/cve``.
  44. For example the CVE check report for the ``flex-native`` recipe looks like::
  45. $ cat poky/build/tmp/deploy/cve/flex-native
  46. LAYER: meta
  47. PACKAGE NAME: flex-native
  48. PACKAGE VERSION: 2.6.4
  49. CVE: CVE-2016-6354
  50. CVE STATUS: Patched
  51. CVE SUMMARY: Heap-based buffer overflow in the yy_get_next_buffer function in Flex before 2.6.1 might allow context-dependent attackers to cause a denial of service or possibly execute arbitrary code via vectors involving num_to_read.
  52. CVSS v2 BASE SCORE: 7.5
  53. CVSS v3 BASE SCORE: 9.8
  54. VECTOR: NETWORK
  55. MORE INFORMATION: https://nvd.nist.gov/vuln/detail/CVE-2016-6354
  56. LAYER: meta
  57. PACKAGE NAME: flex-native
  58. PACKAGE VERSION: 2.6.4
  59. CVE: CVE-2019-6293
  60. CVE STATUS: Ignored
  61. CVE SUMMARY: An issue was discovered in the function mark_beginning_as_normal in nfa.c in flex 2.6.4. There is a stack exhaustion problem caused by the mark_beginning_as_normal function making recursive calls to itself in certain scenarios involving lots of '*' characters. Remote attackers could leverage this vulnerability to cause a denial-of-service.
  62. CVSS v2 BASE SCORE: 4.3
  63. CVSS v3 BASE SCORE: 5.5
  64. VECTOR: NETWORK
  65. MORE INFORMATION: https://nvd.nist.gov/vuln/detail/CVE-2019-6293
  66. For images, a summary of all recipes included in the image and their CVEs is also
  67. generated in textual and JSON formats. These ``.cve`` and ``.json`` reports can be found
  68. in the ``tmp/deploy/images`` directory for each compiled image.
  69. At build time CVE check will also throw warnings about ``Unpatched`` CVEs::
  70. WARNING: flex-2.6.4-r0 do_cve_check: Found unpatched CVE (CVE-2019-6293), for more information check /poky/build/tmp/work/core2-64-poky-linux/flex/2.6.4-r0/temp/cve.log
  71. WARNING: libarchive-3.5.1-r0 do_cve_check: Found unpatched CVE (CVE-2021-36976), for more information check /poky/build/tmp/work/core2-64-poky-linux/libarchive/3.5.1-r0/temp/cve.log
  72. It is also possible to check the CVE status of individual packages as follows::
  73. bitbake -c cve_check flex libarchive
  74. Fixing CVE product name and version mappings
  75. ============================================
  76. By default, :ref:`cve-check <ref-classes-cve-check>` uses the recipe name :term:`BPN` as CVE
  77. product name when querying the CVE database. If this mapping contains false positives, e.g.
  78. some reported CVEs are not for the software component in question, or false negatives like
  79. some CVEs are not found to impact the recipe when they should, then the problems can be
  80. in the recipe name to CVE product mapping. These mapping issues can be fixed by setting
  81. the :term:`CVE_PRODUCT` variable inside the recipe. This defines the name of the software component in the
  82. upstream `NIST CVE database <https://nvd.nist.gov/>`__.
  83. The variable supports using vendor and product names like this::
  84. CVE_PRODUCT = "flex_project:flex"
  85. In this example the vendor name used in the CVE database is ``flex_project`` and the
  86. product is ``flex``. With this setting the ``flex`` recipe only maps to this specific
  87. product and not products from other vendors with same name ``flex``.
  88. Similarly, when the recipe version :term:`PV` is not compatible with software versions used by
  89. the upstream software component releases and the CVE database, these can be fixed using
  90. the :term:`CVE_VERSION` variable.
  91. Note that if the CVE entries in the NVD database contain bugs or have missing or incomplete
  92. information, it is recommended to fix the information there directly instead of working
  93. around the issues possibly for a long time in Poky and OE-Core side recipes. Feedback to
  94. NVD about CVE entries can be provided through the `NVD contact form <https://nvd.nist.gov/info/contact-form>`__.
  95. Fixing vulnerabilities in recipes
  96. =================================
  97. If a CVE security issue impacts a software component, it can be fixed by updating to a newer
  98. version of the software component or by applying a patch. For Poky and OE-Core master branches, updating
  99. to a newer software component release with fixes is the best option, but patches can be applied
  100. if releases are not yet available.
  101. For stable branches, it is preferred to apply patches for the issues. For some software
  102. components minor version updates can also be applied if they are backwards compatible.
  103. Here is an example of fixing CVE security issues with patch files,
  104. an example from the :oe_layerindex:`ffmpeg recipe</layerindex/recipe/47350>`::
  105. SRC_URI = "https://www.ffmpeg.org/releases/${BP}.tar.xz \
  106. file://0001-libavutil-include-assembly-with-full-path-from-sourc.patch \
  107. file://fix-CVE-2020-20446.patch \
  108. file://fix-CVE-2020-20453.patch \
  109. file://fix-CVE-2020-22015.patch \
  110. file://fix-CVE-2020-22021.patch \
  111. file://fix-CVE-2020-22033-CVE-2020-22019.patch \
  112. file://fix-CVE-2021-33815.patch \
  113. A good practice is to include the CVE identifier in both the patch file name
  114. and inside the patch file commit message using the format::
  115. CVE: CVE-2020-22033
  116. CVE checker will then capture this information and change the CVE status to ``Patched``
  117. in the generated reports.
  118. If analysis shows that the CVE issue does not impact the recipe due to configuration, platform,
  119. version or other reasons, the CVE can be marked as ``Ignored`` using the :term:`CVE_CHECK_IGNORE` variable.
  120. As mentioned previously, if data in the CVE database is wrong, it is recommend to fix those
  121. issues in the CVE database directly.
  122. Recipes can be completely skipped by CVE check by including the recipe name in
  123. the :term:`CVE_CHECK_SKIP_RECIPE` variable.
  124. Implementation details
  125. ======================
  126. Here's what the :ref:`cve-check <ref-classes-cve-check>` class does to
  127. find unpatched CVE IDs.
  128. First the code goes through each patch file provided by a recipe. If a valid CVE ID
  129. is found in the name of the file, the corresponding CVE is considered as patched.
  130. Don't forget that if multiple CVE IDs are found in the filename, only the last
  131. one is considered. Then, the code looks for ``CVE: CVE-ID`` lines in the patch
  132. file. The found CVE IDs are also considered as patched.
  133. Then, the code looks up all the CVE IDs in the NIST database for all the
  134. products defined in :term:`CVE_PRODUCT`. Then, for each found CVE:
  135. - If the package name (:term:`PN`) is part of
  136. :term:`CVE_CHECK_SKIP_RECIPE`, it is considered as ``Patched``.
  137. - If the CVE ID is part of :term:`CVE_CHECK_IGNORE`, it is
  138. set as ``Ignored``.
  139. - If the CVE ID is part of the patched CVE for the recipe, it is
  140. already considered as ``Patched``.
  141. - Otherwise, the code checks whether the recipe version (:term:`PV`)
  142. is within the range of versions impacted by the CVE. If so, the CVE
  143. is considered as ``Unpatched``.
  144. The CVE database is stored in :term:`DL_DIR` and can be inspected using
  145. ``sqlite3`` command as follows::
  146. sqlite3 downloads/CVE_CHECK/nvdcve_1.1.db .dump | grep CVE-2021-37462
  147. When analyzing CVEs, it is recommended to:
  148. - study the latest information in `CVE database <https://nvd.nist.gov/vuln/search>`__.
  149. - check how upstream developers of the software component addressed the issue, e.g.
  150. what patch was applied, which upstream release contains the fix.
  151. - check what other Linux distributions like `Debian <https://security-tracker.debian.org/tracker/>`__
  152. did to analyze and address the issue.
  153. - follow security notices from other Linux distributions.
  154. - follow public `open source security mailing lists <https://oss-security.openwall.org/wiki/mailing-lists>`__ for
  155. discussions and advance notifications of CVE bugs and software releases with fixes.