X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=kconfig_hardened_check%2F__init__.py;h=48df2fc9c13dca179f876e0bf1cc44a41510146c;hb=8d3cce0b652b9cb8fb74ef01fc2cc16b696fc51c;hp=d3fc58dcfa725f055b90a3ea633925cba2a8497e;hpb=4e0065c8baf8d40c733f7f4c5c920c07b93c55b6;p=kconfig-hardened-check.git diff --git a/kconfig_hardened_check/__init__.py b/kconfig_hardened_check/__init__.py index d3fc58d..48df2fc 100644 --- a/kconfig_hardened_check/__init__.py +++ b/kconfig_hardened_check/__init__.py @@ -10,11 +10,6 @@ # Please don't cry if my Python code looks like C. # # -# Hardware tag-based KASAN with arm64 Memory Tagging Extension (MTE): -# kasan=on -# kasan.stacktrace=off -# kasan.fault=panic -# # N.B. Hardening sysctls: # kernel.kptr_restrict=2 (or 1?) # kernel.dmesg_restrict=1 (also see the kconfig option) @@ -71,7 +66,7 @@ class OptCheck: 'invalid expected value "{}" for "{}" check (1)'.format(expected, name) val_len = len(expected.split()) if val_len == 3: - assert(expected == 'is not set' or expected == 'is not off'), \ + assert(expected in ('is not set', 'is not off')), \ 'invalid expected value "{}" for "{}" check (2)'.format(expected, name) elif val_len == 2: assert(expected == 'is present'), \ @@ -271,7 +266,7 @@ class AND(ComplexOptCheck): self.result = 'FAIL: {} is not "{}"'.format(opt.name, opt.expected) elif opt.result == 'FAIL: is not present': self.result = 'FAIL: {} is not present'.format(opt.name) - elif opt.result == 'FAIL: is off' or opt.result == 'FAIL: is off, "0"': + elif opt.result in ('FAIL: is off', 'FAIL: is off, "0"'): self.result = 'FAIL: {} is off'.format(opt.name) elif opt.result == 'FAIL: is off, not found': self.result = 'FAIL: {} is off, not found'.format(opt.name) @@ -525,7 +520,7 @@ def add_kconfig_checks(l, arch): if arch == 'ARM64': l += [KconfigCheck('self_protection', 'kspp', 'ARM64_SW_TTBR0_PAN', 'y')] l += [KconfigCheck('self_protection', 'kspp', 'SHADOW_CALL_STACK', 'y')] - l += [KconfigCheck('self_protection', 'kspp', 'KASAN_HW_TAGS', 'y')] + l += [KconfigCheck('self_protection', 'kspp', 'KASAN_HW_TAGS', 'y')] # see also: kasan=on, kasan.stacktrace=off, kasan.fault=panic if arch == 'X86_32': l += [KconfigCheck('self_protection', 'kspp', 'PAGE_TABLE_ISOLATION', 'y')] l += [KconfigCheck('self_protection', 'kspp', 'HIGHMEM64G', 'y')] @@ -640,6 +635,8 @@ def add_kconfig_checks(l, arch): l += [KconfigCheck('cut_attack_surface', 'maintainer', 'VT', 'is not set')] # recommended by Daniel Vetter in /issues/38 l += [KconfigCheck('cut_attack_surface', 'maintainer', 'BLK_DEV_FD', 'is not set')] # recommended by Denis Efremov in /pull/54 l += [KconfigCheck('cut_attack_surface', 'maintainer', 'BLK_DEV_FD_RAWCMD', 'is not set')] # recommended by Denis Efremov in /pull/62 + l += [KconfigCheck('cut_attack_surface', 'maintainer', 'NOUVEAU_LEGACY_CTX_SUPPORT', 'is not set')] + # recommended by Dave Airlie in kernel commit b30a43ac7132cdda # 'cut_attack_surface', 'clipos' l += [KconfigCheck('cut_attack_surface', 'clipos', 'STAGING', 'is not set')] @@ -671,6 +668,7 @@ def add_kconfig_checks(l, arch): l += [KconfigCheck('cut_attack_surface', 'my', 'VIDEO_VIVID', 'is not set')] l += [KconfigCheck('cut_attack_surface', 'my', 'INPUT_EVBUG', 'is not set')] # Can be used as a keylogger l += [KconfigCheck('cut_attack_surface', 'my', 'KGDB', 'is not set')] + l += [KconfigCheck('cut_attack_surface', 'my', 'AIO', 'is not set')] l += [OR(KconfigCheck('cut_attack_surface', 'my', 'TRIM_UNUSED_KSYMS', 'y'), modules_not_set)] @@ -744,6 +742,8 @@ def add_cmdline_checks(l, arch): CmdlineCheck('self_protection', 'defconfig', 'retbleed', 'is not set'))] l += [OR(CmdlineCheck('self_protection', 'defconfig', 'kpti', 'is not off'), CmdlineCheck('self_protection', 'defconfig', 'kpti', 'is not set'))] + l += [OR(CmdlineCheck('self_protection', 'defconfig', 'kvm.nx_huge_pages', 'is not off'), + CmdlineCheck('self_protection', 'defconfig', 'kvm.nx_huge_pages', 'is not set'))] if arch == 'ARM64': l += [OR(CmdlineCheck('self_protection', 'defconfig', 'ssbd', 'kernel'), CmdlineCheck('self_protection', 'my', 'ssbd', 'force-on'), @@ -768,7 +768,8 @@ def add_cmdline_checks(l, arch): CmdlineCheck('self_protection', 'kspp', 'slub_debug', 'P')))] l += [OR(CmdlineCheck('self_protection', 'kspp', 'slab_nomerge', 'is present'), AND(KconfigCheck('self_protection', 'clipos', 'SLAB_MERGE_DEFAULT', 'is not set'), - CmdlineCheck('self_protection', 'kspp', 'slab_merge', 'is not set')))] + CmdlineCheck('self_protection', 'kspp', 'slab_merge', 'is not set'), + CmdlineCheck('self_protection', 'clipos', 'slub_merge', 'is not set')))] l += [OR(CmdlineCheck('self_protection', 'kspp', 'iommu.strict', '1'), AND(KconfigCheck('self_protection', 'kspp', 'IOMMU_DEFAULT_DMA_STRICT', 'y'), CmdlineCheck('self_protection', 'kspp', 'iommu.strict', 'is not set')))] @@ -1110,7 +1111,8 @@ def main(): if mode == 'verbose': # print the parsed options without the checks (for debugging) all_parsed_options = parsed_kconfig_options # assignment does not copy - all_parsed_options.update(parsed_cmdline_options) + if args.cmdline: + all_parsed_options.update(parsed_cmdline_options) print_unknown_options(config_checklist, all_parsed_options) # finally print the results