Merge ~litios/ubuntu-cve-tracker:oval/usn-wrong-cve-tags into ubuntu-cve-tracker:master

Proposed by David Fernandez Gonzalez
Status: Work in progress
Proposed branch: ~litios/ubuntu-cve-tracker:oval/usn-wrong-cve-tags
Merge into: ubuntu-cve-tracker:master
Diff against target: 72 lines (+28/-6)
1 file modified
scripts/oval_lib.py (+28/-6)
Reviewer Review Type Date Requested Status
Eduardo Barretto Pending
Review via email: mp+460034@code.launchpad.net

Description of the change

Current USN OVAL cannot detect if a CVE applied to the release.

This creates several problems:

1. Wrong information about the fixed version. If CVE was fixed in a different USN but CVE and package show up in another USN, that USN will also claim it fixed the CVE (example: USN-3679-1)

2. If CVE doesn't apply to the release, it will still appear in references and cve tags.

-------

Function cve_applies_release was created to fix this problem:

* CVE will only be added if:
  1. Status for that CVE is released in that release and package.
  2. The source version mentioned in the USN matches the one in the CVE.

* If after that there are no CVEs that apply, don't generate that USN OVAL information.

To post a comment you must log in.
Revision history for this message
Eduardo Barretto (ebarretto) wrote :

I'm changing this to work in progress as discussed with David.
We found many corner cases and we are trying to solve it in another approach.
we will update this PR whenever we have a better solution

Unmerged commits

6fbc218... by David Fernandez Gonzalez

[OVAL] USN: if the USN doesn't have any valid CVEs, don't add it

Signed-off-by: David Fernandez Gonzalez <email address hidden>

In progress
[WAITING] unit-tests:0 (build)
[WAITING] check-cves:0 (build)
12 of 2 results
a10ee05... by David Fernandez Gonzalez

[OVAL] USN: only get CVE if it was fixed in the USN

Signed-off-by: David Fernandez Gonzalez <email address hidden>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/scripts/oval_lib.py b/scripts/oval_lib.py
2index b30a987..bb0c37c 100644
3--- a/scripts/oval_lib.py
4+++ b/scripts/oval_lib.py
5@@ -2094,7 +2094,9 @@ class OvalGeneratorUSN():
6
7 # TODO: xml lib
8 def create_usn_definition(self, usn_object, usn_number, id_base, test_refs, cve_dir, instructions):
9- urls, cves_info = self.format_cves_info(usn_object['cves'], cve_dir)
10+ urls, cves_info = self.get_cves_info(usn_object['cves'], cve_dir, usn_object)
11+ if not cves_info: return None
12+
13 cve_references, cve_tags = self.create_cves_elements(cves_info)
14 bug_references = self.create_bug_references(urls)
15
16@@ -2437,7 +2439,8 @@ class OvalGeneratorUSN():
17 'CVSS': cve_object['CVSS'],
18 'References': references.split('\n'),
19 'CVE_URL': self.cve_base_url.format(cve),
20- 'MITRE_URL': self.mitre_base_url.format(cve)
21+ 'MITRE_URL': self.mitre_base_url.format(cve),
22+ 'Packages': cve_object['pkgs']
23 }
24
25 return cve_info
26@@ -2457,16 +2460,33 @@ class OvalGeneratorUSN():
27
28 return (urls, _cves)
29
30- def format_cves_info(self, cves, cve_dir):
31+ def cve_applies_release(self, cve, usn_obj):
32+ pkg_versions = {}
33+ for package_name in cve['Packages']:
34+ package = cve['Packages'][package_name]
35+ if self.release_codename in package and \
36+ package[self.release_codename][0] == 'released':
37+ pkg_versions[package_name] = package[self.release_codename][1]
38+
39+ applies = False
40+ for package_name in usn_obj['releases'][self.release_codename]['sources']:
41+ pkg_fixed_info = usn_obj['releases'][self.release_codename]['sources'][package_name]
42+ if package_name in pkg_versions and \
43+ pkg_fixed_info['version'] == pkg_versions[package_name]:
44+ applies = True
45+
46+ return applies
47+
48+ def get_cves_info(self, cves, cve_dir, usn_obj):
49 urls, cves = self.filter_cves(cves)
50 cves_info = []
51 for cve in cves:
52 # ignore empty CVE entries
53 if len(cve) == 0:
54 continue
55- res = self.get_cve_info_from_file(cve, cve_dir)
56- if res:
57- cves_info.append(res)
58+ cve_info = self.get_cve_info_from_file(cve, cve_dir)
59+ if cve_info and self.cve_applies_release(cve_info, usn_obj):
60+ cves_info.append(cve_info)
61
62 return urls, cves_info
63
64@@ -2578,6 +2598,8 @@ class OvalGeneratorUSN():
65 # Only need one definition, but if multiple versions of binary pkgs,
66 # then may need several test, object, state and var
67 usn_def = self.create_usn_definition(usn_object, usn_number, id_base, test_refs, cve_dir, instructions)
68+ if not usn_def: return
69+
70 self.oval_structure['definition'].write(usn_def)
71
72 for test_ref in test_refs:

Subscribers

People subscribed via source and target branches