scap-security-guide/SOURCES/scap-security-guide-0.1.62-sysctl_separate_object_from_state-PR_8704.patch
2022-06-29 03:34:02 +00:00

89 lines
4.3 KiB
Diff

From 1c403af00f39fcfa3c7cf898b1e832d4580cfb59 Mon Sep 17 00:00:00 2001
From: Watson Sato <wsato@redhat.com>
Date: Thu, 5 May 2022 10:28:34 +0200
Subject: [PATCH] PR #8704 edited manually
- Restrict test to sysctl.conf and /usr/sysctl.d
- Separate the state from the object and check it
---
.../tests/wrong_value_d_directory.fail.sh | 12 ++++++------
shared/templates/sysctl/oval.template | 18 ++++++++++--------
2 files changed, 16 insertions(+), 14 deletions(-)
diff --git a/linux_os/guide/system/permissions/restrictions/enable_execshield_settings/sysctl_kernel_randomize_va_space/tests/wrong_value_d_directory.fail.sh b/linux_os/guide/system/permissions/restrictions/enable_execshield_settings/sysctl_kernel_randomize_va_space/tests/wrong_value_d_directory.fail.sh
index 48a2665..5fb8ddc 100644
--- a/linux_os/guide/system/permissions/restrictions/enable_execshield_settings/sysctl_kernel_randomize_va_space/tests/wrong_value_d_directory.fail.sh
+++ b/linux_os/guide/system/permissions/restrictions/enable_execshield_settings/sysctl_kernel_randomize_va_space/tests/wrong_value_d_directory.fail.sh
@@ -5,19 +5,19 @@
setting_name="kernel.randomize_va_space"
setting_value="2"
# sysctl -w "$setting_name=$setting_value"
-if grep -q "^$setting_name" /usr/lib/sysctl.d/50-sysctl.conf; then
- sed -i "s/^$setting_name.*/$setting_name = $setting_value/" /usr/lib/sysctl.d/50-sysctl.conf
+if grep -q "^$setting_name" /etc/sysctl.conf; then
+ sed -i "s/^$setting_name.*/$setting_name = $setting_value/" /etc/sysctl.conf
else
- echo "$setting_name = $setting_value" >> /usr/lib/sysctl.d/50-sysctl.conf
+ echo "$setting_name = $setting_value" >> /etc/sysctl.conf
fi
setting_name="kernel.randomize_va_space"
setting_value="0"
# sysctl -w "$setting_name=$setting_value"
-if grep -q "^$setting_name" /etc/sysctl.d/99-sysctl.conf; then
- sed -i "s/^$setting_name.*/$setting_name = $setting_value/" /etc/sysctl.d/99-sysctl.conf
+if grep -q "^$setting_name" /etc/sysctl.d/98-sysctl.conf; then
+ sed -i "s/^$setting_name.*/$setting_name = $setting_value/" /etc/sysctl.d/98-sysctl.conf
else
- echo "$setting_name = $setting_value" >> /etc/sysctl.d/99-sysctl.conf
+ echo "$setting_name = $setting_value" >> /etc/sysctl.d/98-sysctl.conf
fi
sysctl --system
diff --git a/shared/templates/sysctl/oval.template b/shared/templates/sysctl/oval.template
index 564cc33..97f1e05 100644
--- a/shared/templates/sysctl/oval.template
+++ b/shared/templates/sysctl/oval.template
@@ -6,21 +6,15 @@
{{% macro state_static_sysctld(prefix) -%}}
<ind:object object_ref="object_static_{{{ prefix }}}_{{{ SYSCTLID }}}" />
-{{%- if SYSCTLVAL == "" %}}
<ind:state state_ref="state_static_sysctld_{{{ SYSCTLID }}}" />
-{{%- endif -%}}
{{%- endmacro -%}}
{{%- macro sysctl_match() -%}}
{{%- if SYSCTLVAL == "" -%}}
<ind:pattern operation="pattern match">^[\s]*{{{ SYSCTLVAR }}}[\s]*=[\s]*(\d+)[\s]*$</ind:pattern>
<ind:instance datatype="int" operation="greater than or equal">1</ind:instance>
{{%- else -%}}
-{{% if OPERATION == "pattern match" %}}
- <ind:pattern operation="pattern match">^[\s]*{{{ SYSCTLVAR }}}[\s]*=[\s]*{{{ SYSCTLVAL_REGEX }}}[\s]*$</ind:pattern>
-{{% else %}}
- <ind:pattern operation="pattern match">^[\s]*{{{ SYSCTLVAR }}}[\s]*=[\s]*{{{ SYSCTLVAL }}}[\s]*$</ind:pattern>
-{{% endif %}}
- <ind:instance datatype="int">1</ind:instance>
+ <ind:pattern operation="pattern match">^[\s]*{{{ SYSCTLVAR }}}[\s]*=[\s]*(.*)[\s]*$</ind:pattern>
+ <ind:instance datatype="int" operation="greater than or equal">1</ind:instance>
{{%- endif -%}}
{{%- endmacro -%}}
{{%- if "P" in FLAGS -%}}
@@ -258,6 +252,14 @@
</ind:textfilecontent54_state>
<external_variable comment="External variable for {{{ SYSCTLVAR }}}" datatype="{{{ DATATYPE }}}" id="sysctl_{{{ SYSCTLID }}}_value" version="1" />
+{{% else %}}
+ <ind:textfilecontent54_state id="state_static_sysctld_{{{ SYSCTLID }}}" version="1">
+{{% if OPERATION == "pattern match" %}}
+ <ind:subexpression operation="{{{ OPERATION }}}" datatype="{{{ DATATYPE }}}">{{{ SYSCTLVAL_REGEX }}}</ind:subexpression>
+{{% else %}}
+ <ind:subexpression operation="{{{ OPERATION }}}" datatype="{{{ DATATYPE }}}">{{{ SYSCTLVAL }}}</ind:subexpression>
+{{% endif %}}
+ </ind:textfilecontent54_state>
{{% endif %}}
</def-group>
{{%- endif -%}}
--
2.34.1