Bug 1796128

Summary: Lazy setup of inotify_fd in sd-journal may cause clients to leak file descriptors
Product: Red Hat Enterprise Linux 8 Reporter: Michal Sekletar <msekleta>
Component: systemdAssignee: Michal Sekletar <msekleta>
Status: CLOSED ERRATA QA Contact: Frantisek Sumsal <fsumsal>
Severity: medium Docs Contact:
Priority: high    
Version: 8.0CC: igreen, lnykryn, systemd-maint-list, tmanor
Target Milestone: rcKeywords: ZStream
Target Release: 8.0Flags: pm-rhel: mirror+
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1812889 1826216 1826217 (view as bug list) Environment:
Last Closed: 2020-11-04 02:02:06 UTC 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:
Bug Depends On:    
Bug Blocks: 1825061, 1826216, 1826217    

Description Michal Sekletar 2020-01-29 16:48:12 UTC
Description of problem:
$subject

Version-Release number of selected component (if applicable):
systemd-239-18.el8_1.1

How reproducible:
always

Steps to Reproduce:
1) run the reproducer script

#!/usr/bin/python3

from systemd import journal
from os import listdir,readlink
from subprocess import run

def list_fds():
    for fd in listdir("/proc/self/fd"):
        try:
            print(f"    {fd} -> {readlink('/proc/self/fd/' + fd)}")
        except FileNotFoundError as e:
            pass
devnull = open("/dev/null", "w")

print("Rotate journal 3 times")
for i in range(3):
    run(["journalctl", "--rotate"], stdout=devnull, stderr=devnull)

print("Open journal")
r = journal.Reader()

print("List fds")
list_fds()

print("Delete some journal files")
run(["journalctl", "--vacuum-files", "1"], stdout=devnull, stderr=devnull)

print("Process journal events")
r.process()

print("List fds")
list_fds()

Actual results:
Deleted files are opened by the client process.

Expected results:
No deleted files are opened.

Additional info:
Thanks to Ilan Green for bringing this issue to our attention.

Comment 15 Lukáš Nykrýn 2020-04-15 17:17:41 UTC
fix merged to github master branch -> https://github.com/systemd-rhel/rhel-8/pull/78

Comment 23 errata-xmlrpc 2020-11-04 02:02:06 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 (Low: systemd security, bug fix, and enhancement 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-2020:4553