This bug has been migrated to another issue tracking site. It has been closed here and may no longer be being monitored.

If you would like to get updates for this issue, or to participate in it, you may do so at Red Hat Issue Tracker .
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 2092273 - /boot/grub2/grubenv's timestamp is getting modified continuously due to "boot_success" implementation
Summary: /boot/grub2/grubenv's timestamp is getting modified continuously due to "boot...
Keywords:
Status: CLOSED MIGRATED
Alias: None
Product: Red Hat Enterprise Linux 9
Classification: Red Hat
Component: grub2
Version: 9.0
Hardware: All
OS: Linux
medium
medium
Target Milestone: rc
: ---
Assignee: Bootloader engineering team
QA Contact: Release Test Team
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2022-06-01 08:40 UTC by Renaud Métrich
Modified: 2023-09-16 13:27 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2023-09-16 13:24:19 UTC
Type: Bug
Target Upstream Version:
Embargoed:
pm-rhel: mirror+


Attachments (Terms of Use)
patch to modify grubenv just once per bootflag (914 bytes, patch)
2023-06-27 12:25 UTC, Petr Janda
no flags Details | Diff
patch to modify grubenv just once per bootflag (916 bytes, patch)
2023-06-27 12:34 UTC, Petr Janda
no flags Details | Diff


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker   RHEL-4320 0 None Migrated None 2023-09-16 13:24:15 UTC
Red Hat Issue Tracker RHELPLAN-123855 0 None None None 2022-06-01 08:47:01 UTC
Red Hat Issue Tracker SECENGSP-5111 0 None None None 2023-03-20 10:20:45 UTC

Description Renaud Métrich 2022-06-01 08:40:03 UTC
Description of problem:

