summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoss Burton <ross.burton@arm.com>2023-06-23 13:32:47 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2023-06-27 16:23:40 +0100
commitcc28393285baf43ec52d77a6bacc52381524fd08 (patch)
tree173e1b39df3835d0e64521f5a9bf893ea92d58e4
parente08025fe4c66837db8c8ddce66e07aa135824316 (diff)
downloadpoky-cc28393285baf43ec52d77a6bacc52381524fd08.tar.gz
cve-update-db-native: remove
The replacement cve-update-nvd2-native is working, so we can remove the old recipe now. (From OE-Core rev: 17eb07885147a06bf7bdd43f7869fe4411be80a0) Signed-off-by: Ross Burton <ross.burton@arm.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/conf/distro/include/maintainers.inc1
-rw-r--r--meta/lib/oeqa/selftest/cases/distrodata.py2
-rw-r--r--meta/recipes-core/meta/cve-update-db-native.bb288
3 files changed, 1 insertions, 290 deletions
diff --git a/meta/conf/distro/include/maintainers.inc b/meta/conf/distro/include/maintainers.inc
index 9bb5c5205c..e27295a7cf 100644
--- a/meta/conf/distro/include/maintainers.inc
+++ b/meta/conf/distro/include/maintainers.inc
@@ -127,7 +127,6 @@ RECIPE_MAINTAINER:pn-cryptodev-module = "Robert Yang <liezhi.yang@windriver.com>
127RECIPE_MAINTAINER:pn-cryptodev-tests = "Robert Yang <liezhi.yang@windriver.com>" 127RECIPE_MAINTAINER:pn-cryptodev-tests = "Robert Yang <liezhi.yang@windriver.com>"
128RECIPE_MAINTAINER:pn-cups = "Chen Qi <Qi.Chen@windriver.com>" 128RECIPE_MAINTAINER:pn-cups = "Chen Qi <Qi.Chen@windriver.com>"
129RECIPE_MAINTAINER:pn-curl = "Robert Joslyn <robert.joslyn@redrectangle.org>" 129RECIPE_MAINTAINER:pn-curl = "Robert Joslyn <robert.joslyn@redrectangle.org>"
130RECIPE_MAINTAINER:pn-cve-update-db-native = "Ross Burton <ross.burton@arm.com>"
131RECIPE_MAINTAINER:pn-cve-update-nvd2-native = "Ross Burton <ross.burton@arm.com>" 130RECIPE_MAINTAINER:pn-cve-update-nvd2-native = "Ross Burton <ross.burton@arm.com>"
132RECIPE_MAINTAINER:pn-cwautomacros = "Ross Burton <ross.burton@arm.com>" 131RECIPE_MAINTAINER:pn-cwautomacros = "Ross Burton <ross.burton@arm.com>"
133RECIPE_MAINTAINER:pn-db = "Unassigned <unassigned@yoctoproject.org>" 132RECIPE_MAINTAINER:pn-db = "Unassigned <unassigned@yoctoproject.org>"
diff --git a/meta/lib/oeqa/selftest/cases/distrodata.py b/meta/lib/oeqa/selftest/cases/distrodata.py
index c83a3a7bd6..111bd3c9be 100644
--- a/meta/lib/oeqa/selftest/cases/distrodata.py
+++ b/meta/lib/oeqa/selftest/cases/distrodata.py
@@ -92,7 +92,7 @@ The following recipes do not have a DESCRIPTION. Please add an entry for DESCRIP
92 92
93 def is_maintainer_exception(entry): 93 def is_maintainer_exception(entry):
94 exceptions = ["musl", "newlib", "linux-yocto", "linux-dummy", "mesa-gl", "libgfortran", "libx11-compose-data", 94 exceptions = ["musl", "newlib", "linux-yocto", "linux-dummy", "mesa-gl", "libgfortran", "libx11-compose-data",
95 "cve-update-db-native","cve-update-nvd2-native",] 95 "cve-update-nvd2-native",]
96 for i in exceptions: 96 for i in exceptions:
97 if i in entry: 97 if i in entry:
98 return True 98 return True
diff --git a/meta/recipes-core/meta/cve-update-db-native.bb b/meta/recipes-core/meta/cve-update-db-native.bb
deleted file mode 100644
index 079f062f79..0000000000
--- a/meta/recipes-core/meta/cve-update-db-native.bb
+++ /dev/null
@@ -1,288 +0,0 @@
1SUMMARY = "Updates the NVD CVE database"
2LICENSE = "MIT"
3
4INHIBIT_DEFAULT_DEPS = "1"
5
6inherit native
7
8deltask do_unpack
9deltask do_patch
10deltask do_configure
11deltask do_compile
12deltask do_install
13deltask do_populate_sysroot
14
15NVDCVE_URL ?= "https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-"
16# CVE database update interval, in seconds. By default: once a day (24*60*60).
17# Use 0 to force the update
18# Use a negative value to skip the update
19CVE_DB_UPDATE_INTERVAL ?= "86400"
20
21# Timeout for blocking socket operations, such as the connection attempt.
22CVE_SOCKET_TIMEOUT ?= "60"
23
24CVE_DB_TEMP_FILE ?= "${CVE_CHECK_DB_DIR}/temp_nvdcve_1.1.db"
25
26python () {
27 if not bb.data.inherits_class("cve-check", d):
28 raise bb.parse.SkipRecipe("Skip recipe when cve-check class is not loaded.")
29}
30
31python do_fetch() {
32 """
33 Update NVD database with json data feed
34 """
35 import bb.utils
36 import bb.progress
37 import shutil
38
39 bb.utils.export_proxies(d)
40
41 db_file = d.getVar("CVE_CHECK_DB_FILE")
42 db_dir = os.path.dirname(db_file)
43 db_tmp_file = d.getVar("CVE_DB_TEMP_FILE")
44
45 cleanup_db_download(db_file, db_tmp_file)
46
47 # The NVD database changes once a day, so no need to update more frequently
48 # Allow the user to force-update
49 try:
50 import time
51 update_interval = int(d.getVar("CVE_DB_UPDATE_INTERVAL"))
52 if update_interval < 0:
53 bb.note("CVE database update skipped")
54 return
55 if time.time() - os.path.getmtime(db_file) < update_interval:
56 bb.debug(2, "Recently updated, skipping")
57 return
58
59 except OSError:
60 pass
61
62 bb.utils.mkdirhier(db_dir)
63 if os.path.exists(db_file):
64 shutil.copy2(db_file, db_tmp_file)
65
66 if update_db_file(db_tmp_file, d) == True:
67 # Update downloaded correctly, can swap files
68 shutil.move(db_tmp_file, db_file)
69 else:
70 # Update failed, do not modify the database
71 bb.note("CVE database update failed")
72 os.remove(db_tmp_file)
73}
74
75do_fetch[lockfiles] += "${CVE_CHECK_DB_FILE_LOCK}"
76do_fetch[file-checksums] = ""
77do_fetch[vardeps] = ""
78
79def cleanup_db_download(db_file, db_tmp_file):
80 """
81 Cleanup the download space from possible failed downloads
82 """
83
84 # Clean up the updates done on the main file
85 # Remove it only if a journal file exists - it means a complete re-download
86 if os.path.exists("{0}-journal".format(db_file)):
87 # If a journal is present the last update might have been interrupted. In that case,
88 # just wipe any leftovers and force the DB to be recreated.
89 os.remove("{0}-journal".format(db_file))
90
91 if os.path.exists(db_file):
92 os.remove(db_file)
93
94 # Clean-up the temporary file downloads, we can remove both journal
95 # and the temporary database
96 if os.path.exists("{0}-journal".format(db_tmp_file)):
97 # If a journal is present the last update might have been interrupted. In that case,
98 # just wipe any leftovers and force the DB to be recreated.
99 os.remove("{0}-journal".format(db_tmp_file))
100
101 if os.path.exists(db_tmp_file):
102 os.remove(db_tmp_file)
103
104def update_db_file(db_tmp_file, d):
105 """
106 Update the given database file
107 """
108 import bb.utils, bb.progress
109 from datetime import date
110 import urllib, gzip, sqlite3
111
112 YEAR_START = 2002
113 cve_socket_timeout = int(d.getVar("CVE_SOCKET_TIMEOUT"))
114
115 # Connect to database
116 conn = sqlite3.connect(db_tmp_file)
117 initialize_db(conn)
118
119 with bb.progress.ProgressHandler(d) as ph, open(os.path.join(d.getVar("TMPDIR"), 'cve_check'), 'a') as cve_f:
120 total_years = date.today().year + 1 - YEAR_START
121 for i, year in enumerate(range(YEAR_START, date.today().year + 1)):
122 bb.debug(2, "Updating %d" % year)
123 ph.update((float(i + 1) / total_years) * 100)
124 year_url = (d.getVar('NVDCVE_URL')) + str(year)
125 meta_url = year_url + ".meta"
126 json_url = year_url + ".json.gz"
127
128 # Retrieve meta last modified date
129 try:
130 response = urllib.request.urlopen(meta_url, timeout=cve_socket_timeout)
131 except urllib.error.URLError as e:
132 cve_f.write('Warning: CVE db update error, Unable to fetch CVE data.\n\n')
133 bb.warn("Failed to fetch CVE data (%s)" % e.reason)
134 return False
135
136 if response:
137 for l in response.read().decode("utf-8").splitlines():
138 key, value = l.split(":", 1)
139 if key == "lastModifiedDate":
140 last_modified = value
141 break
142 else:
143 bb.warn("Cannot parse CVE metadata, update failed")
144 return False
145
146 # Compare with current db last modified date
147 cursor = conn.execute("select DATE from META where YEAR = ?", (year,))
148 meta = cursor.fetchone()
149 cursor.close()
150
151 if not meta or meta[0] != last_modified:
152 bb.debug(2, "Updating entries")
153 # Clear products table entries corresponding to current year
154 conn.execute("delete from PRODUCTS where ID like ?", ('CVE-%d%%' % year,)).close()
155
156 # Update db with current year json file
157 try:
158 response = urllib.request.urlopen(json_url, timeout=cve_socket_timeout)
159 if response:
160 update_db(conn, gzip.decompress(response.read()).decode('utf-8'))
161 conn.execute("insert or replace into META values (?, ?)", [year, last_modified]).close()
162 except urllib.error.URLError as e:
163 cve_f.write('Warning: CVE db update error, CVE data is outdated.\n\n')
164 bb.warn("Cannot parse CVE data (%s), update failed" % e.reason)
165 return False
166 else:
167 bb.debug(2, "Already up to date (last modified %s)" % last_modified)
168 # Update success, set the date to cve_check file.
169 if year == date.today().year:
170 cve_f.write('CVE database update : %s\n\n' % date.today())
171
172 conn.commit()
173 conn.close()
174 return True
175
176def initialize_db(conn):
177 with conn:
178 c = conn.cursor()
179
180 c.execute("CREATE TABLE IF NOT EXISTS META (YEAR INTEGER UNIQUE, DATE TEXT)")
181
182 c.execute("CREATE TABLE IF NOT EXISTS NVD (ID TEXT UNIQUE, SUMMARY TEXT, \
183 SCOREV2 TEXT, SCOREV3 TEXT, MODIFIED INTEGER, VECTOR TEXT)")
184
185 c.execute("CREATE TABLE IF NOT EXISTS PRODUCTS (ID TEXT, \
186 VENDOR TEXT, PRODUCT TEXT, VERSION_START TEXT, OPERATOR_START TEXT, \
187 VERSION_END TEXT, OPERATOR_END TEXT)")
188 c.execute("CREATE INDEX IF NOT EXISTS PRODUCT_ID_IDX on PRODUCTS(ID);")
189
190 c.close()
191
192def parse_node_and_insert(conn, node, cveId):
193 # Parse children node if needed
194 for child in node.get('children', ()):
195 parse_node_and_insert(conn, child, cveId)
196
197 def cpe_generator():
198 for cpe in node.get('cpe_match', ()):
199 if not cpe['vulnerable']:
200 return
201 cpe23 = cpe.get('cpe23Uri')
202 if not cpe23:
203 return
204 cpe23 = cpe23.split(':')
205 if len(cpe23) < 6:
206 return
207 vendor = cpe23[3]
208 product = cpe23[4]
209 version = cpe23[5]
210
211 if cpe23[6] == '*' or cpe23[6] == '-':
212 version_suffix = ""
213 else:
214 version_suffix = "_" + cpe23[6]
215
216 if version != '*' and version != '-':
217 # Version is defined, this is a '=' match
218 yield [cveId, vendor, product, version + version_suffix, '=', '', '']
219 elif version == '-':
220 # no version information is available
221 yield [cveId, vendor, product, version, '', '', '']
222 else:
223 # Parse start version, end version and operators
224 op_start = ''
225 op_end = ''
226 v_start = ''
227 v_end = ''
228
229 if 'versionStartIncluding' in cpe:
230 op_start = '>='
231 v_start = cpe['versionStartIncluding']
232
233 if 'versionStartExcluding' in cpe:
234 op_start = '>'
235 v_start = cpe['versionStartExcluding']
236
237 if 'versionEndIncluding' in cpe:
238 op_end = '<='
239 v_end = cpe['versionEndIncluding']
240
241 if 'versionEndExcluding' in cpe:
242 op_end = '<'
243 v_end = cpe['versionEndExcluding']
244
245 if op_start or op_end or v_start or v_end:
246 yield [cveId, vendor, product, v_start, op_start, v_end, op_end]
247 else:
248 # This is no version information, expressed differently.
249 # Save processing by representing as -.
250 yield [cveId, vendor, product, '-', '', '', '']
251
252 conn.executemany("insert into PRODUCTS values (?, ?, ?, ?, ?, ?, ?)", cpe_generator()).close()
253
254def update_db(conn, jsondata):
255 import json
256 root = json.loads(jsondata)
257
258 for elt in root['CVE_Items']:
259 if not elt['impact']:
260 continue
261
262 accessVector = None
263 cveId = elt['cve']['CVE_data_meta']['ID']
264 cveDesc = elt['cve']['description']['description_data'][0]['value']
265 date = elt['lastModifiedDate']
266 try:
267 accessVector = elt['impact']['baseMetricV2']['cvssV2']['accessVector']
268 cvssv2 = elt['impact']['baseMetricV2']['cvssV2']['baseScore']
269 except KeyError:
270 cvssv2 = 0.0
271 try:
272 accessVector = accessVector or elt['impact']['baseMetricV3']['cvssV3']['attackVector']
273 cvssv3 = elt['impact']['baseMetricV3']['cvssV3']['baseScore']
274 except KeyError:
275 accessVector = accessVector or "UNKNOWN"
276 cvssv3 = 0.0
277
278 conn.execute("insert or replace into NVD values (?, ?, ?, ?, ?, ?)",
279 [cveId, cveDesc, cvssv2, cvssv3, date, accessVector]).close()
280
281 configurations = elt['configurations']['nodes']
282 for config in configurations:
283 parse_node_and_insert(conn, config, cveId)
284
285
286do_fetch[nostamp] = "1"
287
288EXCLUDE_FROM_WORLD = "1"