Skip to content

Commit

Permalink
Merge pull request #8942 from yuumasato/align_kernel_module_with_disa
Browse files Browse the repository at this point in the history
Align kernel module rules  with DISA STIG Benchmarks
  • Loading branch information
jan-cerny authored Jun 17, 2022
2 parents 0d92e2b + 0b7ae4a commit 2535d88
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 10 deletions.
5 changes: 4 additions & 1 deletion docs/templates/template_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -426,12 +426,15 @@ The only way to remediate is to recompile and reinstall the kernel, so no remedi

#### kernel_module_disabled
- Checks if the given Linux kernel module is disabled.
The default method is to check the `install` keyword.
On OL and RHEL products the `blacklist` keyword is also checked.
The SLE products only check for the `blacklist` keyword.

- Parameters:

- **kernmodule** - name of the Linux kernel module, eg. `cramfs`

- Languages: Ansible, Bash, OVAL
- Languages: Ansible, Bash, Kubernetes, OVAL

#### lineinfile
- Checks that the given text is present in a file.
Expand Down
5 changes: 5 additions & 0 deletions shared/macros/01-general.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ Therefore, you need to use a tool that can query the OCP API, retrieve the follo
To configure the system to prevent the <code>{{{ module }}}</code>
kernel module from being loaded, add the following line to the file <code>/etc/modprobe.d/{{{ module }}}.conf</code>:
<pre>install {{{ module }}} /bin/true</pre>
{{% if product in ["ol7", "ol8", "rhel7", "rhel8"] %}}
To configure the system to prevent the <code>{{{ module }}}</code> from being used,
add the following line to file <code>/etc/modprobe.d/{{{ module }}}.conf</code>:
<pre>blacklist {{{ module }}}</pre>
{{% endif %}}
{{%- endmacro %}}


