blob: d715fbf4d8a001e6268e4f8a8c38f6422909891c [file] [log] [blame]
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001# This class is used to check recipes against public CVEs.
2#
3# In order to use this class just inherit the class in the
4# local.conf file and it will add the cve_check task for
5# every recipe. The task can be used per recipe, per image,
6# or using the special cases "world" and "universe". The
7# cve_check task will print a warning for every unpatched
8# CVE found and generate a file in the recipe WORKDIR/cve
9# directory. If an image is build it will generate a report
10# in DEPLOY_DIR_IMAGE for all the packages used.
11#
12# Example:
13# bitbake -c cve_check openssl
14# bitbake core-image-sato
15# bitbake -k -c cve_check universe
16#
17# DISCLAIMER
18#
19# This class/tool is meant to be used as support and not
20# the only method to check against CVEs. Running this tool
21# doesn't guarantee your packages are free of CVEs.
22
Patrick Williams213cb262021-08-07 19:21:33 -050023# The product name that the CVE database uses defaults to BPN, but may need to
Brad Bishop37a0e4d2017-12-04 01:01:44 -050024# be overriden per recipe (for example tiff.bb sets CVE_PRODUCT=libtiff).
Brad Bishop6e60e8b2018-02-01 10:27:11 -050025CVE_PRODUCT ??= "${BPN}"
Brad Bishop316dfdd2018-06-25 12:45:53 -040026CVE_VERSION ??= "${PV}"
Brad Bishop37a0e4d2017-12-04 01:01:44 -050027
Patrick Williamsc0f7c042017-02-23 20:41:17 -060028CVE_CHECK_DB_DIR ?= "${DL_DIR}/CVE_CHECK"
Andrew Geissler82c905d2020-04-13 13:39:40 -050029CVE_CHECK_DB_FILE ?= "${CVE_CHECK_DB_DIR}/nvdcve_1.1.db"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050030CVE_CHECK_DB_FILE_LOCK ?= "${CVE_CHECK_DB_FILE}.lock"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060031
Brad Bishop316dfdd2018-06-25 12:45:53 -040032CVE_CHECK_LOG ?= "${T}/cve.log"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060033CVE_CHECK_TMP_FILE ?= "${TMPDIR}/cve_check"
Andrew Geisslerb7d28612020-07-24 16:15:54 -050034CVE_CHECK_SUMMARY_DIR ?= "${LOG_DIR}/cve"
35CVE_CHECK_SUMMARY_FILE_NAME ?= "cve-summary"
36CVE_CHECK_SUMMARY_FILE ?= "${CVE_CHECK_SUMMARY_DIR}/${CVE_CHECK_SUMMARY_FILE_NAME}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060037
38CVE_CHECK_DIR ??= "${DEPLOY_DIR}/cve"
Andrew Geisslerc3d88e42020-10-02 09:45:00 -050039CVE_CHECK_RECIPE_FILE ?= "${CVE_CHECK_DIR}/${PN}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060040CVE_CHECK_MANIFEST ?= "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.cve"
41CVE_CHECK_COPY_FILES ??= "1"
42CVE_CHECK_CREATE_MANIFEST ??= "1"
43
Andrew Geisslerc3d88e42020-10-02 09:45:00 -050044CVE_CHECK_REPORT_PATCHED ??= "1"
45
Patrick Williamsc0f7c042017-02-23 20:41:17 -060046# Whitelist for packages (PN)
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000047CVE_CHECK_SKIP_RECIPE ?= ""
Patrick Williamsc0f7c042017-02-23 20:41:17 -060048
Brad Bishop96ff1982019-08-19 13:50:42 -040049# Whitelist for CVE. If a CVE is found, then it is considered patched.
50# The value is a string containing space separated CVE values:
Andrew Geisslerc3d88e42020-10-02 09:45:00 -050051#
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000052# CVE_CHECK_IGNORE = 'CVE-2014-2524 CVE-2018-1234'
Andrew Geisslerc3d88e42020-10-02 09:45:00 -050053#
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000054CVE_CHECK_IGNORE ?= ""
Patrick Williamsc0f7c042017-02-23 20:41:17 -060055
Andrew Geisslerd1e89492021-02-12 15:35:20 -060056# Layers to be excluded
57CVE_CHECK_LAYER_EXCLUDELIST ??= ""
58
Patrick Williams213cb262021-08-07 19:21:33 -050059# Layers to be included
Andrew Geisslerd1e89492021-02-12 15:35:20 -060060CVE_CHECK_LAYER_INCLUDELIST ??= ""
61
62
Patrick Williams213cb262021-08-07 19:21:33 -050063# set to "alphabetical" for version using single alphabetical character as increment release
Andrew Geisslerd1e89492021-02-12 15:35:20 -060064CVE_VERSION_SUFFIX ??= ""
65
Andrew Geisslerb7d28612020-07-24 16:15:54 -050066python cve_save_summary_handler () {
67 import shutil
68 import datetime
69
70 cve_tmp_file = d.getVar("CVE_CHECK_TMP_FILE")
71
72 cve_summary_name = d.getVar("CVE_CHECK_SUMMARY_FILE_NAME")
73 cvelogpath = d.getVar("CVE_CHECK_SUMMARY_DIR")
74 bb.utils.mkdirhier(cvelogpath)
75
76 timestamp = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
77 cve_summary_file = os.path.join(cvelogpath, "%s-%s.txt" % (cve_summary_name, timestamp))
78
Andrew Geisslerc9f78652020-09-18 14:11:35 -050079 if os.path.exists(cve_tmp_file):
80 shutil.copyfile(cve_tmp_file, cve_summary_file)
Andrew Geisslerb7d28612020-07-24 16:15:54 -050081
Andrew Geisslerc9f78652020-09-18 14:11:35 -050082 if cve_summary_file and os.path.exists(cve_summary_file):
83 cvefile_link = os.path.join(cvelogpath, cve_summary_name)
Andrew Geisslerb7d28612020-07-24 16:15:54 -050084
Andrew Geisslerc9f78652020-09-18 14:11:35 -050085 if os.path.exists(os.path.realpath(cvefile_link)):
86 os.remove(cvefile_link)
87 os.symlink(os.path.basename(cve_summary_file), cvefile_link)
Andrew Geisslerb7d28612020-07-24 16:15:54 -050088}
89
90addhandler cve_save_summary_handler
91cve_save_summary_handler[eventmask] = "bb.event.BuildCompleted"
92
Patrick Williamsc0f7c042017-02-23 20:41:17 -060093python do_cve_check () {
94 """
95 Check recipe for patched and unpatched CVEs
96 """
Patrick Williams0ca19cc2021-08-16 14:03:13 -050097 from oe.cve_check import get_patched_cves
Patrick Williamsc0f7c042017-02-23 20:41:17 -060098
Brad Bishop96ff1982019-08-19 13:50:42 -040099 if os.path.exists(d.getVar("CVE_CHECK_DB_FILE")):
Andrew Geissler82c905d2020-04-13 13:39:40 -0500100 try:
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500101 patched_cves = get_patched_cves(d)
Andrew Geissler82c905d2020-04-13 13:39:40 -0500102 except FileNotFoundError:
103 bb.fatal("Failure in searching patches")
104 whitelisted, patched, unpatched = check_cves(d, patched_cves)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600105 if patched or unpatched:
106 cve_data = get_cve_info(d, patched + unpatched)
Andrew Geissler82c905d2020-04-13 13:39:40 -0500107 cve_write_data(d, patched, unpatched, whitelisted, cve_data)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600108 else:
Brad Bishop96ff1982019-08-19 13:50:42 -0400109 bb.note("No CVE database found, skipping CVE check")
110
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600111}
112
Andrew Geissler1e34c2d2020-05-29 16:02:59 -0500113addtask cve_check before do_build after do_fetch
Andrew Geissler595f6302022-01-24 19:11:47 +0000114do_cve_check[lockfiles] += "${CVE_CHECK_DB_FILE_LOCK}"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500115do_cve_check[depends] = "cve-update-db-native:do_fetch"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600116do_cve_check[nostamp] = "1"
117
118python cve_check_cleanup () {
119 """
120 Delete the file used to gather all the CVE information.
121 """
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500122 bb.utils.remove(e.data.getVar("CVE_CHECK_TMP_FILE"))
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600123}
124
125addhandler cve_check_cleanup
126cve_check_cleanup[eventmask] = "bb.cooker.CookerExit"
127
128python cve_check_write_rootfs_manifest () {
129 """
130 Create CVE manifest when building an image
131 """
132
133 import shutil
134
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500135 if d.getVar("CVE_CHECK_COPY_FILES") == "1":
Andrew Geisslerc3d88e42020-10-02 09:45:00 -0500136 deploy_file = d.getVar("CVE_CHECK_RECIPE_FILE")
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500137 if os.path.exists(deploy_file):
138 bb.utils.remove(deploy_file)
139
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500140 if os.path.exists(d.getVar("CVE_CHECK_TMP_FILE")):
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600141 bb.note("Writing rootfs CVE manifest")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500142 deploy_dir = d.getVar("DEPLOY_DIR_IMAGE")
143 link_name = d.getVar("IMAGE_LINK_NAME")
144 manifest_name = d.getVar("CVE_CHECK_MANIFEST")
145 cve_tmp_file = d.getVar("CVE_CHECK_TMP_FILE")
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600146
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000147 bb.utils.mkdirhier(os.path.dirname(manifest_name))
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600148 shutil.copyfile(cve_tmp_file, manifest_name)
149
150 if manifest_name and os.path.exists(manifest_name):
151 manifest_link = os.path.join(deploy_dir, "%s.cve" % link_name)
152 # If we already have another manifest, update symlinks
153 if os.path.exists(os.path.realpath(manifest_link)):
154 os.remove(manifest_link)
155 os.symlink(os.path.basename(manifest_name), manifest_link)
156 bb.plain("Image CVE report stored in: %s" % manifest_name)
157}
158
Patrick Williams213cb262021-08-07 19:21:33 -0500159ROOTFS_POSTPROCESS_COMMAND:prepend = "${@'cve_check_write_rootfs_manifest; ' if d.getVar('CVE_CHECK_CREATE_MANIFEST') == '1' else ''}"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500160do_rootfs[recrdeptask] += "${@'do_cve_check' if d.getVar('CVE_CHECK_CREATE_MANIFEST') == '1' else ''}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600161
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600162def check_cves(d, patched_cves):
163 """
Brad Bishopf3fd2882019-06-21 08:06:37 -0400164 Connect to the NVD database and find unpatched cves.
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600165 """
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600166 from oe.cve_check import Version
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600167
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600168 pn = d.getVar("PN")
169 real_pv = d.getVar("PV")
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600170 suffix = d.getVar("CVE_VERSION_SUFFIX")
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600171
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600172 cves_unpatched = []
Brad Bishopf3fd2882019-06-21 08:06:37 -0400173 # CVE_PRODUCT can contain more than one product (eg. curl/libcurl)
Brad Bishop96ff1982019-08-19 13:50:42 -0400174 products = d.getVar("CVE_PRODUCT").split()
Brad Bishop316dfdd2018-06-25 12:45:53 -0400175 # If this has been unset then we're not scanning for CVEs here (for example, image recipes)
Brad Bishop96ff1982019-08-19 13:50:42 -0400176 if not products:
Andrew Geissler82c905d2020-04-13 13:39:40 -0500177 return ([], [], [])
Brad Bishop316dfdd2018-06-25 12:45:53 -0400178 pv = d.getVar("CVE_VERSION").split("+git")[0]
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600179
Patrick Williams213cb262021-08-07 19:21:33 -0500180 # If the recipe has been whitelisted we return empty lists
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000181 if pn in d.getVar("CVE_CHECK_SKIP_RECIPE").split():
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600182 bb.note("Recipe has been whitelisted, skipping check")
Andrew Geissler82c905d2020-04-13 13:39:40 -0500183 return ([], [], [])
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600184
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000185 cve_whitelist = d.getVar("CVE_CHECK_IGNORE").split()
Brad Bishop96ff1982019-08-19 13:50:42 -0400186
Brad Bishopf3fd2882019-06-21 08:06:37 -0400187 import sqlite3
Brad Bishop6dbb3162019-11-25 09:41:34 -0500188 db_file = d.expand("file:${CVE_CHECK_DB_FILE}?mode=ro")
189 conn = sqlite3.connect(db_file, uri=True)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600190
Brad Bishop6dbb3162019-11-25 09:41:34 -0500191 # For each of the known product names (e.g. curl has CPEs using curl and libcurl)...
Brad Bishop96ff1982019-08-19 13:50:42 -0400192 for product in products:
Brad Bishop96ff1982019-08-19 13:50:42 -0400193 if ":" in product:
194 vendor, product = product.split(":", 1)
Brad Bishop96ff1982019-08-19 13:50:42 -0400195 else:
Brad Bishop6dbb3162019-11-25 09:41:34 -0500196 vendor = "%"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600197
Brad Bishop6dbb3162019-11-25 09:41:34 -0500198 # Find all relevant CVE IDs.
199 for cverow in conn.execute("SELECT DISTINCT ID FROM PRODUCTS WHERE PRODUCT IS ? AND VENDOR LIKE ?", (product, vendor)):
200 cve = cverow[0]
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600201
Brad Bishop96ff1982019-08-19 13:50:42 -0400202 if cve in cve_whitelist:
203 bb.note("%s-%s has been whitelisted for %s" % (product, pv, cve))
Brad Bishop64c979e2019-11-04 13:55:29 -0500204 # TODO: this should be in the report as 'whitelisted'
205 patched_cves.add(cve)
Brad Bishop6dbb3162019-11-25 09:41:34 -0500206 continue
Brad Bishopf3fd2882019-06-21 08:06:37 -0400207 elif cve in patched_cves:
208 bb.note("%s has been patched" % (cve))
Brad Bishop6dbb3162019-11-25 09:41:34 -0500209 continue
210
211 vulnerable = False
212 for row in conn.execute("SELECT * FROM PRODUCTS WHERE ID IS ? AND PRODUCT IS ? AND VENDOR LIKE ?", (cve, product, vendor)):
213 (_, _, _, version_start, operator_start, version_end, operator_end) = row
214 #bb.debug(2, "Evaluating row " + str(row))
215
Andrew Geissler82c905d2020-04-13 13:39:40 -0500216 if (operator_start == '=' and pv == version_start) or version_start == '-':
Brad Bishop6dbb3162019-11-25 09:41:34 -0500217 vulnerable = True
Brad Bishop96ff1982019-08-19 13:50:42 -0400218 else:
219 if operator_start:
220 try:
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600221 vulnerable_start = (operator_start == '>=' and Version(pv,suffix) >= Version(version_start,suffix))
222 vulnerable_start |= (operator_start == '>' and Version(pv,suffix) > Version(version_start,suffix))
Brad Bishop96ff1982019-08-19 13:50:42 -0400223 except:
Brad Bishop64c979e2019-11-04 13:55:29 -0500224 bb.warn("%s: Failed to compare %s %s %s for %s" %
Brad Bishop96ff1982019-08-19 13:50:42 -0400225 (product, pv, operator_start, version_start, cve))
Brad Bishop6dbb3162019-11-25 09:41:34 -0500226 vulnerable_start = False
Brad Bishop96ff1982019-08-19 13:50:42 -0400227 else:
Brad Bishop6dbb3162019-11-25 09:41:34 -0500228 vulnerable_start = False
Brad Bishop96ff1982019-08-19 13:50:42 -0400229
230 if operator_end:
231 try:
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600232 vulnerable_end = (operator_end == '<=' and Version(pv,suffix) <= Version(version_end,suffix) )
233 vulnerable_end |= (operator_end == '<' and Version(pv,suffix) < Version(version_end,suffix) )
Brad Bishop96ff1982019-08-19 13:50:42 -0400234 except:
Brad Bishop64c979e2019-11-04 13:55:29 -0500235 bb.warn("%s: Failed to compare %s %s %s for %s" %
Brad Bishop96ff1982019-08-19 13:50:42 -0400236 (product, pv, operator_end, version_end, cve))
Brad Bishop6dbb3162019-11-25 09:41:34 -0500237 vulnerable_end = False
Brad Bishop96ff1982019-08-19 13:50:42 -0400238 else:
Brad Bishop6dbb3162019-11-25 09:41:34 -0500239 vulnerable_end = False
Brad Bishop96ff1982019-08-19 13:50:42 -0400240
241 if operator_start and operator_end:
Brad Bishop6dbb3162019-11-25 09:41:34 -0500242 vulnerable = vulnerable_start and vulnerable_end
Brad Bishop96ff1982019-08-19 13:50:42 -0400243 else:
Brad Bishop6dbb3162019-11-25 09:41:34 -0500244 vulnerable = vulnerable_start or vulnerable_end
Brad Bishop96ff1982019-08-19 13:50:42 -0400245
Brad Bishop6dbb3162019-11-25 09:41:34 -0500246 if vulnerable:
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600247 bb.note("%s-%s is vulnerable to %s" % (pn, real_pv, cve))
Brad Bishop96ff1982019-08-19 13:50:42 -0400248 cves_unpatched.append(cve)
Brad Bishop6dbb3162019-11-25 09:41:34 -0500249 break
250
251 if not vulnerable:
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600252 bb.note("%s-%s is not vulnerable to %s" % (pn, real_pv, cve))
Brad Bishop6dbb3162019-11-25 09:41:34 -0500253 # TODO: not patched but not vulnerable
254 patched_cves.add(cve)
255
Brad Bishopf3fd2882019-06-21 08:06:37 -0400256 conn.close()
257
Andrew Geissler82c905d2020-04-13 13:39:40 -0500258 return (list(cve_whitelist), list(patched_cves), cves_unpatched)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600259
260def get_cve_info(d, cves):
261 """
Brad Bishop96ff1982019-08-19 13:50:42 -0400262 Get CVE information from the database.
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600263 """
264
Brad Bishop6dbb3162019-11-25 09:41:34 -0500265 import sqlite3
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600266
267 cve_data = {}
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000268 db_file = d.expand("file:${CVE_CHECK_DB_FILE}?mode=ro")
269 conn = sqlite3.connect(db_file, uri=True)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600270
Brad Bishop6dbb3162019-11-25 09:41:34 -0500271 for cve in cves:
272 for row in conn.execute("SELECT * FROM NVD WHERE ID IS ?", (cve,)):
273 cve_data[row[0]] = {}
274 cve_data[row[0]]["summary"] = row[1]
275 cve_data[row[0]]["scorev2"] = row[2]
276 cve_data[row[0]]["scorev3"] = row[3]
277 cve_data[row[0]]["modified"] = row[4]
278 cve_data[row[0]]["vector"] = row[5]
279
280 conn.close()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600281 return cve_data
282
Andrew Geissler82c905d2020-04-13 13:39:40 -0500283def cve_write_data(d, patched, unpatched, whitelisted, cve_data):
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600284 """
285 Write CVE information in WORKDIR; and to CVE_CHECK_DIR, and
286 CVE manifest if enabled.
287 """
288
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600289
Brad Bishop316dfdd2018-06-25 12:45:53 -0400290 cve_file = d.getVar("CVE_CHECK_LOG")
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600291 fdir_name = d.getVar("FILE_DIRNAME")
292 layer = fdir_name.split("/")[-3]
293
294 include_layers = d.getVar("CVE_CHECK_LAYER_INCLUDELIST").split()
295 exclude_layers = d.getVar("CVE_CHECK_LAYER_EXCLUDELIST").split()
296
297 if exclude_layers and layer in exclude_layers:
298 return
299
300 if include_layers and layer not in include_layers:
301 return
302
Patrick Williams213cb262021-08-07 19:21:33 -0500303 nvd_link = "https://nvd.nist.gov/vuln/detail/"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600304 write_string = ""
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500305 unpatched_cves = []
Brad Bishop316dfdd2018-06-25 12:45:53 -0400306 bb.utils.mkdirhier(os.path.dirname(cve_file))
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600307
308 for cve in sorted(cve_data):
Andrew Geisslerc3d88e42020-10-02 09:45:00 -0500309 is_patched = cve in patched
310 if is_patched and (d.getVar("CVE_CHECK_REPORT_PATCHED") != "1"):
311 continue
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600312 write_string += "LAYER: %s\n" % layer
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500313 write_string += "PACKAGE NAME: %s\n" % d.getVar("PN")
Andrew Geissler4ed12e12020-06-05 18:00:41 -0500314 write_string += "PACKAGE VERSION: %s%s\n" % (d.getVar("EXTENDPE"), d.getVar("PV"))
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600315 write_string += "CVE: %s\n" % cve
Andrew Geissler82c905d2020-04-13 13:39:40 -0500316 if cve in whitelisted:
317 write_string += "CVE STATUS: Whitelisted\n"
Andrew Geisslerc3d88e42020-10-02 09:45:00 -0500318 elif is_patched:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600319 write_string += "CVE STATUS: Patched\n"
320 else:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500321 unpatched_cves.append(cve)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600322 write_string += "CVE STATUS: Unpatched\n"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600323 write_string += "CVE SUMMARY: %s\n" % cve_data[cve]["summary"]
Brad Bishopf3fd2882019-06-21 08:06:37 -0400324 write_string += "CVSS v2 BASE SCORE: %s\n" % cve_data[cve]["scorev2"]
325 write_string += "CVSS v3 BASE SCORE: %s\n" % cve_data[cve]["scorev3"]
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600326 write_string += "VECTOR: %s\n" % cve_data[cve]["vector"]
327 write_string += "MORE INFORMATION: %s%s\n\n" % (nvd_link, cve)
328
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500329 if unpatched_cves:
330 bb.warn("Found unpatched CVE (%s), for more information check %s" % (" ".join(unpatched_cves),cve_file))
331
Andrew Geisslerc3d88e42020-10-02 09:45:00 -0500332 if write_string:
333 with open(cve_file, "w") as f:
334 bb.note("Writing file %s with CVE information" % cve_file)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600335 f.write(write_string)
336
Andrew Geisslerc3d88e42020-10-02 09:45:00 -0500337 if d.getVar("CVE_CHECK_COPY_FILES") == "1":
338 deploy_file = d.getVar("CVE_CHECK_RECIPE_FILE")
339 bb.utils.mkdirhier(os.path.dirname(deploy_file))
340 with open(deploy_file, "w") as f:
341 f.write(write_string)
Andrew Geisslerb7d28612020-07-24 16:15:54 -0500342
Andrew Geisslerc3d88e42020-10-02 09:45:00 -0500343 if d.getVar("CVE_CHECK_CREATE_MANIFEST") == "1":
344 cvelogpath = d.getVar("CVE_CHECK_SUMMARY_DIR")
345 bb.utils.mkdirhier(cvelogpath)
346
347 with open(d.getVar("CVE_CHECK_TMP_FILE"), "a") as f:
348 f.write("%s" % write_string)