vulnerabilities.rst 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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 ":doc:`../contributor-guide/submit-changes`" for details.
  21. Vulnerability check at build time
  22. =================================
  23. To enable a check for CVE security vulnerabilities using
  24. :ref:`ref-classes-cve-check` in the specific image or target you are building,
  25. add the following setting to your configuration::
  26. INHERIT += "cve-check"
  27. The CVE database contains some old incomplete entries which have been
  28. deemed not to impact Poky or OE-Core. These CVE entries can be excluded from the
  29. check using build configuration::
  30. include conf/distro/include/cve-extra-exclusions.inc
  31. With this CVE check enabled, BitBake build will try to map each compiled software component
  32. recipe name and version information to the CVE database and generate recipe and
  33. image specific reports. These reports will contain:
  34. - metadata about the software component like names and versions
  35. - metadata about the CVE issue such as description and NVD link
  36. - for each software component, a list of CVEs which are possibly impacting this version
  37. - status of each CVE: ``Patched``, ``Unpatched`` or ``Ignored``
  38. The status ``Patched`` means that a patch file to address the security issue has been
  39. applied. ``Unpatched`` status means that no patches to address the issue have been
  40. applied and that the issue needs to be investigated. ``Ignored`` means that after
  41. analysis, it has been deemed to ignore the issue as it for example affects
  42. the software component on a different operating system platform.
  43. By default, no NVD API key is used to retrieve data from the CVE database, which
  44. results in larger delays between NVD API requests. See the :term:`NVDCVE_API_KEY`
  45. documentation on how to request and set a NVD API key.
  46. After a build with CVE check enabled, reports for each compiled source recipe will be
  47. found in ``build/tmp/deploy/cve``.
  48. For example the CVE check report for the ``flex-native`` recipe looks like::
  49. $ cat ./tmp/deploy/cve/flex-native_cve.json
  50. {
  51. "version": "1",
  52. "package": [
  53. {
  54. "name": "flex-native",
  55. "layer": "meta",
  56. "version": "2.6.4",
  57. "products": [
  58. {
  59. "product": "flex",
  60. "cvesInRecord": "No"
  61. },
  62. {
  63. "product": "flex",
  64. "cvesInRecord": "Yes"
  65. }
  66. ],
  67. "issue": [
  68. {
  69. "id": "CVE-2006-0459",
  70. "status": "Patched",
  71. "link": "https://nvd.nist.gov/vuln/detail/CVE-2006-0459",
  72. "summary": "flex.skl in Will Estes and John Millaway Fast Lexical Analyzer Generator (flex) before 2.5.33 does not allocate enough memory for grammars containing (1) REJECT statements or (2) trailing context rules, which causes flex to generate code that contains a buffer overflow that might allow context-dependent attackers to execute arbitrary code.",
  73. "scorev2": "7.5",
  74. "scorev3": "0.0",
  75. "scorev4": "0.0",
  76. "modified": "2024-11-21T00:06Z",
  77. "vector": "NETWORK",
  78. "vectorString": "AV:N/AC:L/Au:N/C:P/I:P/A:P",
  79. "detail": "version-not-in-range"
  80. },
  81. {
  82. "id": "CVE-2016-6354",
  83. "status": "Patched",
  84. "link": "https://nvd.nist.gov/vuln/detail/CVE-2016-6354",
  85. "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.",
  86. "scorev2": "7.5",
  87. "scorev3": "9.8",
  88. "scorev4": "0.0",
  89. "modified": "2024-11-21T02:55Z",
  90. "vector": "NETWORK",
  91. "vectorString": "AV:N/AC:L/Au:N/C:P/I:P/A:P",
  92. "detail": "version-not-in-range"
  93. },
  94. {
  95. "id": "CVE-2019-6293",
  96. "status": "Ignored",
  97. "link": "https://nvd.nist.gov/vuln/detail/CVE-2019-6293",
  98. "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.",
  99. "scorev2": "4.3",
  100. "scorev3": "5.5",
  101. "scorev4": "0.0",
  102. "modified": "2024-11-21T04:46Z",
  103. "vector": "NETWORK",
  104. "vectorString": "AV:N/AC:M/Au:N/C:N/I:N/A:P",
  105. "detail": "upstream-wontfix",
  106. "description": "there is stack exhaustion but no bug and it is building the parser, not running it, effectively similar to a compiler ICE. Upstream no plans to address this."
  107. }
  108. ]
  109. }
  110. ]
  111. }
  112. For images, a summary of all recipes included in the image and their CVEs is also
  113. generated in the JSON format. These ``.json`` reports can be found
  114. in the ``tmp/deploy/images`` directory for each compiled image.
  115. At build time CVE check will also throw warnings about ``Unpatched`` CVEs::
  116. WARNING: qemu-native-9.2.0-r0 do_cve_check: Found unpatched CVE (CVE-2023-1386)
  117. It is also possible to check the CVE status of individual packages as follows::
  118. bitbake -c cve_check flex libarchive
  119. Fixing CVE product name and version mappings
  120. ============================================
  121. By default, :ref:`ref-classes-cve-check` uses the recipe name :term:`BPN` as CVE
  122. product name when querying the CVE database. If this mapping contains false positives, e.g.
  123. some reported CVEs are not for the software component in question, or false negatives like
  124. some CVEs are not found to impact the recipe when they should, then the problems can be
  125. in the recipe name to CVE product mapping. These mapping issues can be fixed by setting
  126. the :term:`CVE_PRODUCT` variable inside the recipe. This defines the name of the software component in the
  127. upstream `NIST CVE database <https://nvd.nist.gov/>`__.
  128. The variable supports using vendor and product names like this::
  129. CVE_PRODUCT = "flex_project:flex westes:flex"
  130. In this example we have two possible vendors names, ``flex_project`` and ``westes``,
  131. with the product name ``flex``. With this setting the ``flex`` recipe only maps to this specific
  132. product and not products from other vendors with same name ``flex``.
  133. Similarly, when the recipe version :term:`PV` is not compatible with software versions used by
  134. the upstream software component releases and the CVE database, these can be fixed using
  135. the :term:`CVE_VERSION` variable.
  136. Note that if the CVE entries in the NVD database contain bugs or have missing or incomplete
  137. information, it is recommended to fix the information there directly instead of working
  138. around the issues possibly for a long time in Poky and OE-Core side recipes. Feedback to
  139. NVD about CVE entries can be provided through the `NVD contact form <https://nvd.nist.gov/info/contact-form>`__.
  140. Fixing vulnerabilities in recipes
  141. =================================
  142. Suppose a CVE security issue impacts a software component. In that case, it can
  143. be fixed by updating to a newer version, by applying a patch, or by marking it
  144. as patched via :term:`CVE_STATUS` variable flag. For Poky and OE-Core master
  145. branches, updating to a more recent software component release with fixes is
  146. the best option, but patches can be applied if releases are not yet available.
  147. For stable branches, we want to avoid API (Application Programming Interface)
  148. or ABI (Application Binary Interface) breakages. When submitting an update,
  149. a minor version update of a component is preferred if the version is
  150. backward-compatible. Many software components have backward-compatible stable
  151. versions, with a notable example of the Linux kernel. However, if the new
  152. version does or likely might introduce incompatibilities, extracting and
  153. backporting patches is preferred.
  154. Here is an example of fixing CVE security issues with patch files,
  155. an example from the :oe_layerindex:`ffmpeg recipe for dunfell </layerindex/recipe/122174>`::
  156. SRC_URI = "https://www.ffmpeg.org/releases/${BP}.tar.xz \
  157. file://mips64_cpu_detection.patch \
  158. file://CVE-2020-12284.patch \
  159. file://0001-libavutil-include-assembly-with-full-path-from-sourc.patch \
  160. file://CVE-2021-3566.patch \
  161. file://CVE-2021-38291.patch \
  162. file://CVE-2022-1475.patch \
  163. file://CVE-2022-3109.patch \
  164. file://CVE-2022-3341.patch \
  165. file://CVE-2022-48434.patch \
  166. "
  167. The recipe has both generic and security-related fixes. The CVE patch files are named
  168. according to the CVE they fix.
  169. When preparing the patch file, take the original patch from the upstream repository.
  170. Do not use patches from different distributions, except if it is the only available source.
  171. Modify the patch adding OE-related metadata. We will follow the example of the
  172. ``CVE-2022-3341.patch``.
  173. The original `commit message <https://github.com/FFmpeg/FFmpeg/commit/9cf652cef49d74afe3d454f27d49eb1a1394951e.patch/>`__
  174. is::
  175. From 9cf652cef49d74afe3d454f27d49eb1a1394951e Mon Sep 17 00:00:00 2001
  176. From: Jiasheng Jiang <jiasheng@iscas.ac.cn>
  177. Date: Wed, 23 Feb 2022 10:31:59 +0800
  178. Subject: [PATCH] avformat/nutdec: Add check for avformat_new_stream
  179. Check for failure of avformat_new_stream() and propagate
  180. the error code.
  181. Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
  182. ---
  183. libavformat/nutdec.c | 16 ++++++++++++----
  184. 1 file changed, 12 insertions(+), 4 deletions(-)
  185. For the correct operations of the ``cve-check``, it requires the CVE
  186. identification in a ``CVE:`` tag of the patch file commit message using
  187. the format::
  188. CVE: CVE-2022-3341
  189. It is also recommended to add the ``Upstream-Status:`` tag with a link
  190. to the original patch and sign-off by people working on the backport.
  191. If there are any modifications to the original patch, note them in
  192. the ``Comments:`` tag.
  193. With the additional information, the header of the patch file in OE-core becomes::
  194. From 9cf652cef49d74afe3d454f27d49eb1a1394951e Mon Sep 17 00:00:00 2001
  195. From: Jiasheng Jiang <jiasheng@iscas.ac.cn>
  196. Date: Wed, 23 Feb 2022 10:31:59 +0800
  197. Subject: [PATCH] avformat/nutdec: Add check for avformat_new_stream
  198. Check for failure of avformat_new_stream() and propagate
  199. the error code.
  200. Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
  201. CVE: CVE-2022-3341
  202. Upstream-Status: Backport [https://github.com/FFmpeg/FFmpeg/commit/9cf652cef49d74afe3d454f27d49eb1a1394951e]
  203. Comments: Refreshed Hunk
  204. Signed-off-by: Narpat Mali <narpat.mali@windriver.com>
  205. Signed-off-by: Bhabu Bindu <bhabu.bindu@kpit.com>
  206. ---
  207. libavformat/nutdec.c | 16 ++++++++++++----
  208. 1 file changed, 12 insertions(+), 4 deletions(-)
  209. A good practice is to include the CVE identifier in the patch file name, the patch file
  210. commit message and optionally in the recipe commit message.
  211. CVE checker will then capture this information and change the CVE status to ``Patched``
  212. in the generated reports.
  213. If analysis shows that the CVE issue does not impact the recipe due to configuration, platform,
  214. version or other reasons, the CVE can be marked as ``Ignored`` by using
  215. the :term:`CVE_STATUS` variable flag with appropriate reason which is mapped to ``Ignored``.
  216. The entry should have the format like::
  217. CVE_STATUS[CVE-2016-10642] = "cpe-incorrect: This is specific to the npm package that installs cmake, so isn't relevant to OpenEmbedded"
  218. As mentioned previously, if data in the CVE database is wrong, it is recommended
  219. to fix those issues in the CVE database (NVD in the case of OE-core and Poky)
  220. directly.
  221. Note that if there are many CVEs with the same status and reason, those can be
  222. shared by using the :term:`CVE_STATUS_GROUPS` variable.
  223. Recipes can be completely skipped by CVE check by including the recipe name in
  224. the :term:`CVE_CHECK_SKIP_RECIPE` variable.
  225. Implementation details
  226. ======================
  227. Here's what the :ref:`ref-classes-cve-check` class does to find unpatched CVE IDs.
  228. First the code goes through each patch file provided by a recipe. If a valid CVE ID
  229. is found in the name of the file, the corresponding CVE is considered as patched.
  230. Don't forget that if multiple CVE IDs are found in the filename, only the last
  231. one is considered. Then, the code looks for ``CVE: CVE-ID`` lines in the patch
  232. file. The found CVE IDs are also considered as patched.
  233. Additionally ``CVE_STATUS`` variable flags are parsed for reasons mapped to ``Patched``
  234. and these are also considered as patched.
  235. Then, the code looks up all the CVE IDs in the NIST database for all the
  236. products defined in :term:`CVE_PRODUCT`. Then, for each found CVE:
  237. - If the package name (:term:`PN`) is part of
  238. :term:`CVE_CHECK_SKIP_RECIPE`, it is considered as ``Patched``.
  239. - If the CVE ID has status ``CVE_STATUS[<CVE ID>] = "ignored"`` or if it's set to
  240. any reason which is mapped to status ``Ignored`` via ``CVE_CHECK_STATUSMAP``,
  241. it is set as ``Ignored``.
  242. - If the CVE ID is part of the patched CVE for the recipe, it is
  243. already considered as ``Patched``.
  244. - Otherwise, the code checks whether the recipe version (:term:`PV`)
  245. is within the range of versions impacted by the CVE. If so, the CVE
  246. is considered as ``Unpatched``.
  247. The CVE database is stored in :term:`DL_DIR` and can be inspected using
  248. ``sqlite3`` command as follows::
  249. sqlite3 downloads/CVE_CHECK/nvdcve_1.1.db .dump | grep CVE-2021-37462
  250. When analyzing CVEs, it is recommended to:
  251. - study the latest information in `CVE database <https://nvd.nist.gov/vuln/search>`__.
  252. - check how upstream developers of the software component addressed the issue, e.g.
  253. what patch was applied, which upstream release contains the fix.
  254. - check what other Linux distributions like `Debian <https://security-tracker.debian.org/tracker/>`__
  255. did to analyze and address the issue.
  256. - follow security notices from other Linux distributions.
  257. - follow public `open source security mailing lists <https://oss-security.openwall.org/wiki/mailing-lists>`__ for
  258. discussions and advance notifications of CVE bugs and software releases with fixes.