Bug 193094 - 'mount' mounts wrong filesystem with bind mounts
'mount' mounts wrong filesystem with bind mounts
Product: Fedora
Classification: Fedora
Component: util-linux (Show other bugs)
All Linux
medium Severity medium
: ---
: ---
Assigned To: Karel Zak
Ben Levenson
Depends On:
  Show dependency treegraph
Reported: 2006-05-25 03:53 EDT by Avi Kivity
Modified: 2008-03-09 06:30 EDT (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2006-08-21 11:29:59 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
fix - ignore device nodes that are regular files or directories (891 bytes, patch)
2006-05-25 03:53 EDT, Avi Kivity
no flags Details | Diff

  None (edit)
Description Avi Kivity 2006-05-25 03:53:09 EDT
Description of problem:

mount can accept either a device node or a mountpoint if the filesystem is 
in /etc/fstab. unfortunately, with bind (and loop) mounts, a file or directory 
can appear as both the device node or the mountpoint (in different entries), 
making a simple 'mount /blah' ambiguous.

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

How reproducible:
$ grep /test /etc/fstab
/dev/VolGroup00/tmp     /test                   ext3    defaults        0 0
/test                   /test1                  none    bind            0 0

$ sudo mount /test

-> /test1 mounted instead of /test.

Steps to Reproduce:
1. have a filesystem in /fstab also be the source of a bind mount
2. try to mount it
Actual results:
the bind mount is mounted instead of the filesystem

Expected results:
filesystem mounted

bind mounts are important for nfs4 exports and for setting chrooted 
environments (FC5-in-FC4, etc.)
Comment 1 Avi Kivity 2006-05-25 03:53:09 EDT
Created attachment 129975 [details]
fix - ignore device nodes that are regular files or directories
Comment 2 Karel Zak 2006-08-21 11:29:59 EDT
It's not so simple. Your patch completely disable mount by /path/file.img for
loop devices. You also forget that no all people use ambiguous configuration and
use bind mount by source directories is fine for them. 

I think rather than add to code some non-transparent heuristic is better use for
example mount by LABEL/UUID/device for your /dev/VolGroup00/tmp.
Comment 3 Avi Kivity 2006-08-21 11:50:05 EDT
bind mounts cannot use LABEL/UUID/device.

Perhaps disambiguate by using a prefix:

mount device:/path/file.img   # by device
mount /dev/devicenode         # by device
mount /path/mountpoint        # by mountpoint


I can do the patch.
Comment 4 Karel Zak 2006-08-21 12:04:45 EDT
Well, I didn't talk about LABEL/UUID/device for bind mount. Let's use:

  mount /dev/VolGroup00/tmp  (or mount LABEL=foo)

when you need mount the device and

  mount /test1  (or mount /test, because the mount checks fs_spec before fs_file)

when you need bind mount. 
Comment 5 Avi Kivity 2006-08-21 12:08:31 EDT
This removes the ambiguity for the case I mentioned, but is ambiguous for 

The core problem is that

# mount x

will match two lines in /etc/fstab (or /etc/mtab):

x blah
blah x

unless we disambiguate, somebody will hit this.  I know I did, and silently 
unexpected behavior with mount/umount can easily be disasterous.
Comment 6 vikram goyal 2008-03-09 06:30:49 EDT
*** Bug 242935 has been marked as a duplicate of this bug. ***

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