9 echo "Beginning of the functional tests"
11 echo ">>>>> get help <<<<<"
12 coverage run -a --branch bin/kernel-hardening-checker
13 coverage run -a --branch bin/kernel-hardening-checker -h
15 echo ">>>>> get version <<<<<"
16 coverage run -a --branch bin/kernel-hardening-checker --version
18 echo ">>>>> print the security hardening recommendations <<<<<"
19 coverage run -a --branch bin/kernel-hardening-checker -p X86_64
20 coverage run -a --branch bin/kernel-hardening-checker -p X86_64 -m verbose
21 coverage run -a --branch bin/kernel-hardening-checker -p X86_64 -m json
23 coverage run -a --branch bin/kernel-hardening-checker -p X86_32
24 coverage run -a --branch bin/kernel-hardening-checker -p X86_32 -m verbose
25 coverage run -a --branch bin/kernel-hardening-checker -p X86_32 -m json
27 coverage run -a --branch bin/kernel-hardening-checker -p ARM64
28 coverage run -a --branch bin/kernel-hardening-checker -p ARM64 -m verbose
29 coverage run -a --branch bin/kernel-hardening-checker -p ARM64 -m json
31 coverage run -a --branch bin/kernel-hardening-checker -p ARM
32 coverage run -a --branch bin/kernel-hardening-checker -p ARM -m verbose
33 coverage run -a --branch bin/kernel-hardening-checker -p ARM -m json
35 echo ">>>>> generate the Kconfig fragment <<<<<"
36 coverage run -a --branch bin/kernel-hardening-checker -g X86_64
37 coverage run -a --branch bin/kernel-hardening-checker -g X86_32
38 coverage run -a --branch bin/kernel-hardening-checker -g ARM64
39 coverage run -a --branch bin/kernel-hardening-checker -g ARM
41 echo ">>>>> check the example kconfig files, cmdline, and sysctl <<<<<"
43 echo "l1tf=off mds=full mitigations=off randomize_kstack_offset=on retbleed=0 iommu.passthrough=0" > ./cmdline_example
45 sysctl -a > /tmp/sysctls
46 CONFIG_DIR=`find . -name config_files`
47 SYSCTL_EXAMPLE=$CONFIG_DIR/distros/example_sysctls.txt
48 KCONFIGS=`find $CONFIG_DIR -type f | grep -e "\.config" -e "\.gz"`
52 COUNT=$(expr $COUNT + 1)
53 echo "\n>>>>> checking kconfig number $COUNT <<<<<"
54 coverage run -a --branch bin/kernel-hardening-checker -c $C
55 coverage run -a --branch bin/kernel-hardening-checker -c $C -m verbose > /dev/null
56 coverage run -a --branch bin/kernel-hardening-checker -c $C -l /proc/cmdline
57 coverage run -a --branch bin/kernel-hardening-checker -c $C -s /tmp/sysctls
58 coverage run -a --branch bin/kernel-hardening-checker -c $C -l ./cmdline_example -s $SYSCTL_EXAMPLE
59 coverage run -a --branch bin/kernel-hardening-checker -c $C -l ./cmdline_example -s $SYSCTL_EXAMPLE -m verbose > /dev/null
60 coverage run -a --branch bin/kernel-hardening-checker -c $C -l ./cmdline_example -s $SYSCTL_EXAMPLE -m json
61 coverage run -a --branch bin/kernel-hardening-checker -c $C -l ./cmdline_example -s $SYSCTL_EXAMPLE -m show_ok
62 coverage run -a --branch bin/kernel-hardening-checker -c $C -l ./cmdline_example -s $SYSCTL_EXAMPLE -m show_fail
64 echo "\n>>>>> have checked $COUNT kconfigs <<<<<"
66 echo ">>>>> check sysctl separately <<<<<"
67 coverage run -a --branch bin/kernel-hardening-checker -s $SYSCTL_EXAMPLE
68 coverage run -a --branch bin/kernel-hardening-checker -s $SYSCTL_EXAMPLE -m verbose > /dev/null
69 coverage run -a --branch bin/kernel-hardening-checker -s $SYSCTL_EXAMPLE -m json
70 coverage run -a --branch bin/kernel-hardening-checker -s $SYSCTL_EXAMPLE -m show_ok
71 coverage run -a --branch bin/kernel-hardening-checker -s $SYSCTL_EXAMPLE -m show_fail
73 echo "Collect coverage for error handling"
75 echo ">>>>> -c and -p together <<<<<"
76 coverage run -a --branch bin/kernel-hardening-checker -p X86_64 -c kernel_hardening_checker/config_files/distros/fedora_34.config && exit 1
78 echo ">>>>> -c and -g together <<<<<"
79 coverage run -a --branch bin/kernel-hardening-checker -g X86_64 -c kernel_hardening_checker/config_files/distros/fedora_34.config && exit 1
81 echo ">>>>> -l without -c <<<<<"
82 coverage run -a --branch bin/kernel-hardening-checker -l /proc/cmdline && exit 1
84 echo ">>>>> -s and -p together <<<<<"
85 coverage run -a --branch bin/kernel-hardening-checker -p X86_64 -s $SYSCTL_EXAMPLE && exit 1
87 echo ">>>>> -s and -g together <<<<<"
88 coverage run -a --branch bin/kernel-hardening-checker -g X86_64 -s $SYSCTL_EXAMPLE && exit 1
90 echo ">>>>> -p and -g together <<<<<"
91 coverage run -a --branch bin/kernel-hardening-checker -p X86_64 -g X86_64 && exit 1
93 echo ">>>>> wrong modes for -p <<<<<"
94 coverage run -a --branch bin/kernel-hardening-checker -p X86_64 -m show_ok && exit 1
95 coverage run -a --branch bin/kernel-hardening-checker -p X86_64 -m show_fail && exit 1
97 echo ">>>>> wrong mode for -g <<<<<"
98 coverage run -a --branch bin/kernel-hardening-checker -g X86_64 -m show_ok && exit 1
100 cp kernel_hardening_checker/config_files/distros/fedora_34.config ./test.config
102 echo ">>>>> no kernel version <<<<<"
103 sed '3d' test.config > error.config
104 coverage run -a --branch bin/kernel-hardening-checker -c error.config && exit 1
106 echo ">>>>> strange kernel version string <<<<<"
107 sed '3 s/5./version 5./' test.config > error.config
108 coverage run -a --branch bin/kernel-hardening-checker -c error.config && exit 1
110 echo ">>>>> no arch <<<<<"
111 sed '305d' test.config > error.config
112 coverage run -a --branch bin/kernel-hardening-checker -c error.config && exit 1
114 echo ">>>>> more than one arch <<<<<"
115 cp test.config error.config
116 echo 'CONFIG_ARM64=y' >> error.config
117 coverage run -a --branch bin/kernel-hardening-checker -c error.config && exit 1
119 echo ">>>>> invalid enabled kconfig option <<<<<"
120 cp test.config error.config
121 echo 'CONFIG_FOO=is not set' >> error.config
122 coverage run -a --branch bin/kernel-hardening-checker -c error.config && exit 1
124 echo ">>>>> one config option multiple times <<<<<"
125 cp test.config error.config
126 echo 'CONFIG_BUG=y' >> error.config
127 coverage run -a --branch bin/kernel-hardening-checker -c error.config && exit 1
129 echo ">>>>> invalid compiler versions <<<<<"
130 cp test.config error.config
131 sed '8 s/CONFIG_CLANG_VERSION=0/CONFIG_CLANG_VERSION=120000/' test.config > error.config
132 coverage run -a --branch bin/kernel-hardening-checker -c error.config && exit 1
134 echo ">>>>> unexpected line in the kconfig file <<<<<"
135 cp test.config error.config
136 echo 'some strange line' >> error.config
137 coverage run -a --branch bin/kernel-hardening-checker -c error.config && exit 1
139 echo ">>>>> multi-line cmdline file <<<<<"
140 echo 'hey man 1' > cmdline
141 echo 'hey man 2' >> cmdline
142 coverage run -a --branch bin/kernel-hardening-checker -c test.config -l cmdline && exit 1
144 echo ">>>>> unexpected line in the sysctl file <<<<<"
145 cp $SYSCTL_EXAMPLE error_sysctls
146 echo 'some strange line' >> error_sysctls
147 coverage run -a --branch bin/kernel-hardening-checker -c test.config -s error_sysctls && exit 1
149 echo ">>>>> invalid sysctl file <<<<<"
151 coverage run -a --branch bin/kernel-hardening-checker -c test.config -s empty_file && exit 1
153 echo "The end of the functional tests"