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 1913962 - "dnf needs-restarting -r" work incorrectly inside systemd-nspawn containers
Summary: "dnf needs-restarting -r" work incorrectly inside systemd-nspawn containers
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: dnf-plugins-core
Version: 8.3
Hardware: Unspecified
OS: Unspecified
medium
high
Target Milestone: rc
: 8.0
Assignee: Nicola Sella
QA Contact: Jan Blazek
URL:
Whiteboard:
Depends On: 1951414
Blocks:
TreeView+ depends on / blocked
 
Reported: 2021-01-07 21:06 UTC by Gena Makhomed
Modified: 2021-11-10 09:33 UTC (History)
5 users (show)

Fixed In Version: dnf-plugins-core-4.0.21-1.el8
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2021-11-09 19:52:16 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHSA-2021:4464 0 None Waiting on Red Hat lost/broken network ip conectivity in windows guests, while guest agent update. 2022-04-23 22:37:26 UTC

Internal Links: 1914251 2137935

Description Gena Makhomed 2021-01-07 21:06:02 UTC
Description of problem:

"dnf needs-restarting -r" work incorrectly inside systemd-nspawn containers

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

binary: python3-dnf-plugins-core-4.0.17-5.el8.noarch.rpm
source: dnf-plugins-core-4.0.17-5.el8.src.rpm

How reproducible:

always

Steps to Reproduce:

1. Install RHEL 8.3 / CentOS 8.3 on host, install systemd-container package on host:

dnf install systemd-container

2. Install RHEL 8.3 / CentOS 8.3 inside systemd-nspawn container:

yum --installroot=/var/lib/machines/test --releasever=8 install dnf python3-dnf-plugins-core systemd

3. start container test:

machinectl start test

4. enter inside container test:

machinectl shell test

5. check if container needs restarting:

dnf needs-restarting -r

Actual results:

# dnf needs-restarting -r
Core libraries or services have been updated since boot-up:
  * dbus
  * dbus-daemon
  * glibc
  * systemd

Reboot is required to fully utilize these updates.

Expected results:

# dnf needs-restarting -r
No core libraries or services have been updated since boot-up.
Reboot should not be necessary.

Additional info:

Cause of bug located in file:

/usr/lib/python3.6/site-packages/dnf-plugins/needs_restarting.py

Linus Torvalds say: "Talk is cheap. Show me the code".

Ok.

Patch to solve this bug:

After this patch - command "dnf needs-restarting -r" will work correctly
inside and outside systemd-nspawn containers.

The first process start time could be used as container/host start time:

 int(os.stat('/proc/1/cmdline').st_mtime)

/proc/1/cmdline is a virtual file in the procfs, whose creation date is the same 
as the container creation date or linux host boot time, if no containers is used.

--- needs_restarting.py.orig    2020-08-12 00:06:14.000000000 +0300
+++ needs_restarting.py 2021-01-07 22:27:20.779006509 +0200
@@ -174,11 +174,7 @@

     @staticmethod
     def get_boot_time():
-        with open('/proc/stat') as stat_file:
-            for line in stat_file.readlines():
-                if not line.startswith('btime '):
-                    continue
-                return int(line[len('btime '):].strip())
+        return int(os.stat('/proc/1/cmdline').st_mtime)

     @staticmethod
     def get_sc_clk_tck():

Comment 1 Nicola Sella 2021-01-13 10:01:46 UTC
Hello, thanks for the detailed explanation and solution proposed.

I am trying to reproduce the bug, but I am getting an error

$ machinectl start test
Job for systemd-nspawn failed because the control process exited with error code.
See "systemctl status systemd-nspawn" and "journalctl -xe" for details.

The error is related to SELinux policies, so I have to set SELinux Permissive to get through this error. Then, the bug seems reproducible. 
Do you have any specific SELinux configuration? I would like to reproduce it with your configuration if possible.

Thank you

Comment 2 Gena Makhomed 2021-01-13 11:42:00 UTC
(In reply to nsella from comment #1)
> I am trying to reproduce the bug, but I am getting an error
> 
> $ machinectl start test
> Job for systemd-nspawn failed because the control process
> exited with error code.
> See "systemctl status systemd-nspawn" and "journalctl -xe" for
> details.
> 
> The error is related to SELinux policies, so I have to set SELinux
> Permissive to get through this error. Then, the bug seems reproducible. 
> Do you have any specific SELinux configuration? I would like to reproduce it
> with your configuration if possible.

Yes, sorry, I forgot to write about SELinux.

I reproduce this bug with SELinux disabled:

1. Install RHEL 8.3 / CentOS 8.3 on host, install systemd-container package on host:

dnf install systemd-container

1.1. disable SELinux in /etc/selinux/config, write SELINUX=disabled

1.2. reboot

2. Install RHEL 8.3 / CentOS 8.3 inside systemd-nspawn container:

dnf --installroot=/var/lib/machines/test --releasever=8 install dnf python3-dnf-plugins-core systemd

...

Comment 3 Nicola Sella 2021-01-13 15:14:01 UTC
I added a PR with your patch
https://github.com/rpm-software-management/dnf-plugins-core/pull/422

Comment 12 errata-xmlrpc 2021-11-09 19:52:16 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (Moderate: dnf security and bug fix update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2021:4464


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