Skip bpf_jit_harden sysctl if BPF_JIT is not set
authorEneas U de Queiroz <cotequeiroz@gmail.com>
Wed, 6 Sep 2023 17:20:53 +0000 (14:20 -0300)
committerAlexander Popov <alex.popov@linux.com>
Thu, 2 May 2024 09:18:14 +0000 (12:18 +0300)
Also, switch the test for root sysctl to the 'kernel.cad_pid' symbol.

Signed-off-by: Eneas U de Queiroz <cotequeiroz@gmail.com>
kernel_hardening_checker/__init__.py
kernel_hardening_checker/checks.py

index 89c24f71e44fbf87f6e128c67fa4608c77906fb5..161fc9411fe1c79fc07555c0854cc60589c137a7 100644 (file)
@@ -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():
index 47036d60dc4faaec92da80067ac26626b8f4d9f5..ed8354181699c849ab8fc8f5f2ba56bfebe1dabc 100644 (file)
@@ -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/