Test more wrong combinations of options
[kconfig-hardened-check.git] / .github / workflows / functional_test.sh
1 #!/bin/sh
2
3 set -x
4 set -e
5
6 git status
7 git show -s
8
9 echo "Beginning of the functional tests"
10
11 echo ">>>>> get help <<<<<"
12 coverage run -a --branch bin/kconfig-hardened-check
13 coverage run -a --branch bin/kconfig-hardened-check -h
14
15 echo ">>>>> get version <<<<<"
16 coverage run -a --branch bin/kconfig-hardened-check --version
17
18 echo ">>>>> print the security hardening recommendations <<<<<"
19 coverage run -a --branch bin/kconfig-hardened-check -p X86_64
20 coverage run -a --branch bin/kconfig-hardened-check -p X86_64 -m verbose
21 coverage run -a --branch bin/kconfig-hardened-check -p X86_64 -m json
22
23 coverage run -a --branch bin/kconfig-hardened-check -p X86_32
24 coverage run -a --branch bin/kconfig-hardened-check -p X86_32 -m verbose
25 coverage run -a --branch bin/kconfig-hardened-check -p X86_32 -m json
26
27 coverage run -a --branch bin/kconfig-hardened-check -p ARM64
28 coverage run -a --branch bin/kconfig-hardened-check -p ARM64 -m verbose
29 coverage run -a --branch bin/kconfig-hardened-check -p ARM64 -m json
30
31 coverage run -a --branch bin/kconfig-hardened-check -p ARM
32 coverage run -a --branch bin/kconfig-hardened-check -p ARM -m verbose
33 coverage run -a --branch bin/kconfig-hardened-check -p ARM -m json
34
35 echo ">>>>> generate the Kconfig fragment <<<<<"
36 coverage run -a --branch bin/kconfig-hardened-check -g X86_64
37 coverage run -a --branch bin/kconfig-hardened-check -g X86_32
38 coverage run -a --branch bin/kconfig-hardened-check -g ARM64
39 coverage run -a --branch bin/kconfig-hardened-check -g ARM
40
41 echo ">>>>> check the example kconfig files, cmdline, and sysctl <<<<<"
42 cat /proc/cmdline
43 echo "l1tf=off mds=full mitigations=off randomize_kstack_offset=on retbleed=0 iommu.passthrough=0" > ./cmdline_example
44 cat ./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"`
49 COUNT=0
50 for C in $KCONFIGS
51 do
52         COUNT=$(expr $COUNT + 1)
53         echo "\n>>>>> checking kconfig number $COUNT <<<<<"
54         coverage run -a --branch bin/kconfig-hardened-check -c $C > /dev/null
55         coverage run -a --branch bin/kconfig-hardened-check -c $C -m verbose > /dev/null
56         coverage run -a --branch bin/kconfig-hardened-check -c $C -l /proc/cmdline > /dev/null
57         coverage run -a --branch bin/kconfig-hardened-check -c $C -s /tmp/sysctls > /dev/null
58         coverage run -a --branch bin/kconfig-hardened-check -c $C -l ./cmdline_example -s $SYSCTL_EXAMPLE > /dev/null
59         coverage run -a --branch bin/kconfig-hardened-check -c $C -l ./cmdline_example -s $SYSCTL_EXAMPLE -m verbose > /dev/null
60         coverage run -a --branch bin/kconfig-hardened-check -c $C -l ./cmdline_example -s $SYSCTL_EXAMPLE -m json > /dev/null
61         coverage run -a --branch bin/kconfig-hardened-check -c $C -l ./cmdline_example -s $SYSCTL_EXAMPLE -m show_ok > /dev/null
62         coverage run -a --branch bin/kconfig-hardened-check -c $C -l ./cmdline_example -s $SYSCTL_EXAMPLE -m show_fail > /dev/null
63 done
64 echo "\n>>>>> have checked $COUNT kconfigs <<<<<"
65
66 echo ">>>>> check sysctl separately <<<<<"
67 coverage run -a --branch bin/kconfig-hardened-check -s $SYSCTL_EXAMPLE > /dev/null
68 coverage run -a --branch bin/kconfig-hardened-check -s $SYSCTL_EXAMPLE -m verbose > /dev/null
69 coverage run -a --branch bin/kconfig-hardened-check -s $SYSCTL_EXAMPLE -m json > /dev/null
70 coverage run -a --branch bin/kconfig-hardened-check -s $SYSCTL_EXAMPLE -m show_ok > /dev/null
71 coverage run -a --branch bin/kconfig-hardened-check -s $SYSCTL_EXAMPLE -m show_fail > /dev/null
72
73 echo "Collect coverage for error handling"
74
75 echo ">>>>> -c and -p together <<<<<"
76 coverage run -a --branch bin/kconfig-hardened-check -p X86_64 -c kconfig_hardened_check/config_files/distros/fedora_34.config && exit 1
77
78 echo ">>>>> -c and -g together <<<<<"
79 coverage run -a --branch bin/kconfig-hardened-check -g X86_64 -c kconfig_hardened_check/config_files/distros/fedora_34.config && exit 1
80
81 echo ">>>>> -l without -c <<<<<"
82 coverage run -a --branch bin/kconfig-hardened-check -l /proc/cmdline && exit 1
83
84 echo ">>>>> -s and -p together <<<<<"
85 coverage run -a --branch bin/kconfig-hardened-check -p X86_64 -s $SYSCTL_EXAMPLE && exit 1
86
87 echo ">>>>> -s and -g together <<<<<"
88 coverage run -a --branch bin/kconfig-hardened-check -g X86_64 -s $SYSCTL_EXAMPLE && exit 1
89
90 echo ">>>>> -p and -g together <<<<<"
91 coverage run -a --branch bin/kconfig-hardened-check -p X86_64 -g X86_64 && exit 1
92
93 echo ">>>>> wrong modes for -p <<<<<"
94 coverage run -a --branch bin/kconfig-hardened-check -p X86_64 -m show_ok && exit 1
95 coverage run -a --branch bin/kconfig-hardened-check -p X86_64 -m show_fail && exit 1
96
97 echo ">>>>> wrong mode for -g <<<<<"
98 coverage run -a --branch bin/kconfig-hardened-check -g X86_64 -m show_ok && exit 1
99
100 cp kconfig_hardened_check/config_files/distros/fedora_34.config ./test.config
101
102 echo ">>>>> no kernel version <<<<<"
103 sed '3d' test.config > error.config
104 coverage run -a --branch bin/kconfig-hardened-check -c error.config && exit 1
105
106 echo ">>>>> strange kernel version string <<<<<"
107 sed '3 s/5./version 5./' test.config > error.config
108 coverage run -a --branch bin/kconfig-hardened-check -c error.config && exit 1
109
110 echo ">>>>> no arch <<<<<"
111 sed '305d' test.config > error.config
112 coverage run -a --branch bin/kconfig-hardened-check -c error.config && exit 1
113
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/kconfig-hardened-check -c error.config && exit 1
118
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/kconfig-hardened-check -c error.config && exit 1
123
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/kconfig-hardened-check -c error.config && exit 1
128
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/kconfig-hardened-check -c error.config && exit 1
133
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/kconfig-hardened-check -c error.config && exit 1
138
139 echo ">>>>> multi-line cmdline file <<<<<"
140 echo 'hey man 1' > cmdline
141 echo 'hey man 2' >> cmdline
142 coverage run -a --branch bin/kconfig-hardened-check -c test.config -l cmdline && exit 1
143
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/kconfig-hardened-check -c test.config -s error_sysctls && exit 1
148
149 echo ">>>>> invalid sysctl file <<<<<"
150 touch empty_file
151 coverage run -a --branch bin/kconfig-hardened-check -c test.config -s empty_file && exit 1
152
153 echo "The end of the functional tests"