Bug 1748840

Summary: script generated by systemd-fstab-generator which is mounting a plain file under /tmp can start tmp.mount
Product: Red Hat Enterprise Linux 8 Reporter: Yongcheng Yang <yoyang>
Component: systemdAssignee: David Tardon <dtardon>
Status: CLOSED ERRATA QA Contact: Frantisek Sumsal <fsumsal>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 8.0CC: dtardon, systemd-maint-list, xzhou
Target Milestone: rcKeywords: Reopened, Reproducer
Target Release: 8.2Flags: msekleta: mirror+
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: 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: 1708794    

Description Yongcheng Yang 2019-09-04 09:30:37 UTC
Description of problem:
If trying to loop mount a plain file, the OS will perform `losetup` automaticly in the backgroud. And that's okay.
But if that entry is added into /etc/fstab and execute `systemctl daemon-reload`, the newly created xxx.mount script generated by systemd-fstab-generator could start tmp.mount (which is disabled by default) leading the /tmp over-mounted!

Version-Release number of selected component (if applicable):
systemd-239-17.el8.x86_64

How reproducible:
always easily

Steps to Reproduce:
0. truncate --size 1G /tmp/test_img && mkfs -t xfs /tmp/test_img && mkdir -p /test
1. echo "/tmp/test_img  /test  xfs  defaults  0 0" >> /etc/fstab
2. systemctl daemon-reload
3. systemctl start /test


Actual results:
[root.0~]# tail -1 /etc/fstab 
/tmp/test_img  /test  xfs  defaults  0 0
[root.0~]# mount /test
[root.0~]# losetup 
NAME       SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE     DIO LOG-SEC
/dev/loop0         0      0         1  0 /tmp/test_img   0     512
[root.0~]# umount /test
[root.0~]# losetup 
[root.0~]# systemctl daemon-reload
[root.0~]# systemctl cat /test/
# /run/systemd/generator/test.mount
# Automatically generated by systemd-fstab-generator

[Unit]
SourcePath=/etc/fstab
Documentation=man:fstab(5) man:systemd-fstab-generator(8)
Before=local-fs.target

[Mount]
Where=/test
What=/tmp/test_img        <<<<<<<<<<
Type=xfs
[root.0~]# df -h /tmp
Filesystem                              Size  Used Avail Use% Mounted on
/dev/mapper/rhel_ibm--x3250m4--07-root   50G  3.2G   47G   7% / <<<<<<<<
[root.0~]# systemctl start /test/
Job for test.mount failed.
See "systemctl status test.mount" and "journalctl -xe" for details.
[root.0~]# df -h /tmp
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           1.9G     0  1.9G   0% /tmp               <<<<<<<<<<<<<<
[root.0~]# 
[root.0~]# systemctl stop tmp.mount
[root.0~]# df -h /tmp
Filesystem                              Size  Used Avail Use% Mounted on
/dev/mapper/rhel_ibm--x3250m4--07-root   50G  3.2G   47G   7% /


Expected results:
/tmp should not be over-mounted


Additional info:
 - This problem only occurs since 8.0.0 and does't reproduce in rhel7 now
 - It works if switching plain file to loop device directly
   E.g.
   ~~~~~~~~~~~~~~
   [root.0~]# systemctl daemon-reload
   [root.0~]# systemctl cat /test/
   # /run/systemd/generator/test.mount
   # Automatically generated by systemd-fstab-generator
   
   [Unit]
   SourcePath=/etc/fstab
   Documentation=man:fstab(5) man:systemd-fstab-generator(8)
   Before=local-fs.target
   
   [Mount]
   Where=/test
   What=/dev/loop0        <<<<<<<<<<<<
   Type=xfs
   [root.0~]# df -h /tmp
   Filesystem                              Size  Used Avail Use% Mounted on
   /dev/mapper/rhel_ibm--x3250m4--07-root   50G  3.2G   47G   7% /
   [root.0~]# systemctl start /test/
   [root.0~]# df -h /tmp
   Filesystem                              Size  Used Avail Use% Mounted on
   /dev/mapper/rhel_ibm--x3250m4--07-root   50G  3.2G   47G   7% /
   [root.0~]# umount /test/
   [root.0~]# 
   ~~~~~~~~~~~~~~

Comment 1 Yongcheng Yang 2019-09-04 09:35:16 UTC
*** Bug 1653207 has been marked as a duplicate of this bug. ***

Comment 2 Yongcheng Yang 2019-09-05 06:24:45 UTC
Have just checked this problem can only be triggered when mounting plain file resides in the directory /tmp/
~~~~~~~~~~~~~~~~~~~~~~~~~~~
# systemctl start /test
# df -h /tmp/
Filesystem                              Size  Used Avail Use% Mounted on
/dev/mapper/rhel_ibm--x3250m4--07-root   50G  3.2G   47G   7% /
# systemctl cat /test
# /run/systemd/generator/test.mount
# Automatically generated by systemd-fstab-generator

[Unit]
SourcePath=/etc/fstab
Documentation=man:fstab(5) man:systemd-fstab-generator(8)
Before=local-fs.target

[Mount]
Where=/test
What=/root/test_img                            <<<<<<<<<<
Type=xfs
# losetup
NAME       SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE      DIO LOG-SEC
/dev/loop0         0      0         1  0 /root/test_img   0     512

Comment 3 David Tardon 2020-01-14 17:46:32 UTC
The result might be a bit surprising, but there is no bug here. The generator adds /root/test_img to test.mount's RequiresMountsFor= (run "systemctl show -p RequiresMountsFor test.mount" to check). Because of this and because there is an active mount unit for /tmp, tmp.mount is added to test.mount's After= when test.mount is loaded ("systemctl show -p After test.mount"). Mask tmp.mount if you don't want this.

Comment 4 David Tardon 2020-01-15 11:41:31 UTC
I didn't realize we already handle this as a special case in RHEL 7. Reopening.

Comment 5 Lukáš Nykrýn 2020-06-08 13:50:53 UTC
fix merged to github master branch -> https://github.com/systemd-rhel/rhel-8/pull/104

Comment 12 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