Skip to content

Commit

Permalink
Merge pull request ComplianceAsCode#10993 from matusmarhefka/slab_fre…
Browse files Browse the repository at this point in the history
…elist_random

Fix kernel config name typo in rule kernel_config_slab_freelist_random
  • Loading branch information
marcusburghardt authored Aug 17, 2023
2 parents a57a3c9 + 7862a5f commit 616fce1
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ description: |-
Randomizes the freelist order used on creating new pages.
This configuration is available from kernel 5.9, but may be available if backported by distros.
{{{ describe_kernel_build_config("CONFIG_SLAB_FRELIST_RANDOM", "y") | indent(4) }}}
{{{ describe_kernel_build_config("CONFIG_SLAB_FREELIST_RANDOM", "y") | indent(4) }}}
rationale: |-
This security feature reduces the predictability of the kernel slab allocator against heap overflows.
Expand All @@ -28,11 +28,11 @@ references:
ocil_clause: 'the kernel was not built with the required value'

ocil: |-
{{{ ocil_kernel_build_config("CONFIG_SLAB_FRELIST_RANDOM", "y") | indent(4) }}}
{{{ ocil_kernel_build_config("CONFIG_SLAB_FREELIST_RANDOM", "y") | indent(4) }}}
template:
name: kernel_build_config
vars:
config: CONFIG_SLAB_FRELIST_RANDOM
config: CONFIG_SLAB_FREELIST_RANDOM
value: 'y'

6 changes: 6 additions & 0 deletions shared/templates/kernel_build_config/tests/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

if [ ! -e /boot/config-$(uname -r) ]; then
mkdir -p /boot
touch /boot/config-$(uname -r)
fi
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash
# remediation = none

source common.sh

# The sets up a config file with extra double quotes

{{%- if VARIABLE %}}
Expand Down
2 changes: 2 additions & 0 deletions shared/templates/kernel_build_config/tests/fail1.fail.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
{{%- set VALUE="correct_value" %}}
{{%- endif %}}

source common.sh

# fail1 is the plain expected fail scenario, the config with a wrong value

for file in /boot/config-* ; do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
{{%- set VALUE="correct_value" %}}
{{%- endif %}}

source common.sh

# fail1 is the plain expected fail scenario, the config with a wrong value
for file in /boot/config-* ; do
if grep -q ^{{{ CONFIG }}} "$file" ; then
Expand All @@ -15,6 +17,5 @@ for file in /boot/config-* ; do
done

# Ensure one config file is compliant
cp /boot/config-$(uname -r ) /boot/config-test
touch /boot/config-test
sed -i "s/{{{ CONFIG }}}.*/{{{ CONFIG }}}={{{ VALUE }}}/" /boot/config-test

2 changes: 2 additions & 0 deletions shared/templates/kernel_build_config/tests/fail2.fail.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash
# remediation = none

source common.sh

# fail2 is the second fail scenario

{{%- if VALUE == "n" %}}
Expand Down
2 changes: 2 additions & 0 deletions shared/templates/kernel_build_config/tests/pass1.pass.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

source common.sh

# pass1 is the plain expected pass scenario

{{%- if VALUE == "n" %}}
Expand Down
2 changes: 2 additions & 0 deletions shared/templates/kernel_build_config/tests/pass2.pass.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

source common.sh

# pass 2 is the second pass scenario

{{%- if VALUE == "n" %}}
Expand Down
2 changes: 2 additions & 0 deletions shared/templates/kernel_build_config/tests/substrings.fail.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
{{%- set SUPER_VALUE='XYZ' ~ VALUE %}}
{{%- endif %}}

source common.sh

for file in /boot/config-* ; do
if grep -q ^{{{ CONFIG }}} "$file" ; then
sed -i "s/{{{ CONFIG }}}.*/{{{ CONFIG }}}={{{ SUPER_VALUE }}}/" "$file"
Expand Down

0 comments on commit 616fce1

Please sign in to comment.