-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSV-257799.rb
69 lines (51 loc) · 2.92 KB
/
SV-257799.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
control 'SV-257799' do
title 'RHEL 9 must prevent the loading of a new kernel for later execution.'
desc 'Changes to any software components can have significant effects on the overall security of the operating system. This requirement ensures the software has not been tampered with and that it has been provided by a trusted vendor.
Disabling kexec_load prevents an unsigned kernel image (that could be a windows kernel or modified vulnerable kernel) from being loaded. Kexec can be used subvert the entire secureboot process and should be avoided at all costs especially since it can load unsigned kernel images.'
desc 'check', %q(Verify RHEL 9 is configured to disable kernel image loading.
Check the status of the kernel.kexec_load_disabled kernel parameter with the following command:
$ sudo sysctl kernel.kexec_load_disabled
kernel.kexec_load_disabled = 1
If "kernel.kexec_load_disabled" is not set to "1" or is missing, this is a finding.
Check that the configuration files are present to enable this kernel parameter with the following command:
$ sudo /usr/lib/systemd/systemd-sysctl --cat-config | egrep -v '^(#|;)' | grep -F kernel.kexec_load_disabled | tail -1
kernel.kexec_load_disabled = 1
If "kernel.kexec_load_disabled" is not set to "1" or is missing, this is a finding.)
desc 'fix', 'Add or edit the following line in a system configuration file in the "/etc/sysctl.d/" directory:
kernel.kexec_load_disabled = 1
Load settings from all system configuration files with the following command:
$ sudo sysctl --system'
impact 0.5
ref 'DPMS Target Red Hat Enterprise Linux 9'
tag severity: 'medium'
tag gtitle: 'SRG-OS-000480-GPOS-00227'
tag gid: 'V-257799'
tag rid: 'SV-257799r997051_rule'
tag stig_id: 'RHEL-09-213020'
tag fix_id: 'F-61464r925383_fix'
tag cci: ['CCI-001749', 'CCI-000366', 'CCI-003992']
tag nist: ['CM-5 (3)', 'CM-6 b', 'CM-14']
tag 'host'
only_if('Control not applicable within a container', impact: 0.0) {
!virtualization.system.eql?('docker')
}
parameter = 'kernel.kexec_load_disabled'
value = 1
regexp = /^\s*#{parameter}\s*=\s*#{value}\s*$/
describe kernel_parameter(parameter) do
its('value') { should eq value }
end
search_results = command("/usr/lib/systemd/systemd-sysctl --cat-config | egrep -v '^(#|;)' | grep -F #{parameter}").stdout.strip.split("\n")
correct_result = search_results.any? { |line| line.match(regexp) }
incorrect_results = search_results.map(&:strip).reject { |line| line.match(regexp) }
describe 'Kernel config files' do
it "should configure '#{parameter}'" do
expect(correct_result).to eq(true), 'No config file was found that correctly sets this action'
end
unless incorrect_results.nil?
it 'should not have incorrect or conflicting setting(s) in the config files' do
expect(incorrect_results).to be_empty, "Incorrect or conflicting setting(s) found:\n\t- #{incorrect_results.join("\n\t- ")}"
end
end
end
end