Skip to content

Commit 19ce790

Browse files
fix: ensure mountpoints are properly detected (ovh#177)
Fixes ovh#155 When real entries are present in fstab, system startup or runtime mountpoints are now properly detected Add a supplementary check in case of partition not present in fstab
1 parent 47cf862 commit 19ce790

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

Diff for: lib/utils.sh

+6
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,9 @@ is_a_partition() {
424424
if grep "[[:space:]]$1[[:space:]]" /etc/fstab | grep -vqE "^#"; then
425425
debug "$PARTITION found in fstab"
426426
FNRET=0
427+
elif mountpoint -q "$PARTITION"; then
428+
debug "$PARTITION found in /proc fs"
429+
FNRET=0
427430
else
428431
debug "Unable to find $PARTITION in fstab"
429432
FNRET=1
@@ -461,6 +464,9 @@ has_mount_option() {
461464
if grep "[[:space:]]${PARTITION}[[:space:]]" /etc/fstab | grep -vE "^#" | awk '{print $4}' | grep -q "$OPTION"; then
462465
debug "$OPTION has been detected in fstab for partition $PARTITION"
463466
FNRET=0
467+
elif mountpoint -q "$PARTITION"; then
468+
debug "$OPTION not detected in fstab, but $PARTITION is a mount point searching in /proc fs"
469+
has_mounted_option "$PARTITION" "$OPTION"
464470
else
465471
debug "Unable to find $OPTION in fstab for partition $PARTITION"
466472
FNRET=1

Diff for: tests/hardening/1.1.15_run_shm_nodev.sh

+7
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,15 @@ test_audit() {
1212
register_test retvalshouldbe 0
1313
run resolved /opt/debian-cis/bin/hardening/"${script}".sh --audit-all
1414

15+
echo "dummy entry" >>/etc/fstab
16+
17+
describe Fstab with a real entry to match runtime partitions
18+
register_test retvalshouldbe 0
19+
run resolved /opt/debian-cis/bin/hardening/"${script}".sh --audit-all
20+
1521
# Cleanup
1622
rm /run/shm
23+
sed "/dummy entry/d" /etc/fstab
1724

1825
##################################################################
1926
# For this test, we only check that it runs properly on a blank #

Diff for: tests/hardening/1.1.16_run_shm_nosuid.sh

+7
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,15 @@ test_audit() {
1212
register_test retvalshouldbe 0
1313
run resolved /opt/debian-cis/bin/hardening/"${script}".sh --audit-all
1414

15+
echo "dummy entry" >>/etc/fstab
16+
17+
describe Fstab with a real entry to match runtime partitions
18+
register_test retvalshouldbe 0
19+
run resolved /opt/debian-cis/bin/hardening/"${script}".sh --audit-all
20+
1521
# Cleanup
1622
rm /run/shm
23+
sed "/dummy entry/d" /etc/fstab
1724

1825
##################################################################
1926
# For this test, we only check that it runs properly on a blank #

Diff for: tests/hardening/1.1.17_run_shm_noexec.sh

+7
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,15 @@ test_audit() {
1212
register_test retvalshouldbe 0
1313
run resolved /opt/debian-cis/bin/hardening/"${script}".sh --audit-all
1414

15+
echo "dummy entry" >>/etc/fstab
16+
17+
describe Fstab with a real entry to match runtime partitions
18+
register_test retvalshouldbe 0
19+
run resolved /opt/debian-cis/bin/hardening/"${script}".sh --audit-all
20+
1521
# Cleanup
1622
rm /run/shm
23+
sed "/dummy entry/d" /etc/fstab
1724

1825
##################################################################
1926
# For this test, we only check that it runs properly on a blank #

0 commit comments

Comments
 (0)