Skip to content

Commit 881b368

Browse files
authored
Merge pull request #14379 from vojtapolasek/fix_mount_option_nodev_local_parts_vfat
mount_option_nodev_nonroot_local_partitions: ignore vfat partitions
2 parents 1bdf03a + ceae41d commit 881b368

5 files changed

Lines changed: 46 additions & 5 deletions

File tree

linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/ansible/shared.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
- lustre
3232
- davfs
3333
- fuse.sshfs
34+
- vfat
3435

3536
- name: "{{{ rule_title }}}: Ensure non-root local partitions are mounted with nodev option"
3637
ansible.posix.mount:
@@ -41,6 +42,7 @@
4142
fstype: "{{ item.fstype }}"
4243
when:
4344
- "item.mount is match('/\\w')"
45+
- "item.mount is not match('/(boot|efi)')"
4446
- "item.options is not search('nodev')"
4547
- "item.fstype not in excluded_fstypes"
4648
with_items:
@@ -49,5 +51,5 @@
4951
- name: "{{{ rule_title }}}: Ensure non-root local partitions are present with nodev option in /etc/fstab"
5052
ansible.builtin.replace:
5153
path: /etc/fstab
52-
regexp: '^\s*(?!#)(/dev/\S+|UUID=\S+)\s+(/\w\S*)\s+(\S+)\s+(?!.*\bnodev\b)(\S+)(.*)$'
54+
regexp: '^\s*(?!#)(/dev/\S+|UUID=\S+)\s+(/(?!boot|efi)\w\S*)\s+(?!vfat\s)(\S+)\s+(?!.*\bnodev\b)(\S+)(.*)$'
5355
replace: '\1 \2 \3 \4,nodev \5'

linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/bash/shared.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ excluded_fstypes=(
3030
lustre
3131
davfs
3232
fuse.sshfs
33+
vfat
3334
)
3435

3536
for partition_record in "${partitions_records[@]}"; do
@@ -38,6 +39,11 @@ for partition_record in "${partitions_records[@]}"; do
3839
device="$(echo "${partition_record}" | cut -d " " -f2)"
3940
device_type="$(echo "${partition_record}" | cut -d " " -f3)"
4041

42+
# Skip /boot and /efi partitions
43+
if [[ "$mount_point" =~ ^/(boot|efi) ]]; then
44+
continue
45+
fi
46+
4147
# Skip polyinstantiated directories
4248
if printf '%s\0' "${polyinstantiated_dirs[@]}" | grep -qxzF "$mount_point"; then
4349
continue
@@ -59,5 +65,5 @@ for partition_record in "${partitions_records[@]}"; do
5965
{{{ bash_ensure_partition_is_mounted("$mount_point") | indent(4) }}}
6066
done
6167

62-
# Remediate unmounted /etc/fstab entries
63-
sed -i -E '/nodev/! s;^\s*(/dev/\S+|UUID=\S+)\s+(/\w\S*)\s+(\S+)\s+(\S+)(.*)$;\1 \2 \3 \4,nodev \5;' /etc/fstab
68+
# Remediate unmounted /etc/fstab entries, excluding /boot, /efi, and vfat partitions
69+
sed -i -E '/nodev/! { /^\s*(\/dev\/\S+|UUID=\S+)\s+\/(boot|efi)/! { /^\s*(\/dev\/\S+|UUID=\S+)\s+\/\w\S*\s+vfat\s/! s;^\s*(/dev/\S+|UUID=\S+)\s+(/\w\S*)\s+(\S+)\s+(\S+)(.*)$;\1 \2 \3 \4,nodev \5; } }' /etc/fstab

linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/oval/shared.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<linux:partition_state id="state_local_nodev" version="1">
3434
<!-- this check defines a local partition as one which has a device node in /dev -->
3535
<linux:device operation="pattern match">^/dev/.*$</linux:device>
36-
<linux:fs_type operation="pattern match">^(?!afs$|autofs$|ceph$|cifs$|smb3$|smbfs$|sshfs$|ncpfs$|ncp$|nfs$|nfs4$|gfs$|gfs2$|glusterfs$|gpfs$|pvfs2$|ocfs2$|lustre$|davfs$|fuse\.sshfs$).+</linux:fs_type>
36+
<linux:fs_type operation="pattern match">^(?!afs$|autofs$|ceph$|cifs$|smb3$|smbfs$|sshfs$|ncpfs$|ncp$|nfs$|nfs4$|gfs$|gfs2$|glusterfs$|gpfs$|pvfs2$|ocfs2$|lustre$|davfs$|fuse\.sshfs$|vfat$).+</linux:fs_type>
3737
<linux:mount_options datatype="string" entity_check="all"
3838
operation="not equal">nodev</linux:mount_options>
3939
</linux:partition_state>
@@ -46,7 +46,7 @@
4646
</ind:textfilecontent54_test>
4747
<ind:textfilecontent54_object version="1" id="object_non_root_partitions_in_fstab">
4848
<ind:filepath>/etc/fstab</ind:filepath>
49-
<ind:pattern operation="pattern match">^\s*(?!#)(?:/dev/\S+|UUID=\S+)\s+/\w\S*\s+\S+\s+(\S+)</ind:pattern>
49+
<ind:pattern operation="pattern match">^\s*(?!#)(?:/dev/\S+|UUID=\S+)\s+/(?!boot|efi)\w\S*\s+(?!vfat\s)\S+\s+(\S+)</ind:pattern>
5050
<ind:instance datatype="int" operation="greater than or equal">1</ind:instance>
5151
</ind:textfilecontent54_object>
5252
<ind:textfilecontent54_state version="1"

linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/rule.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ ocil: |
2424
2525
ocil_clause: "some mounts appear among output lines"
2626

27+
2728
severity: medium
2829

2930
identifiers:
@@ -50,3 +51,16 @@ fixtext: |-
5051
Configure the "/etc/fstab" to use the "nodev" option on all non-root local partitions.
5152
5253
srg_requirement: '{{{ full_name }}} must prevent special devices on non-root local partitions.'
54+
55+
warnings:
56+
- general: |-
57+
This rule checks only local partitions, identified as those backed by
58+
a device node in <tt>/dev</tt>. Network file systems such as NFS, CIFS,
59+
GlusterFS and others are excluded because they do not expose local
60+
device nodes. The <tt>/boot</tt> and <tt>/efi</tt> partitions are
61+
excluded because they are special partitions usually handled by a
62+
systemd mount unit, and enforcing <tt>nodev</tt> on them during
63+
operating system installation causes issues. Partitions with the
64+
<tt>vfat</tt> file system type are excluded because vfat does not
65+
support Unix device special files, so <tt>nodev</tt> enforcement on
66+
them is not meaningful.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
. $SHARED/partition.sh
4+
5+
# Add nodev option to all records in fstab to ensure that test will
6+
# run on environment where everything is set correctly for rule check.
7+
cp /etc/fstab /etc/fstab.backup
8+
sed -i -e 's/\bnodev\b/,/g' -e 's/,,//g' -e 's/\s,\s/defaults/g' /etc/fstab.backup
9+
awk '{$4 = $4",nodev"; print}' /etc/fstab.backup > /etc/fstab
10+
# Remount all partitions. (--all option can't be used because it doesn't
11+
# mount e.g. /boot partition
12+
declare -a partitions=( $(awk '{print $2}' /etc/fstab | grep "^/\w") )
13+
for partition in ${partitions[@]}; do
14+
mount -o remount "$partition"
15+
done
16+
17+
# A vfat partition without nodev should be ignored by the rule.
18+
PARTITION="/dev/new_partition1"; create_partition
19+
make_fstab_given_partition_line "/tmp/partition1" vfat defaults

0 commit comments

Comments
 (0)