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 1436004 - Unexpected, catastrophic behavior from systemd-tmpfiles
Summary: Unexpected, catastrophic behavior from systemd-tmpfiles
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: systemd
Version: 7.3
Hardware: x86_64
OS: Linux
unspecified
high
Target Milestone: rc
: ---
Assignee: Jan Synacek
QA Contact: Frantisek Sumsal
URL:
Whiteboard:
Depends On:
Blocks: 1546552 1549617 1551061
TreeView+ depends on / blocked
 
Reported: 2017-03-26 16:00 UTC by Tom Kelliher
Modified: 2022-03-13 14:14 UTC (History)
5 users (show)

Fixed In Version: systemd-219-58.el7
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-10-30 11:32:10 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Tom Kelliher 2017-03-26 16:00:08 UTC
Description of problem:

A tmpfiles.d entry of the form

R! /foo/.*

appears to be interpreted by systemd-tmpfiles as something similar to

R! /

destroying the filesystem.

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

219-30.el7_3.7

How reproducible:

Consistently reproducible.

Steps to Reproduce:
1. Create the directory /foo.
2. In /etc/tmpfiles.d create the file foo.conf containing the one line
        R! /foo/.*
3. Reboot.
4. Wait several minutes; the system won't come up to the user login stage.
5. Reboot a second time.

Actual results:

Grub reports that it can't find /grub2/i386-pc/normal.mod and drops into rescue mode.  The filesystem appears to be destroyed.

Expected results:

dot files and directories in /foo/ are (recursively) removed.

Additional info:

None.

Comment 2 Jan Synacek 2017-03-27 07:05:12 UTC
You want to use r! instead of R! if you want to use that glob.

Comment 3 Jan Synacek 2017-03-27 07:50:57 UTC
https://github.com/systemd/systemd/issues/5644

Comment 4 Lukáš Nykrýn 2017-03-27 10:23:40 UTC
The problem here is, that tmpfiles did exactly what you asked then to do.
For glob /foo/.* it will also match /foo/.. which is /.

But I agree that this behavior is kinda dangerous and should be changed.

Comment 5 Tom Kelliher 2017-03-27 12:12:49 UTC
I had forgotten about '..'.  Thanks for enlightening me.  The behavior is kinda dangerous, but entirely consistent.  At the very least, this experience gave me the opportunity to put my dump/restore strategy to the test, during which I came across a bug while restoring a level 1 dump, but that's for another bug report.

Thank you for your responses.

Comment 6 Jan Synacek 2017-03-29 07:05:00 UTC
Merged upstream.

Comment 7 Jan Synacek 2017-03-29 07:32:42 UTC
How to test:

1) # mkdir -p /foo/bar/dir{1,2}
2) # touch /foo/bar/file{1,2}
3) # echo "R /foo/bar/.* - - - - -" > /etc/tmpfiles.d/test.conf
4) # systemd-tmpfiles --remove
5) # ls /foo
/foo will be empty if the bug reproduces.

Comment 8 Jan Synacek 2017-03-29 08:28:03 UTC
A better reproducer...

$ cat rep.sh 
#!/bin/sh

mkdir -p /foo/bar/.dir{1,2}
mkdir -p /foo/bar/dir{3,4}
touch /foo/bar/.file{5,6}
touch /foo/bar/file{7,8}
systemd-tmpfiles --remove
ls -la /foo/bar

The expected input is something like

drwxr-xr-x 4 root root 4096 Mar 29 10:25 .
drwxr-xr-x 3 root root 4096 Mar 29 10:07 ..
drwxr-xr-x 2 root root 4096 Mar 29 10:07 dir3
drwxr-xr-x 2 root root 4096 Mar 29 10:07 dir4
-rw-r--r-- 1 root root    0 Mar 29 10:25 file7
-rw-r--r-- 1 root root    0 Mar 29 10:25 file8

When the bug reproduces, 'ls -la /foo/bar' fails with

ls: cannot access '/foo/bar': No such file or directory

Comment 9 Jan Synacek 2017-04-26 13:22:52 UTC
(In reply to Jan Synacek from comment #6)
> Merged upstream.

My original patch was merged, but it does solve only a small part of the issue. Much better solution is being implemented in https://github.com/systemd/systemd/pull/5809/.

Comment 11 Jan Synacek 2017-05-04 13:11:15 UTC
Backporting the upstream fixes turned out much harder than it looked. Moving to RHEL-7.5.

Comment 15 Jan Synacek 2018-05-28 09:56:21 UTC
https://github.com/lnykryn/systemd-rhel/pull/208

Comment 16 Lukáš Nykrýn 2018-06-21 10:11:25 UTC
fix merged to staging branch -> https://github.com/lnykryn/systemd-rhel/pull/208 -> post

Comment 20 errata-xmlrpc 2018-10-30 11:32:10 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, 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/RHBA-2018:3245


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