-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSV-257797.rb
75 lines (54 loc) · 3.59 KB
/
SV-257797.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
70
71
72
73
74
75
control 'SV-257797' do
title 'RHEL 9 must restrict access to the kernel message buffer.'
desc 'Preventing unauthorized information transfers mitigates the risk of information, including encrypted representations of information, produced by the actions of prior users/roles (or the actions of processes acting on behalf of prior users/roles) from being available to any current users/roles (or current processes) that obtain access to shared system resources (e.g., registers, main memory, hard disks) after those resources have been released back to information systems. The control of information in shared resources is also commonly referred to as object reuse and residual information protection.
This requirement generally applies to the design of an information technology product, but it can also apply to the configuration of particular information system components that are, or use, such products. This can be verified by acceptance/validation processes in DOD or other government agencies.
There may be shared resources with configurable protections (e.g., files in storage) that may be assessed on specific information system components.
Restricting access to the kernel message buffer limits access to only root. This prevents attackers from gaining additional system information as a nonprivileged user.'
desc 'check', %q(Verify RHEL 9 is configured to restrict access to the kernel message buffer with the following commands:
Check the status of the kernel.dmesg_restrict kernel parameter.
$ sudo sysctl kernel.dmesg_restrict
kernel.dmesg_restrict = 1
If "kernel.dmesg_restrict" is not set to "1" or is missing, this is a finding.
Check that the configuration files are present to enable this kernel parameter.
$ sudo /usr/lib/systemd/systemd-sysctl --cat-config | egrep -v '^(#|;)' | grep -F kernel.dmesg_restrict | tail -1
kernel.dmesg_restrict = 1
If "kernel.dmesg_restrict" is not set to "1" or is missing, this is a finding.)
desc 'fix', 'Configure RHEL 9 to restrict access to the kernel message buffer.
Add or edit the following line in a system configuration file, in the "/etc/sysctl.d/" directory:
kernel.dmesg_restrict = 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-000132-GPOS-00067'
tag gid: 'V-257797'
tag rid: 'SV-257797r958514_rule'
tag stig_id: 'RHEL-09-213010'
tag fix_id: 'F-61462r925377_fix'
tag cci: ['CCI-001090', 'CCI-001082']
tag nist: ['SC-4', 'SC-2']
tag 'host'
only_if('Control not applicable within a container', impact: 0.0) {
!virtualization.system.eql?('docker')
}
parameter = 'kernel.dmesg_restrict'
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