Verify Permissions on the GRUB2 Files of the EFI System Partition

Description

The GRUB2 files in /boot/efi/EFI and its subdirectories, which are the files whose names start with grub, such as grub.cfg, grubenv and the grubx64.efi boot loader, and the files named user.cfg, should have mode 0700 or stricter. The EFI system partition is a FAT file system, which takes the mode of its files from its mount options. To set it, add the fmask=0077 option to the /boot/efi entry in /etc/fstab, for example:

UUID=... /boot/efi vfat defaults,umask=0027,fmask=0077,uid=0,gid=0 0 2

and remount the file system.

Rationale

These files hold the boot parameters and the boot loader password hashes. A user who can read them learns the boot settings, which can reveal weaknesses to exploit at boot.

Remediation

Shell script

The following script can be run on the host to remediate the issue.

#!/bin/bash

# Remediation is applicable only in certain platforms
if ( rpm --quiet -q grub2-common && rpm --quiet -q kernel-core ) && { ( ! ( [ -f /.dockerenv ] || [ -f /run/.containerenv ] ) ); }; then

find -P /boot/efi/EFI/  -perm /u+s,g+xwrs,o+xwrt  -type f -regextype posix-extended -regex '^(.*/)?(grub[^/]*|user\.cfg)$' -exec chmod u-s,g-xwrs,o-xwrt {} \;

else
    >&2 echo 'Remediation is not applicable, nothing was done'
fi

Ansible playbook

The following playbook can be run with Ansible to remediate the issue.

- name: Gather the package facts
  package_facts:
    manager: auto
  tags:
  - CCE-88600-2
  - configure_strategy
  - file_permissions_efi_grub2_config_files
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed

- name: Find /boot/efi/EFI/ file(s) recursively
  ansible.builtin.command: find -P /boot/efi/EFI/  -perm /u+s,g+xwrs,o+xwrt  -type
    f -regextype posix-extended -regex "^(.*/)?(grub[^/]*|user\.cfg)$"
  register: files_found
  changed_when: false
  failed_when: false
  check_mode: false
  when:
  - ( "grub2-common" in ansible_facts.packages and "kernel-core" in ansible_facts.packages
    )
  - not ( ansible_virtualization_type in ["docker", "lxc", "openvz", "podman", "container"]
    )
  tags:
  - CCE-88600-2
  - configure_strategy
  - file_permissions_efi_grub2_config_files
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed

- name: Set permissions for /boot/efi/EFI/ file(s)
  ansible.builtin.file:
    path: '{{ item }}'
    mode: u-s,g-xwrs,o-xwrt
    state: file
  with_items:
  - '{{ files_found.stdout_lines }}'
  when:
  - ( "grub2-common" in ansible_facts.packages and "kernel-core" in ansible_facts.packages
    )
  - not ( ansible_virtualization_type in ["docker", "lxc", "openvz", "podman", "container"]
    )
  tags:
  - CCE-88600-2
  - configure_strategy
  - file_permissions_efi_grub2_config_files
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed

Warning

The chmod command of the remediation leaves the mode of the files on a FAT file system as it is. Set the fmask option in /etc/fstab and remount /boot/efi, which may need a reboot.