Expand Down
5 changes: 4 additions & 1 deletion shared/macros/10-ocil.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -754,8 +754,11 @@ ocil_clause: "no line is returned"
#}}
{{%- macro ocil_module_disable(module) %}}
If the system is configured to prevent the loading of the <code>{{{ module }}}</code> kernel module,
it will contain lines inside any file in <code>/etc/modprobe.d</code> or the deprecated<code>/etc/modprobe.conf</code>.
it will contain lines inside any file in <code>/etc/modprobe.d</code> or the deprecated<code> /etc/modprobe.conf</code>.
These lines instruct the module loading system to run another program (such as <code>/bin/true</code>) upon a module <code>install</code> event.
{{% if product in ["ol7", "ol8", "rhel7", "rhel8"] %}}
These lines can also instruct the module loading system to ignore the <code>{{{ module }}}</code> kernel module via <code>blacklist</code> keyword.
{{% endif %}}
Run the following command to search for such lines in all files in <code>/etc/modprobe.d</code> and the deprecated <code>/etc/modprobe.conf</code>:
<pre>$ grep -r {{{ module }}} /etc/modprobe.conf /etc/modprobe.d</pre>
{{%- endmacro %}}
Expand Down
8 changes: 8 additions & 0 deletions shared/templates/kernel_module_disabled/ansible.template
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,12 @@
dest: "/etc/modprobe.d/{{{ KERNMODULE }}}.conf"
regexp: '{{{ KERNMODULE }}}'
line: "install {{{ KERNMODULE }}} /bin/true"
{{% if product in ["ol7", "ol8", "rhel7", "rhel8"] %}}
- name: Ensure kernel module '{{{ KERNMODULE }}}' is blacklisted
lineinfile:
create: yes
dest: "/etc/modprobe.d/{{{ KERNMODULE }}}.conf"
regexp: '^blacklist {{{ KERNMODULE }}}$'
line: "blacklist {{{ KERNMODULE }}}"
{{% endif %}}
{{% endif %}}
5 changes: 5 additions & 0 deletions shared/templates/kernel_module_disabled/bash.template
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ else
echo -e "\n# Disable per security requirements" >> /etc/modprobe.d/{{{ KERNMODULE }}}.conf
echo "install {{{ KERNMODULE }}} /bin/true" >> /etc/modprobe.d/{{{ KERNMODULE }}}.conf
fi
{{% if product in ["ol7", "ol8", "rhel7", "rhel8"] %}}
if ! LC_ALL=C grep -q -m 1 "^blacklist {{{ KERNMODULE }}}$" /etc/modprobe.d/{{{ KERNMODULE }}}.conf ; then
echo "blacklist {{{ KERNMODULE }}}" >> /etc/modprobe.d/{{{ KERNMODULE }}}.conf
fi
{{% endif %}}
{{% endif %}}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spec:
storage:
files:
- contents:
source: data:,install%20{{{ KERNMODULE | urlencode }}}%20/bin/true%0A
source: data:,install%20{{{ KERNMODULE | urlencode }}}%20/bin/true%0Ablacklist%20{{{ KERNMODULE | urlencode }}}%0A
mode: 0644
path: /etc/modprobe.d/75-kernel_module_{{{ KERNMODULE }}}_disabled.conf
overwrite: true
29 changes: 22 additions & 7 deletions shared/templates/kernel_module_disabled/oval.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,28 @@
id="kernel_module_{{{ KERNMODULE }}}_disabled" version="1">
{{{ oval_metadata("The kernel module " + KERNMODULE + " should be disabled.") }}}
<criteria operator="OR">
<criterion test_ref="test_kernmod_{{{ KERNMODULE }}}_disabled"
comment="kernel module {{{ KERNMODULE }}} disabled in modprobe.d" />
{{% if product in ["sle12", "sle15"] %}}
{{% if product in ["sle12", "sle15"] %}}
<criterion test_ref="test_kernmod_{{{ KERNMODULE }}}_blacklisted"
comment="kernel module {{{ KERNMODULE }}} blacklisted in modprobe.d" />
{{% endif %}}
{{% if "ubuntu" not in product %}}
{{% elif product in ["ol7", "ol8", "rhcos4", "rhel7", "rhel8"] %}}
<criteria operator="AND">
<criterion test_ref="test_kernmod_{{{ KERNMODULE }}}_blacklisted"
comment="kernel module {{{ KERNMODULE }}} blacklisted in modprobe.d" />
<criterion test_ref="test_kernmod_{{{ KERNMODULE }}}_disabled"
comment="kernel module {{{ KERNMODULE }}} disabled in modprobe.d" />
</criteria>
{{% else %}}
<criterion test_ref="test_kernmod_{{{ KERNMODULE }}}_disabled"
comment="kernel module {{{ KERNMODULE }}} disabled in modprobe.d" />
{{% endif %}}
{{% if "ubuntu" not in product and "rhel" not in product%}}
<criterion test_ref="test_kernmod_{{{ KERNMODULE }}}_modprobeconf" comment="kernel module {{{ KERNMODULE }}} disabled in /etc/modprobe.conf" />
{{% endif %}}

</criteria>
</definition>

{{% if product not in ["sle12", "sle15"] %}}
<ind:textfilecontent54_test id="test_kernmod_{{{ KERNMODULE }}}_disabled" version="1" check="all"
comment="kernel module {{{ KERNMODULE }}} disabled">
<ind:object object_ref="obj_kernmod_{{{ KERNMODULE }}}_disabled" />
Expand All @@ -38,22 +47,28 @@
<value>/usr/lib/modprobe.d</value>
<value>/usr/lib/modules-load.d</value>
</constant_variable>
{{% endif %}}

{{% if product in ["sle12", "sle15"] %}}
{{% if product in ["ol7", "ol8", "rhcos4", "rhel7", "rhel8", "sle12", "sle15"] %}}
<ind:textfilecontent54_test id="test_kernmod_{{{ KERNMODULE }}}_blacklisted" version="1" check="all"
comment="kernel module {{{ KERNMODULE }}} blacklisted">
<ind:object object_ref="obj_kernmod_{{{ KERNMODULE }}}_blacklisted" />
</ind:textfilecontent54_test>