We have a customer noticing that the /boot/grub2/grubenv file is getting modified continuously, which raises an alert when executing aide monitoring tool (https://aide.github.io/).
This happens because every time a user logs in and has a session living for more than 2 minutes, the user's grub-boot-success.timer elapses, causing grub-boot-success.service unit to write "boot_success=1" into /boot/grub2/grubenv.

I have several concerns about this feature and the current implementation.

Regarding the feature itself, I understand the idea behind this is to automatically boot on the previous kernel if the newer kernel fails to boot several times in a row.
On RHEL, this doesn't work for many reason:
1. usually the latest kernel fails to boot because the initramfs is broken, which leads to a kernel panic and system sitting there
2. assuming kernel and initramfs boot fine, if the system fails after switch root, it's expected to fail whatever the booted kernel is
3. the feature is not enabled by default since its implementation inside grub.cfg relies on a "boot_counter" variable which isn't set
4. the implementation inside grub.cfg assumes the second menu entry will boot better, which is far from being true: on customer systems it's not rare that kernel updates are performed but no reboot is made in-between, waiting for a "reboot window"
5. it's unclear when a RHEL system should be considered as "booted fine": many systems are acting as services only (e.g. database server) with no user except root connecting to the system

Regarding the implementaion (the grub-boot-success.timer/grub-boot-success.service units) itself, it doesn't work on RHEL in many cases:
1. when there is only a root user accessing the system (because "ConditionUser=!@system" doesn't evaluate to true when uid is 0)
2. if other users are not using the "systemd --user" service, which is usually what we recommend and will be the default in some future for non-graphical installations
3. when users use "lingering" (i.e. starting "systemd --user" service at boot without actually logging into the system): the "boot_success=1" flag will be automatically set after 2 minutes even if users cannot effectively log in
4. there may be a race if 2 users log in concurrently: after 2 minutes, both grub-boot-success.service units will execute concurrently, which may break the grubenv file content if no proper locking is performed (I didn't check the code to confirm/infirm this)

For all these reasons and many more, I think this functionality is not wished on RHEL at all, it may bring more trouble than what it tries to solve.
For sure, if we decide to continue with this, the implementation needs to be enhanced.

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

grub2-tools-minimal since RHEL8

How reproducible:

N/A

Comment 1 Robbie Harwood 2022-06-01 15:05:02 UTC
> We have a customer noticing that the /boot/grub2/grubenv file is getting modified continuously, which raises an alert when executing aide monitoring tool (https://aide.github.io/).

Sounds like the monitoring tool needs to be fixed.

> 1. usually the latest kernel fails to boot because the initramfs is broken, which leads to a kernel panic and system sitting there

No, usually the latest kernel works :)  Otherwise it's a bug that needs to be handled.  Worth noting that the UX won't be better without this feature: the system still won't boot, will still panic and sit there, etc..  In both cases the admin will need to reboot the system again, and in both cases they'll get the menu.

> 3. the feature is not enabled by default since its implementation inside grub.cfg relies on a "boot_counter" variable which isn't set

Well, if it weren't a default, it wouldn't be a problem :)  That variable is controlled by grub itself - see 12_menu_auto_hide, 10_reset_boot_success, grub-set-bootflag.

> 5. it's unclear when a RHEL system should be considered as "booted fine": many systems are acting as services only (e.g. database server) with no user except root connecting to the system

We're not interested in whether user space works perfectly.  We're interested in whether we can *get* to user-space.  Boot success is defined as successfully running a session as a non-root user for > 2 minutes (or manually rebooted from gdm) - otherwise it's indeterminate, and we'll show the screen.

> 4. there may be a race if 2 users log in concurrently: after 2 minutes, both grub-boot-success.service units will execute concurrently, which may break the grubenv file content if no proper locking is performed (I didn't check the code to confirm/infirm this)

This race should be harmless - they'll both record a success state.

Comment 2 Renaud Métrich 2022-06-07 06:04:31 UTC
(In reply to Robbie Harwood from comment #1)
> > We have a customer noticing that the /boot/grub2/grubenv file is getting modified continuously, which raises an alert when executing aide monitoring tool (https://aide.github.io/).
> 
> Sounds like the monitoring tool needs to be fixed.

Nope, it's Grub that needs to be fixed: the /boot/grub2/grubenv file should be modified only in rare occasions (through kernel update or administration commands).

> 
> > 1. usually the latest kernel fails to boot because the initramfs is broken, which leads to a kernel panic and system sitting there
> 
> No, usually the latest kernel works :)  Otherwise it's a bug that needs to
> be handled.  Worth noting that the UX won't be better without this feature:
> the system still won't boot, will still panic and sit there, etc..  In both
> cases the admin will need to reboot the system again, and in both cases
> they'll get the menu.
> 
> > 3. the feature is not enabled by default since its implementation inside grub.cfg relies on a "boot_counter" variable which isn't set
> 
> Well, if it weren't a default, it wouldn't be a problem :)  That variable is
> controlled by grub itself - see 12_menu_auto_hide, 10_reset_boot_success,
> grub-set-bootflag.

I mean setting "boot_success" has no impact by default: with or without it with RHEL /dev/default/grub settings, nothing special happens while in the Grub menu:
having grub_success just sets "menu_hide_ok" which isn't taking action when we have a serial console (usually in use with servers) or we don't have GRUB_HIDDEN_TIMEOUT_* variables.

> 
> > 5. it's unclear when a RHEL system should be considered as "booted fine": many systems are acting as services only (e.g. database server) with no user except root connecting to the system
> 
> We're not interested in whether user space works perfectly.  We're
> interested in whether we can *get* to user-space.  Boot success is defined
> as successfully running a session as a non-root user for > 2 minutes (or
> manually rebooted from gdm) - otherwise it's indeterminate, and we'll show
> the screen.
> 

OK then it's not correct to rely on a user session to do this, this should be done by a "system service" pulled by multi-user.target, this service may be triggered by a timer.
Note that on server systems, having "systemd --user" instance is optional and we recommend our users to disable this service.

> > 4. there may be a race if 2 users log in concurrently: after 2 minutes, both grub-boot-success.service units will execute concurrently, which may break the grubenv file content if no proper locking is performed (I didn't check the code to confirm/infirm this)
> 
> This race should be harmless - they'll both record a success state.

At least the tool should check if flag is not already present and modify the file only if that's not the case.

Also it's not acceptable on servers to have grub2-set-bootflag be able to modify the timeout for the menu while logged in as a normal user, only administrators should be able to do this.

Comment 4 raravind 2023-02-06 19:41:34 UTC
Hi Suresh,

It is working as expected.Reason - As Robbie said in comment#1 ,the grubenv file is used to store boot success and other grub information. grub-boot-success.timer will run two minutes after non-root user logins. This timer calls grub-boot-success.service which sets the boot success flag within the environment block.

Also possible that with monitoring tools like AIDE ,it is likely that the modification time of the "/boot/grub2/grubenv" file is being recorded even if none made any changes to it.May be the monitoring tool is designed to track changes to all files on the system, regardless of whether they have been modified by the user or by other processes?

Comment 5 Marta Lewandowska 2023-03-20 10:05:33 UTC
Switching component to aide based on comment#1

Comment 6 Renaud Métrich 2023-03-20 10:20:03 UTC
IMHO the issue is not with "aide" but Grub2, which, as I already wrote previously, updates CONSTANTLY the file while it should be smarter and update only once ("check boot success flag is set? return, otherwise set it").

Comment 7 Marta Lewandowska 2023-03-20 11:36:21 UTC
Hi Renaud,
yeah, I know. :) Since Robbie disagrees with you, perhaps the way forward is to engage with aide devels.

Comment 9 Renaud Métrich 2023-06-23 06:48:28 UTC
I'm switching this back to Grub, because the issue is clearly with the implementation of the "Boot Success" functionality.

The tool HAS to be smart, and do the update only when necessary, hence modify grubenv only if there is a change.

aide as such is not culprit and cannot be fixed, it depends on the aide configuration created by the user.
To me, it's completely legit to monitor changed in /boot/grub2/grubenv because this indicates a potential tampering.

I would like a decision to be taken about this bug, it's open for too long time.

Renaud.

Comment 10 Petr Janda 2023-06-27 12:25:35 UTC
Created attachment 1972823 [details]
patch to modify grubenv just once per bootflag

Comment 11 Petr Janda 2023-06-27 12:31:19 UTC
If it is enough to modify grubenv only once per bootflag when an user is logged in, see attached patch.

Just want to comment this:
> 4. there may be a race if 2 users log in concurrently: after 2 minutes, both
> grub-boot-success.service units will execute concurrently, which may break
> the grubenv file content if no proper locking is performed (I didn't check
> the code to confirm/infirm this)

According my understanding of code, it is possible that the grubenv will be changed twice in very short time period, but won't be corrupted. Every instance of service creates its own tempfile and then use rename syscall and it is atomic on Linux.

Comment 12 Petr Janda 2023-06-27 12:34:19 UTC
Created attachment 1972824 [details]
patch to modify grubenv just once per bootflag

wrong patch adding correct one

Comment 13 RHEL Program Management 2023-09-16 13:23:44 UTC
Issue migration from Bugzilla to Jira is in process at this time. This will be the last message in Jira copied from the Bugzilla bug.

Comment 14 RHEL Program Management 2023-09-16 13:24:19 UTC
This BZ has been automatically migrated to the issues.redhat.com Red Hat Issue Tracker. All future work related to this report will be managed there.

Due to differences in account names between systems, some fields were not replicated.  Be sure to add yourself to Jira issue's "Watchers" field to continue receiving updates and add others to the "Need Info From" field to continue requesting information.

To find the migrated issue, look in the "Links" section for a direct link to the new issue location. The issue key will have an icon of 2 footprints next to it, and begin with "RHEL-" followed by an integer.  You can also find this issue by visiting https://issues.redhat.com/issues/?jql= and searching the "Bugzilla Bug" field for this BZ's number, e.g. a search like:

"Bugzilla Bug" = 1234567

In the event you have trouble locating or viewing this issue, you can file an issue by sending mail to rh-issues. You can also visit https://access.redhat.com/articles/7032570 for general account information.


Note You need to log in before you can comment on or make changes to this bug.