commit 2e1eeff365be8fde302620fae6691ccc523f6f9e Author: Gabriel Becker Date: Thu Feb 24 18:19:45 2022 +0100 Manual edited patch scap-security-guide-0.1.60-rhel9_stig_grub-PR_7931.patch. diff --git a/linux_os/guide/system/bootloader-grub2/grub2_kernel_trust_cpu_rng/oval/shared.xml b/linux_os/guide/system/bootloader-grub2/grub2_kernel_trust_cpu_rng/oval/shared.xml index c95f1d4..9035eee 100644 --- a/linux_os/guide/system/bootloader-grub2/grub2_kernel_trust_cpu_rng/oval/shared.xml +++ b/linux_os/guide/system/bootloader-grub2/grub2_kernel_trust_cpu_rng/oval/shared.xml @@ -29,11 +29,34 @@ 1 - - - + {{% if product in ['rhel9'] %}} + + + + + + + + + + + + /boot/loader/entries/ + ^.*\.conf$ + ^options (.*)$ + 1 + + {{% else %}} + + + + @@ -50,6 +73,7 @@ ^kernelopts=(.*)$ 1 + {{% endif %}} @@ -61,5 +85,4 @@ ^(?:.*\s)?random\.trust_cpu=off(?:\s.*)?$ - diff --git a/linux_os/guide/system/network/network-ipv6/disabling_ipv6/grub2_ipv6_disable_argument/rule.yml b/linux_os/guide/system/network/network-ipv6/disabling_ipv6/grub2_ipv6_disable_argument/rule.yml index dae640f..b8ff66c 100644 --- a/linux_os/guide/system/network/network-ipv6/disabling_ipv6/grub2_ipv6_disable_argument/rule.yml +++ b/linux_os/guide/system/network/network-ipv6/disabling_ipv6/grub2_ipv6_disable_argument/rule.yml @@ -1,6 +1,6 @@ documentation_complete: true -prodtype: fedora,rhcos4,ol7,ol8,rhel7,rhel8,rhv4,sle15 +prodtype: fedora,ol7,ol8,rhcos4,rhel7,rhel8,rhel9,rhv4,sle15 title: 'Ensure IPv6 is disabled through kernel boot parameter' diff --git a/linux_os/guide/system/network/network-ipv6/disabling_ipv6/grub2_ipv6_disable_argument/tests/arg_not_there_rhel9.fail.sh b/linux_os/guide/system/network/network-ipv6/disabling_ipv6/grub2_ipv6_disable_argument/tests/arg_not_there_rhel9.fail.sh new file mode 100644 index 0000000..fc649d7 --- /dev/null +++ b/linux_os/guide/system/network/network-ipv6/disabling_ipv6/grub2_ipv6_disable_argument/tests/arg_not_there_rhel9.fail.sh @@ -0,0 +1,10 @@ +#!/bin/bash +# platform = Red Hat Enterprise Linux 9 + +# Removes ipv6.disable argument from kernel command line in //boot/loader/entries/*.conf + +for file in /boot/loader/entries/*.conf ; do + if grep -q '^.*ipv6\.disable=.*' "$file" ; then + sed -i 's/\(^.*\)ipv6\.disable=[^[:space:]]*\(.*\)/\1 \2/' "$file" + fi +done diff --git a/linux_os/guide/system/network/network-ipv6/disabling_ipv6/grub2_ipv6_disable_argument/tests/wrong_value_rhel9.fail.sh b/linux_os/guide/system/network/network-ipv6/disabling_ipv6/grub2_ipv6_disable_argument/tests/wrong_value_rhel9.fail.sh new file mode 100644 index 0000000..3c1cde1 --- /dev/null +++ b/linux_os/guide/system/network/network-ipv6/disabling_ipv6/grub2_ipv6_disable_argument/tests/wrong_value_rhel9.fail.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# platform = Red Hat Enterprise Linux 9 + +# Break the ipv6.disable argument in kernel command line in /boot/loader/entries/*.conf + +for file in /boot/loader/entries/*.conf ; do + if grep -q '^.*ipv6\.disable=.*' "$file" ; then + # modify the GRUB command-line if an ipv6.disable= arg already exists + sed -i 's/\(^.*\)ipv6\.disable=[^[:space:]]*\(.*\)/\1 ipv6\.disable=0 \2/' "$file" + else + # no ipv6.disable=arg is present, append it + sed -i 's/\(^.*\(vmlinuz\|kernelopts|options\).*\)/\1 ipv6\.disable=0/' "$file" + fi +done diff --git a/shared/macros-bash.jinja b/shared/macros-bash.jinja index b5f55ae..3eebbd9 100644 --- a/shared/macros-bash.jinja +++ b/shared/macros-bash.jinja @@ -684,3 +684,43 @@ dpkg-query --show --showformat='${db:Status-Status}\n' "{{{ pkgname }}}" 2>/dev/ rpm --quiet -q "{{{ pkgname }}}" {{%- endif -%}} {{%- endmacro -%}} + +{{# + + Remediation for grub2 bootloader arguments +#}} +{{% macro grub2_bootloader_argument_remediation(ARG_NAME, ARG_NAME_VALUE) %}} +{{% if product in ["rhel7", "ol7", "rhel9"] or 'ubuntu' in product %}} +{{% if '/' in ARG_NAME %}} +{{{ raise("ARG_NAME (" + ARG_NAME + ") uses sed path separator (/) in " + rule_id) }}} +{{% elif '/' in ARG_NAME_VALUE %}} +{{{ raise("ARG_NAME_VALUE (" + ARG_NAME_VALUE + ") uses sed path separator (/) in " + rule_id) }}} +{{% endif %}} +# Correct the form of default kernel command line in GRUB +if grep -q '^GRUB_CMDLINE_LINUX=.*{{{ ARG_NAME }}}=.*"' '/etc/default/grub' ; then + # modify the GRUB command-line if an {{{ ARG_NAME }}}= arg already exists + sed -i 's/\(^GRUB_CMDLINE_LINUX=".*\){{{ ARG_NAME }}}=[^[:space:]]*\(.*"\)/\1 {{{ ARG_NAME_VALUE }}} \2/' '/etc/default/grub' +else + # no {{{ ARG_NAME }}}=arg is present, append it + sed -i 's/\(^GRUB_CMDLINE_LINUX=".*\)"/\1 {{{ ARG_NAME_VALUE }}}"/' '/etc/default/grub' +fi + +{{% if 'ubuntu' in product %}} +update-grub +{{% else %}} +# Correct the form of kernel command line for each installed kernel in the bootloader +grubby --update-kernel=ALL --args="{{{ ARG_NAME_VALUE }}}" +{{% endif %}} +{{% else %}} +# Correct grub2 kernelopts value using grub2-editenv +existing_kernelopts="$(grub2-editenv - list | grep kernelopts)" +if ! printf '%s' "$existing_kernelopts" | grep -qE '^kernelopts=(.*\s)?{{{ ARG_NAME_VALUE }}}(\s.*)?$'; then + if test -n "$existing_kernelopts"; then + grub2-editenv - set "$existing_kernelopts {{{ ARG_NAME_VALUE }}}" + else + grub2-editenv - set "kernelopts={{{ ARG_NAME_VALUE }}}" + fi +fi +{{% endif %}} + +{{% endmacro %}} diff --git a/shared/templates/grub2_bootloader_argument/bash.template b/shared/templates/grub2_bootloader_argument/bash.template index cecd1f9..fd75db4 100644 --- a/shared/templates/grub2_bootloader_argument/bash.template +++ b/shared/templates/grub2_bootloader_argument/bash.template @@ -1,6 +1,6 @@ # platform = multi_platform_rhel,multi_platform_fedora,multi_platform_ol,multi_platform_rhv,multi_platform_ubuntu -{{% if product in ["rhel7", "ol7"] or 'ubuntu' in product %}} +{{% if product in ["rhel7", "ol7", "rhel9"] or 'ubuntu' in product %}} {{% if '/' in ARG_NAME %}} {{{ raise("ARG_NAME (" + ARG_NAME + ") uses sed path separator (/) in " + rule_id) }}} {{% elif '/' in ARG_NAME_VALUE %}} diff --git a/shared/templates/grub2_bootloader_argument/oval.template b/shared/templates/grub2_bootloader_argument/oval.template index e8da1fe..3ea8acb 100644 --- a/shared/templates/grub2_bootloader_argument/oval.template +++ b/shared/templates/grub2_bootloader_argument/oval.template @@ -2,9 +2,14 @@ {{{ oval_metadata("Ensure " + ARG_NAME_VALUE + " is configured in the kernel line in /etc/default/grub.") }}} - {{% if product in ["rhel7", "ol7"] or 'ubuntu' in product %}} - + {{% if product in ["rhel7", "ol7", "rhel9"] or 'ubuntu' in product %}} + {{% if product in ['rhel9'] %}} + + {{% else %}} + + {{% endif %}} @@ -22,7 +27,7 @@ -{{% if product in ["rhel7", "ol7"] or 'ubuntu' in product %}} +{{% if product in ["rhel7", "ol7", "rhel9"] or 'ubuntu' in product %}} @@ -50,6 +55,21 @@ 1 + {{% if product in ["rhel9"] %}} + + + + + + + /boot/loader/entries/ + ^.*\.conf$ + ^options (.*)$ + 1 + + {{% else %}} @@ -68,6 +88,8 @@ 1 + {{% endif %}} + {{% else %}}