X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;ds=inline;f=kernel_hardening_checker%2F__init__.py;h=043dae8c8362b446e9a25e9291d4e095c7e85d9d;hb=HEAD;hp=5893fab542ddd3e16e1b22a55f86e5e21e1ab258;hpb=8d6d939d66cd51f63514837ec6d4c7839ddc01b7;p=kconfig-hardened-check.git diff --git a/kernel_hardening_checker/__init__.py b/kernel_hardening_checker/__init__.py old mode 100644 new mode 100755 index 5893fab..6f551e5 --- a/kernel_hardening_checker/__init__.py +++ b/kernel_hardening_checker/__init__.py @@ -3,7 +3,8 @@ """ This tool is for checking the security hardening options of the Linux kernel. -Author: Alexander Popov +SPDX-FileCopyrightText: Alexander Popov +SPDX-License-Identifier: GPL-3.0-only This module performs input/output. """ @@ -116,12 +117,12 @@ def print_checklist(mode: StrOrNone, checklist: List[ChecklistObjType], with_res ok_count += 1 if mode == 'show_fail': continue - elif opt.result.startswith('FAIL'): + else: + assert(opt.result.startswith('FAIL')), \ + f'unexpected result "{opt.result}" of {opt.name} check' fail_count += 1 if mode == 'show_ok': continue - else: - assert(False), f'unexpected result "{opt.result}" of {opt.name} check' opt.table_print(mode, with_results) print() if mode == 'verbose': @@ -141,7 +142,7 @@ def print_checklist(mode: StrOrNone, checklist: List[ChecklistObjType], with_res def parse_kconfig_file(_mode: StrOrNone, parsed_options: Dict[str, str], fname: str) -> None: with _open(fname) as f: - opt_is_on = re.compile(r"CONFIG_[a-zA-Z0-9_]+=.+$") + opt_is_on = re.compile(r"CONFIG_[a-zA-Z0-9_]+=.*$") opt_is_off = re.compile(r"# CONFIG_[a-zA-Z0-9_]+ is not set$") for line in f.readlines(): @@ -153,6 +154,8 @@ def parse_kconfig_file(_mode: StrOrNone, parsed_options: Dict[str, str], fname: option, value = line.split('=', 1) if value == 'is not set': sys.exit(f'[!] ERROR: bad enabled Kconfig option "{line}"') + if value == '': + print(f'[!] WARNING: found strange Kconfig option {option} with empty value') elif opt_is_off.match(line): option, value = line[2:].split(' ', 1) assert(value == 'is not set'), \ @@ -164,7 +167,7 @@ def parse_kconfig_file(_mode: StrOrNone, parsed_options: Dict[str, str], fname: sys.exit(f'[!] ERROR: Kconfig option "{line}" is found multiple times') if option: - assert(value), f'unexpected empty value for {option}' + assert(value is not None), f'unexpected None value for {option}' parsed_options[option] = value