From b4e374903e5e22dddfce8be0c4162fa7dcd20808 Mon Sep 17 00:00:00 2001 From: Eneas U de Queiroz Date: Wed, 6 Sep 2023 14:20:53 -0300 Subject: [PATCH] Skip bpf_jit_harden sysctl if BPF_JIT is not set Also, switch the test for root sysctl to the 'kernel.cad_pid' symbol. Signed-off-by: Eneas U de Queiroz --- kernel_hardening_checker/__init__.py | 4 ++-- kernel_hardening_checker/checks.py | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/kernel_hardening_checker/__init__.py b/kernel_hardening_checker/__init__.py index 89c24f7..161fc94 100644 --- a/kernel_hardening_checker/__init__.py +++ b/kernel_hardening_checker/__init__.py @@ -219,8 +219,8 @@ def parse_sysctl_file(mode, parsed_options, fname): sys.exit(f'[!] ERROR: {fname} doesn\'t look like a sysctl output file, please try `sudo sysctl -a > {fname}`') # let's check the presence of a sysctl option available for root - if 'net.core.bpf_jit_harden' not in parsed_options and mode != 'json': - print(f'[!] WARNING: sysctl option "net.core.bpf_jit_harden" available for root is not found in {fname}, please try `sudo sysctl -a > {fname}`') + if 'kernel.cad_pid' not in parsed_options and mode != 'json': + print(f'[!] WARNING: sysctl option "kernel.cad_pid" available for root is not found in {fname}, please try `sudo sysctl -a > {fname}`') def main(): diff --git a/kernel_hardening_checker/checks.py b/kernel_hardening_checker/checks.py index 47036d6..ed83541 100644 --- a/kernel_hardening_checker/checks.py +++ b/kernel_hardening_checker/checks.py @@ -663,7 +663,10 @@ def add_sysctl_checks(l, _arch): # Calling the SysctlCheck class constructor: # SysctlCheck(reason, decision, name, expected) - l += [SysctlCheck('self_protection', 'kspp', 'net.core.bpf_jit_harden', '2')] + l += [OR(SysctlCheck('self_protection', 'kspp', 'net.core.bpf_jit_harden', '2'), + AND(KconfigCheck('cut_attack_surface', 'kspp', 'BPF_JIT', 'is not set'), + # use an omnipresent config symbol to see if we have a config file to check BPF_JIT. + KconfigCheck('cut_attack_surface', 'kspp', 'DEFAULT_INIT', 'is present')))] l += [SysctlCheck('cut_attack_surface', 'kspp', 'kernel.dmesg_restrict', '1')] l += [SysctlCheck('cut_attack_surface', 'kspp', 'kernel.perf_event_paranoid', '3')] # with a custom patch, see https://lwn.net/Articles/696216/ -- 2.31.1