diff options
Diffstat (limited to 'scripts/contrib/improve_kernel_cve_report.py')
| -rwxr-xr-x | scripts/contrib/improve_kernel_cve_report.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/scripts/contrib/improve_kernel_cve_report.py b/scripts/contrib/improve_kernel_cve_report.py index 5c39df05a5..3a15b1ed26 100755 --- a/scripts/contrib/improve_kernel_cve_report.py +++ b/scripts/contrib/improve_kernel_cve_report.py | |||
| @@ -236,6 +236,26 @@ def read_spdx3(spdx): | |||
| 236 | cfiles.add(filename) | 236 | cfiles.add(filename) |
| 237 | return cfiles | 237 | return cfiles |
| 238 | 238 | ||
| 239 | def read_debugsources(file_path): | ||
| 240 | ''' | ||
| 241 | Read zstd file from pkgdata to extract sources | ||
| 242 | ''' | ||
| 243 | import zstandard as zstd | ||
| 244 | import itertools | ||
| 245 | # Decompress the .zst file | ||
| 246 | cfiles = set() | ||
| 247 | with open(file_path, 'rb') as fh: | ||
| 248 | dctx = zstd.ZstdDecompressor() | ||
| 249 | with dctx.stream_reader(fh) as reader: | ||
| 250 | decompressed_bytes = reader.read() | ||
| 251 | json_data = json.loads(decompressed_bytes) | ||
| 252 | # We need to remove one level from the debug sources | ||
| 253 | for source_list in json_data.values(): | ||
| 254 | for source in source_list: | ||
| 255 | src = source.split("/",1)[1] | ||
| 256 | cfiles.add(src) | ||
| 257 | return cfiles | ||
| 258 | |||
| 239 | def check_kernel_compiled_files(compiled_files, cve_info): | 259 | def check_kernel_compiled_files(compiled_files, cve_info): |
| 240 | """ | 260 | """ |
| 241 | Return if a CVE affected us depending on compiled files | 261 | Return if a CVE affected us depending on compiled files |
| @@ -373,6 +393,10 @@ def main(): | |||
| 373 | help="SPDX2/3 for the kernel. Needs to include compiled sources", | 393 | help="SPDX2/3 for the kernel. Needs to include compiled sources", |
| 374 | ) | 394 | ) |
| 375 | parser.add_argument( | 395 | parser.add_argument( |
| 396 | "--debug-sources-file", | ||
| 397 | help="Debug sources zstd file generated from Yocto", | ||
| 398 | ) | ||
| 399 | parser.add_argument( | ||
| 376 | "--datadir", | 400 | "--datadir", |
| 377 | type=pathlib.Path, | 401 | type=pathlib.Path, |
| 378 | help="Directory where CVE data is", | 402 | help="Directory where CVE data is", |
| @@ -415,6 +439,9 @@ def main(): | |||
| 415 | if args.spdx: | 439 | if args.spdx: |
| 416 | compiled_files = read_spdx(args.spdx) | 440 | compiled_files = read_spdx(args.spdx) |
| 417 | logging.info("Total compiled files %d", len(compiled_files)) | 441 | logging.info("Total compiled files %d", len(compiled_files)) |
| 442 | if args.debug_sources_file: | ||
| 443 | compiled_files = read_debugsources(args.debug_sources_file) | ||
| 444 | logging.info("Total compiled files %d", len(compiled_files)) | ||
| 418 | 445 | ||
| 419 | if args.old_cve_report: | 446 | if args.old_cve_report: |
| 420 | with open(args.old_cve_report, encoding='ISO-8859-1') as f: | 447 | with open(args.old_cve_report, encoding='ISO-8859-1') as f: |
