]>
Commit | Line | Data |
---|---|---|
65871d1a MT |
1 | #!/usr/bin/perl |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
34798dcd | 5 | # Copyright (C) 2007-2022 IPFire Team <info@ipfire.org> # |
65871d1a MT |
6 | # # |
7 | # This program is free software: you can redistribute it and/or modify # | |
8 | # it under the terms of the GNU General Public License as published by # | |
9 | # the Free Software Foundation, either version 3 of the License, or # | |
10 | # (at your option) any later version. # | |
11 | # # | |
12 | # This program is distributed in the hope that it will be useful, # | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
15 | # GNU General Public License for more details. # | |
16 | # # | |
17 | # You should have received a copy of the GNU General Public License # | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
19 | # # | |
20 | ############################################################################### | |
21 | ||
22 | use strict; | |
23 | ||
24 | # enable only the following on debugging purpose | |
f238e251 MT |
25 | #use warnings; |
26 | #use CGI::Carp 'fatalsToBrowser'; | |
65871d1a MT |
27 | |
28 | require '/var/ipfire/general-functions.pl'; | |
29 | require "${General::swroot}/lang.pl"; | |
30 | require "${General::swroot}/header.pl"; | |
31 | ||
32 | my %VULNERABILITIES = ( | |
6fb52ca1 | 33 | "itlb_multihit" => "$Lang::tr{'itlb multihit'} (CVE-2018-12207)", |
65871d1a MT |
34 | "l1tf" => "$Lang::tr{'foreshadow'} (CVE-2018-3620)", |
35 | "mds" => "$Lang::tr{'fallout zombieload ridl'} (CVE-2018-12126, CVE-2018-12130, CVE-2018-12127, CVE-2019-11091)", | |
36 | "meltdown" => "$Lang::tr{'meltdown'} (CVE-2017-5754)", | |
34798dcd | 37 | "mmio_stale_data" => "$Lang::tr{'mmio stale data'} (CVE-2022-21123, CVE-2022-21125, CVE-2022-21127, CVE-2022-21166)", |
7ee2eec3 | 38 | "retbleed" => "$Lang::tr{'retbleed'} (CVE-2022-29900, CVE-2022-29901)", |
65871d1a MT |
39 | "spec_store_bypass" => "$Lang::tr{'spectre variant 4'} (CVE-2018-3639)", |
40 | "spectre_v1" => "$Lang::tr{'spectre variant 1'} (CVE-2017-5753)", | |
41 | "spectre_v2" => "$Lang::tr{'spectre variant 2'} (CVE-2017-5715)", | |
e9c62e37 | 42 | "srbds" => "$Lang::tr{'srbds'} (CVE-2020-0543)", |
6fb52ca1 | 43 | "tsx_async_abort" => "$Lang::tr{'taa zombieload2'} (CVE-2019-11135)", |
65871d1a MT |
44 | ); |
45 | ||
46 | my $errormessage = ""; | |
47 | my $notice = ""; | |
48 | ||
49 | my %mainsettings = (); | |
50 | my %color = (); | |
51 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
8186b372 | 52 | &General::readhash("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \%color); |
65871d1a MT |
53 | |
54 | my %settings = ( | |
55 | "ENABLE_SMT" => "auto", | |
56 | ); | |
57 | &General::readhash("${General::swroot}/main/security", \%settings); | |
58 | ||
59 | &Header::showhttpheaders(); | |
60 | ||
61 | &Header::getcgihash(\%settings); | |
62 | ||
63 | if ($settings{'ACTION'} eq $Lang::tr{'save'}) { | |
64 | if ($settings{'ENABLE_SMT'} !~ /^(auto|on)$/) { | |
65 | $errormessage = $Lang::tr{'invalid input'}; | |
66 | } | |
67 | ||
68 | unless ($errormessage) { | |
69 | &General::writehash("${General::swroot}/main/security", \%settings); | |
70 | $notice = $Lang::tr{'please reboot to apply your changes'}; | |
71 | } | |
72 | } | |
73 | ||
74 | my %checked = (); | |
75 | $checked{'ENABLE_SMT'}{'auto'} = ''; | |
76 | $checked{'ENABLE_SMT'}{'on'} = ''; | |
77 | $checked{'ENABLE_SMT'}{$settings{'ENABLE_SMT'}} = "checked"; | |
78 | ||
79 | &Header::openpage($Lang::tr{'processor vulnerability mitigations'}, 1, ''); | |
80 | ||
81 | &Header::openbigbox("100%", "left", "", $errormessage); | |
82 | ||
83 | if ($errormessage) { | |
84 | &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); | |
85 | print "<font color='red'>$errormessage</font>"; | |
86 | &Header::closebox(); | |
87 | } | |
88 | ||
89 | if ($notice) { | |
90 | &Header::openbox('100%', 'left', $Lang::tr{'notice'}); | |
91 | print "<font color='red'>$notice</font>"; | |
92 | &Header::closebox(); | |
93 | } | |
94 | ||
95 | &Header::openbox('100%', 'center', $Lang::tr{'processor vulnerability mitigations'}); | |
96 | ||
97 | print <<END; | |
98 | <table class="tbl" width='100%'> | |
99 | <thead> | |
100 | <tr> | |
101 | <th align="center"> | |
102 | <strong>$Lang::tr{'vulnerability'}</strong> | |
103 | </th> | |
104 | <th align="center"> | |
105 | <strong>$Lang::tr{'status'}</strong> | |
106 | </th> | |
107 | </tr> | |
108 | </thead> | |
109 | <tbody> | |
110 | END | |
111 | ||
112 | my $id = 0; | |
113 | for my $vuln (sort keys %VULNERABILITIES) { | |
114 | my ($status, $message) = &check_status($vuln); | |
115 | next if (!$status); | |
116 | ||
117 | my $colour = ""; | |
118 | my $bgcolour = ""; | |
119 | my $status_message = ""; | |
120 | ||
121 | # Not affected | |
122 | if ($status eq "Not affected") { | |
123 | $status_message = $Lang::tr{'not affected'}; | |
124 | $colour = "white"; | |
29abc2d0 | 125 | $bgcolour = ${Header::colourgreen}; |
65871d1a MT |
126 | |
127 | # Vulnerable | |
128 | } elsif ($status eq "Vulnerable") { | |
129 | $status_message = $Lang::tr{'vulnerable'}; | |
130 | $colour = "white"; | |
131 | $bgcolour = ${Header::colourred}; | |
132 | ||
133 | # Mitigated | |
134 | } elsif ($status eq "Mitigation") { | |
135 | $status_message = $Lang::tr{'mitigated'}; | |
984a6cab | 136 | $colour = "white"; |
29abc2d0 | 137 | $bgcolour = ${Header::colourblue}; |
65871d1a | 138 | |
984a6cab | 139 | # Unknown report from kernel |
65871d1a | 140 | } else { |
b23db9b9 | 141 | $status_message = $status; |
984a6cab AF |
142 | $colour = "black"; |
143 | $bgcolour = ${Header::colouryellow}; | |
65871d1a MT |
144 | } |
145 | ||
146 | my $table_colour = ($id++ % 2) ? $color{'color22'} : $color{'color20'}; | |
147 | ||
148 | print <<END; | |
149 | <tr bgcolor="$table_colour"> | |
150 | <td align="left"> | |
151 | <strong>$VULNERABILITIES{$vuln}</strong> | |
152 | </td> | |
153 | ||
154 | <td bgcolor="$bgcolour" align="center"> | |
155 | <font color="$colour"> | |
156 | END | |
157 | if ($message) { | |
e896a9bd | 158 | print "<strong>$status_message</strong> - $message"; |
65871d1a MT |
159 | } else { |
160 | print "<strong>$status_message</strong>"; | |
161 | } | |
162 | ||
163 | print <<END; | |
164 | </font> | |
165 | </td> | |
166 | </tr> | |
167 | END | |
168 | } | |
169 | ||
170 | print <<END; | |
171 | </tbody> | |
172 | </table> | |
173 | END | |
174 | ||
175 | &Header::closebox(); | |
176 | ||
177 | print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n"; | |
178 | ||
179 | &Header::openbox('100%', 'center', $Lang::tr{'settings'}); | |
180 | ||
1cbcd044 MT |
181 | my $smt_status = &smt_status(); |
182 | ||
65871d1a MT |
183 | print <<END; |
184 | <table class="tbl" width="66%"> | |
185 | <tbody> | |
1cbcd044 MT |
186 | <tr> |
187 | <th colspan="2" align="center"> | |
188 | <strong>$smt_status</strong> | |
189 | </th> | |
190 | </tr> | |
191 | ||
65871d1a MT |
192 | <tr> |
193 | <td width="50%" align="left"> | |
1cbcd044 | 194 | $Lang::tr{'enable smt'} |
65871d1a MT |
195 | </td> |
196 | ||
197 | <td width="50%" align="center"> | |
198 | <label> | |
199 | <input type="radio" name="ENABLE_SMT" | |
200 | value="auto" $checked{'ENABLE_SMT'}{'auto'}> | |
201 | $Lang::tr{'automatic'} | |
202 | </label> / | |
203 | <label> | |
204 | <input type="radio" name="ENABLE_SMT" | |
205 | value="on" $checked{'ENABLE_SMT'}{'on'}> | |
206 | $Lang::tr{'force enable'} ($Lang::tr{'dangerous'}) | |
207 | </label> | |
208 | </td> | |
209 | </tr> | |
210 | ||
211 | <tr> | |
212 | <td colspan="2" align="right"> | |
213 | <input type="submit" name="ACTION" value="$Lang::tr{'save'}"> | |
214 | </td> | |
215 | </tr> | |
216 | </tbody> | |
217 | </table> | |
218 | END | |
219 | ||
220 | &Header::closebox(); | |
221 | ||
222 | print "</form>\n"; | |
223 | ||
224 | &Header::closebigbox(); | |
225 | ||
226 | &Header::closepage(); | |
227 | ||
228 | sub check_status($) { | |
229 | my $vuln = shift; | |
230 | ||
231 | open(FILE, "/sys/devices/system/cpu/vulnerabilities/$vuln") or return undef; | |
232 | my $status = <FILE>; | |
233 | close(FILE); | |
234 | ||
e896a9bd AF |
235 | chomp($status); |
236 | ||
413f84e9 | 237 | # Fix status when something has been mitigated, but not fully, yet |
b23db9b9 | 238 | if ($status =~ /^(Mitigation): (.*vulnerable.*)$/) { |
e896a9bd | 239 | return ("Vulnerable", $status); |
b23db9b9 AF |
240 | } |
241 | ||
a96bcf41 | 242 | if ($status =~ /^(Vulnerable|Mitigation): (.*)$/) { |
65871d1a | 243 | return ($1, $2); |
66c36198 | 244 | } |
65871d1a MT |
245 | |
246 | return $status; | |
247 | } | |
1cbcd044 MT |
248 | |
249 | sub smt_status() { | |
250 | open(FILE, "/sys/devices/system/cpu/smt/control"); | |
251 | my $status = <FILE>; | |
252 | close(FILE); | |
253 | ||
254 | chomp($status); | |
255 | ||
256 | if ($status eq "on") { | |
257 | return $Lang::tr{'smt enabled'}; | |
258 | } elsif (($status eq "off") || ($status eq "forceoff")) { | |
259 | return $Lang::tr{'smt disabled'}; | |
260 | } elsif ($status eq "notsupported") { | |
261 | return $Lang::tr{'smt not supported'}; | |
262 | } | |
263 | ||
264 | return $status; | |
265 | } |