Bug 2230349

Summary: BLS snippets in /boot/loader/entries are improperly labeled with "module_object_t" SELinux context
Product: Red Hat Enterprise Linux 8 Reporter: Renaud Métrich <rmetrich>
Component: grub2Assignee: Bootloader engineering team <bootloader-eng-team>
Status: NEW --- QA Contact: Release Test Team <release-test-team>
Severity: low Docs Contact:
Priority: low    
Version: 8.8CC: peter.vreman, sbarcomb
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Renaud Métrich 2023-08-09 11:02:24 UTC
Description of problem:

When updating the kernel, the new BLS snippet gets "module_object_t label:
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
# ls -lZ /boot/loader/entries/
[...]
-rw-r--r--. 1 root root system_u:object_r:modules_object_t:s0 371 Jun 29 17:25 9d59a9f41c1642b196990576ac8b7846-4.18.0-477.15.1.el8_8.x86_64.conf
[...]
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------

This is due to copying the "bls.conf" template from the kernel tree without using "-Z" option to "cp", as seen on line 94 of /usr/lib/kernel/install.d/20-grub.install:
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
 93             if [[ -f "${KERNEL_DIR}/bls.conf" ]]; then
 94                 cp -aT "${KERNEL_DIR}/bls.conf" "${BLS_TARGET}" || exit $?
 95             else
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------

Note that RHEL9 implements a different fix using "restorecon", on idea why this complicated code is used:
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
 65                 rm -f "/boot/${i##*/}-${KERNEL_VERSION}"
 66                 cp -aT "$i" "/boot/${i##*/}-${KERNEL_VERSION}"
 67                 command -v restorecon &>/dev/null && \
 68                     restorecon -R "/boot/${i##*/}-${KERNEL_VERSION}"
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------

Version-Release number of selected component (if applicable):

grub2-common-2.02-148.el8.noarch

How reproducible:

Always

Steps to Reproduce:
1. Install a new kernel

Actual results:

Improper context

Expected results:

Proper "boot_t" context