<ind:textfilecontent54_object id="obj_kernmod_{{{ KERNMODULE }}}_blacklisted"
version="1" comment="kernel module {{{ KERNMODULE }}} blacklisted">
{{% if product in ["sle12", "sle15"] %}}
<ind:filepath>/etc/modprobe.d/50-blacklist.conf</ind:filepath>
{{% else %}}
<ind:path var_ref="var_kernel_module_{{{ KERNMODULE }}}_paths" var_check="at least one" />
<ind:filename operation="pattern match">^.*\.conf$</ind:filename>
{{% endif %}}
<ind:pattern operation="pattern match">^blacklist\s+{{{ KERNMODULE }}}$</ind:pattern>
<ind:instance datatype="int">1</ind:instance>
</ind:textfilecontent54_object>
{{% endif %}}

{{% if "ubuntu" not in product %}}
{{% if "ubuntu" not in product and "rhel" not in product %}}
<ind:textfilecontent54_test id="test_kernmod_{{{ KERNMODULE }}}_modprobeconf" version="1" check="all"
comment="kernel module {{{ KERNMODULE }}} disabled in /etc/modprobe.conf">
<ind:object object_ref="obj_kernmod_{{{ KERNMODULE }}}_modprobeconf" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/bin/bash

echo "install {{{ KERNMODULE }}} /bin/true" > /etc/modprobe.d/{{{ KERNMODULE }}}.conf
{{% if product in ["ol7", "ol8", "rhel7", "rhel8"] %}}
echo "blacklist {{{ KERNMODULE }}}" >> /etc/modprobe.d/{{{ KERNMODULE }}}.conf
{{% endif %}}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/bin/bash

echo "install {{{ KERNMODULE }}} /bin/true" > /etc/modules-load.d/{{{ KERNMODULE }}}.conf
{{% if product in ["ol7", "ol8", "rhel7", "rhel8"] %}}
echo "blacklist {{{ KERNMODULE }}}" >> /etc/modules-load.d/{{{ KERNMODULE }}}.conf
{{% endif %}}
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ if [[ ! -d /run/modprobe.d ]]; then
mkdir -p /run/modprobe.d
fi
echo "install {{{ KERNMODULE }}} /bin/true" > /run/modprobe.d/{{{ KERNMODULE }}}.conf
{{% if product in ["ol7", "ol8", "rhel7", "rhel8"] %}}
echo "blacklist {{{ KERNMODULE }}}" >> /run/modprobe.d/{{{ KERNMODULE }}}.conf
{{% endif %}}
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ if [[ ! -d /run/modules-load.d ]]; then
fi

echo "install {{{ KERNMODULE }}} /bin/true" > /run/modules-load.d/{{{ KERNMODULE }}}.conf
{{% if product in ["ol7", "ol8", "rhel7", "rhel8"] %}}
echo "blacklist {{{ KERNMODULE }}}" >> /run/modules-load.d/{{{ KERNMODULE }}}.conf
{{% endif %}}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/bin/bash

echo "install {{{ KERNMODULE }}} /bin/true" > /usr/lib/modprobe.d/{{{ KERNMODULE }}}.conf
{{% if product in ["ol7", "ol8", "rhel7", "rhel8"] %}}
echo "blacklist {{{ KERNMODULE }}}" >> /usr/lib/modprobe.d/{{{ KERNMODULE }}}.conf
{{% endif %}}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/bin/bash

echo "install {{{ KERNMODULE }}} /bin/true" > /usr/lib/modules-load.d/{{{ KERNMODULE }}}.conf
{{% if product in ["ol7", "ol8", "rhel7", "rhel8"] %}}
echo "blacklist {{{ KERNMODULE }}}" >> /usr/lib/modules-load.d/{{{ KERNMODULE }}}.conf
{{% endif %}}

0 comments on commit 2535d88

Please sign in to comment.