Skip to content

Commit

Permalink
parsing CONFIG_LSM option implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
d1sgr4c3 committed Nov 23, 2024
1 parent 8aa1595 commit 1815e42
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion kernel_hardening_checker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ def main() -> None:
add_kconfig_checks(config_checklist, arch)
print(f'CONFIG_{arch}=y') # the Kconfig fragment should describe the microarchitecture
for opt in config_checklist:
if opt.name in ('CONFIG_ARCH_MMAP_RND_BITS', 'CONFIG_ARCH_MMAP_RND_COMPAT_BITS'):
if opt.name in ('CONFIG_ARCH_MMAP_RND_BITS', 'CONFIG_ARCH_MMAP_RND_COMPAT_BITS', 'CONFIG_LSM'):
continue # don't add Kconfig options with a value that needs refinement
if opt.expected == 'is not off':
continue # don't add Kconfig options without explicitly recommended values
Expand Down
3 changes: 3 additions & 0 deletions kernel_hardening_checker/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ def add_kconfig_checks(l: List[ChecklistObjType], arch: str) -> None:
l += [OR(KconfigCheck('self_protection', 'kspp', 'UBSAN_SANITIZE_ALL', 'y'),
AND(ubsan_bounds_is_set,
VersionCheck((6, 9, 0))))] # UBSAN_SANITIZE_ALL was enabled by default in UBSAN in v6.9
l += [KconfigCheck('self_protection', 'kspp', 'LSM', '*landlock*')]
l += [KconfigCheck('self_protection', 'kspp', 'LSM', '*lockdown*')]
l += [KconfigCheck('self_protection', 'kspp', 'LSM', '*yama*')]
if arch in ('X86_64', 'ARM64', 'X86_32'):
stackleak_is_set = KconfigCheck('self_protection', 'kspp', 'GCC_PLUGIN_STACKLEAK', 'y')
l += [AND(stackleak_is_set,
Expand Down
8 changes: 8 additions & 0 deletions kernel_hardening_checker/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ def check(self) -> None:
else:
self.result = f'FAIL: "{self.state}"'

# handle checks, provided with list()
if self.expected.startswith('*') and self.state is not None:
print(self.state)
if self.expected.strip('*') in list(self.state.strip('\"').split(',')):
self.result = 'OK'
else:
self.result = f'FAIL: "{self.state}"'

def table_print(self, _mode: StrOrNone, with_results: bool) -> None:
print(f'{self.name:<40}|{self.opt_type:^7}|{self.expected:^12}|{self.decision:^10}|{self.reason:^18}', end='')
if with_results:
Expand Down

0 comments on commit 1815e42

Please sign in to comment.