Bug 491924 - avoid using /proc/mounts, use /proc/self/mountinfo instead
avoid using /proc/mounts, use /proc/self/mountinfo instead
Status: CLOSED RAWHIDE
Product: Fedora
Classification: Fedora
Component: DeviceKit-disks (Show other bugs)
rawhide
All Linux
low Severity medium
: ---
: ---
Assigned To: David Zeuthen
Fedora Extras Quality Assurance
:
Depends On:
Blocks: F11Blocker/F11FinalBlocker
  Show dependency treegraph
 
Reported: 2009-03-24 12:49 EDT by Matthias Clasen
Modified: 2013-03-05 22:58 EST (History)
7 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2009-04-07 00:43:53 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:


Attachments (Terms of Use)

  None (edit)
Description Matthias Clasen 2009-03-24 12:49:03 EDT
I filed a bug blaming gnome-disk-utility for getting mountpoints wrong ( http://bugzilla.gnome.org/show_bug.cgi?id=576341 ). But it turns out that this caused by xguest badly messing up /proc/mounts. 

Without xguest installed, this is what my /proc/mounts looks like:

rootfs / rootfs rw 0 0
/dev/root / ext4 rw,barrier=1,data=ordered 0 0
/dev /dev tmpfs rw,mode=755 0 0
/proc /proc proc rw 0 0
/sys /sys sysfs rw 0 0
none /selinux selinuxfs rw 0 0
/proc/bus/usb /proc/bus/usb usbfs rw 0 0
devpts /dev/pts devpts rw,gid=5,mode=620,ptmxmode=000 0 0
/dev/sda3 /other ext4 rw,barrier=1,data=ordered 0 0
/dev/sda2 /home ext4 rw,barrier=1,data=ordered 0 0
/dev/sda1 /boot ext3 rw,errors=continue,user_xattr,acl,data=ordered 0 0
tmpfs /dev/shm tmpfs rw 0 0
none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0
sunrpc /var/lib/nfs/rpc_pipefs rpc_pipefs rw 0 0
gvfs-fuse-daemon /home/mclasen/.gvfs fuse.gvfs-fuse-daemon rw,nosuid,nodev,user_id=500,group_id=500 0 0


With xguest installed, I get the following: 

rootfs / rootfs rw 0 0
/dev/root / ext4 rw,barrier=1,data=ordered 0 0
/dev /dev tmpfs rw,mode=755 0 0
/proc /proc proc rw 0 0
/sys /sys sysfs rw 0 0
none /selinux selinuxfs rw 0 0
/proc/bus/usb /proc/bus/usb usbfs rw 0 0
devpts /dev/pts devpts rw,gid=5,mode=620,ptmxmode=000 0 0
/dev/sda3 /other ext4 rw,barrier=1,data=ordered 0 0
/dev/sda2 /home ext4 rw,barrier=1,data=ordered 0 0
/dev/sda1 /boot ext3 rw,errors=continue,user_xattr,acl,data=ordered 0 0
tmpfs /dev/shm tmpfs rw 0 0
none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0
/dev/root /tmp ext4 rw,barrier=1,data=ordered 0 0
/dev/root /var/tmp ext4 rw,barrier=1,data=ordered 0 0
/dev/sda2 /home/xguest ext4 rw,barrier=1,data=ordered 0 0
sunrpc /var/lib/nfs/rpc_pipefs rpc_pipefs rw 0 0
gvfs-fuse-daemon /home/mclasen/.gvfs fuse.gvfs-fuse-daemon rw,nosuid,nodev,user_id=500,group_id=500 0 0


Notice how /dev/root shows up three times and /dev/sda2 two times.
This has the potential to make everything that looks at /proc/mounts stumble.
Since we decided to put xguest in the default install, this is pretty bad.
Comment 1 Bill Nottingham 2009-03-24 13:52:44 EDT
Could gnome-mount use /proc/self/mountinfo (which may or may not be better)?
Comment 2 Matthias Clasen 2009-03-24 14:47:29 EDT
gnome-mount is not involved here. 
I hope you agree that the /proc/mounts output I present above is just broken and needs to be fixed ?
Comment 3 Bill Nottingham 2009-03-24 14:50:07 EDT
Sorry, meant gnome-disk-utility.

I suspect the /proc/mounts stuff would have to be fixed in the kernel, as it appears that any bind mount triggers it.
Comment 4 Daniel Walsh 2009-03-24 15:17:40 EDT
xguest is executing


        touch $LOCKFILE
        mount --make-rshared /
        mount --bind /tmp /tmp
        mount --bind /var/tmp /var/tmp
        mount --bind /home/xguest /home/xguest
        mount --make-private /home/xguest
        mount --make-private /tmp
        mount --make-private /var/tmp
        RETVAL=$?


On boot,  This is probably what you are seeing.
Comment 5 David Zeuthen 2009-03-24 15:50:07 EDT
(In reply to comment #1)
> Could gnome-mount use /proc/self/mountinfo (which may or may not be better)?  

No, it is devkit-disks-daemon (a system-wide daemon) that reads /proc/mounts.
Comment 6 Daniel Walsh 2009-03-24 15:56:38 EDT
Considering we suport various namespaces I am not sure if this will every be right.
Comment 7 David Zeuthen 2009-03-24 16:58:43 EDT
(In reply to comment #3)
> I suspect the /proc/mounts stuff would have to be fixed in the kernel, as it
> appears that any bind mount triggers it.  

IIRC the way /proc/mounts work is that the first argument of the mount(2) syscall

       int mount(const char *source, const char *target,
                 const char *filesystemtype, unsigned long mountflags,
                 const void *data);

e.g. @source is what is displayed in /proc/mounts. And I think you can just pass any kind of garbage in and then it is displayed in /proc/mounts. Hallelujah. Yes, ideally we'd have a better way to discover mounts than /proc/mounts but we don't so there you go.

It's probably worth running strace(1) to see what mount(1) passes when doing the mount(2) syscall. My bet is that is passes in /dev/root and there is the bug. It should probably pass in "none" or "bind" or something else.
Comment 8 Bill Nottingham 2009-03-24 17:12:23 EDT
/proc/self/mountinfo is arguably a better way. But it has its own quirks, and you'd have to write a custom parser, as you can't use getmntent() on it.
Comment 9 David Zeuthen 2009-03-24 17:19:19 EDT
(In reply to comment #8)
> /proc/self/mountinfo is arguably a better way. But it has its own quirks, and
> you'd have to write a custom parser, as you can't use getmntent() on it.  

Maybe we should use that, I wasn't aware it was merged yet (I was only aware people were bitching about /proc/mounts being insufficient); do you happen to know when this was merged?

Matthias, what is the output of 'cat /proc/self/mountinfo' (when logged in at VT1 as root) with xguest installed?
Comment 10 Bill Nottingham 2009-03-24 17:31:02 EDT
According to Alex on IRC, it was merged in 2.6.26.
Comment 11 David Zeuthen 2009-03-24 17:34:36 EDT
(In reply to comment #9)
> Matthias, what is the output of 'cat /proc/self/mountinfo' (when logged in at
> VT1 as root) with xguest installed?  

Never mind, did it myself

# cat /proc/mounts 
rootfs / rootfs rw 0 0
/dev/root / ext3 rw,errors=continue,data=ordered 0 0
/dev /dev tmpfs rw,mode=755 0 0
/proc /proc proc rw 0 0
/sys /sys sysfs rw 0 0
none /selinux selinuxfs rw 0 0
/proc/bus/usb /proc/bus/usb usbfs rw 0 0
devpts /dev/pts devpts rw,gid=5,mode=620,ptmxmode=000 0 0
tmpfs /dev/shm tmpfs rw 0 0
none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0
gvfs-fuse-daemon /home/davidz/.gvfs fuse.gvfs-fuse-daemon rw,nosuid,nodev,user_id=500,group_id=500 0 0
/dev/root /tmp ext3 rw,errors=continue,data=ordered 0 0
/dev/root /var/tmp ext3 rw,errors=continue,data=ordered 0 0
/dev/root /home/xguest ext3 rw,errors=continue,data=ordered 0 0

# cat /proc/self/mountinfo 
19 1 8:1 / / rw shared:1 - ext3 /dev/root rw,errors=continue,data=ordered
20 19 0:15 / /dev rw shared:2 - tmpfs /dev rw,mode=755
21 19 0:3 / /proc rw shared:5 - proc /proc rw
22 19 0:0 / /sys rw shared:8 - sysfs /sys rw
23 19 0:13 / /selinux rw shared:9 - selinuxfs none rw
16 21 0:14 / /proc/bus/usb rw shared:6 - usbfs /proc/bus/usb rw
24 20 0:10 / /dev/pts rw shared:3 - devpts devpts rw,gid=5,mode=620,ptmxmode=000
25 20 0:16 / /dev/shm rw shared:4 - tmpfs tmpfs rw
26 21 0:17 / /proc/sys/fs/binfmt_misc rw shared:7 - binfmt_misc none rw
15 19 0:18 / /home/davidz/.gvfs rw,nosuid,nodev shared:10 - fuse.gvfs-fuse-daemon gvfs-fuse-daemon rw,user_id=500,group_id=500
17 19 8:1 /tmp /tmp rw - ext3 /dev/root rw,errors=continue,data=ordered
18 19 8:1 /var/tmp /var/tmp rw - ext3 /dev/root rw,errors=continue,data=ordered
27 19 8:1 /home/xguest /home/xguest rw - ext3 /dev/root rw,errors=continue,data=ordered
Comment 12 David Zeuthen 2009-03-24 17:41:04 EDT
Relevant docs: 

http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/filesystems/proc.txt;h=830bad7cce0f946ba356e7aff283775d270063f1#l2229

So basically, I think, we should just ignore all mounts for where field 4 (root) != '/'. Will have to look closer into whether that's right.
Comment 13 David Zeuthen 2009-03-24 17:44:09 EDT
Reassigning to DeviceKit-disks so I can fix it there.

It might be worth considering what else xguest breaks - I think most other things (such as GVfs) is using /proc/mounts since /proc/self/mountinfo is somewhat recent.
Comment 14 David Zeuthen 2009-03-24 17:49:18 EDT
(In reply to comment #13)
> Reassigning to DeviceKit-disks so I can fix it there.
> 
> It might be worth considering what else xguest breaks - I think most other
> things (such as GVfs) is using /proc/mounts since /proc/self/mountinfo is
> somewhat recent.  

Actually GVfs is still using /etc/mtab which has yet another set of issues; see

http://bugzilla.gnome.org/show_bug.cgi?id=522053
Comment 15 Matthias Clasen 2009-03-24 17:59:31 EDT
David, if I manually do a mount --bind /foo /bar, I get an entry with root == '/' in /proc/self/mountinfo, so that seems not really watertight.

It seems ironic that /etc/mtab is the one that gets this right, since it shows
/foo /bar none rw,bind 0 0
so bind mounts are recognizable there.
Comment 16 David Zeuthen 2009-03-24 18:07:10 EDT
(In reply to comment #15)
> David, if I manually do a mount --bind /foo /bar, I get an entry with root ==
> '/' in /proc/self/mountinfo, so that seems not really watertight.

I think you messed up Matthias. This seems fine to me, see [1], field 4 is not '/'. Please check again.

[1] :

# mkdir /foo
# mkdir /bar
# mount -obind /foo /bar
# cat /proc/self/mountinfo 
19 1 8:1 / / rw shared:1 - ext3 /dev/root rw,errors=continue,data=ordered
20 19 0:15 / /dev rw shared:2 - tmpfs /dev rw,mode=755
21 19 0:3 / /proc rw shared:5 - proc /proc rw
22 19 0:0 / /sys rw shared:8 - sysfs /sys rw
23 19 0:13 / /selinux rw shared:9 - selinuxfs none rw
16 21 0:14 / /proc/bus/usb rw shared:6 - usbfs /proc/bus/usb rw
24 20 0:10 / /dev/pts rw shared:3 - devpts devpts rw,gid=5,mode=620,ptmxmode=000
25 20 0:16 / /dev/shm rw shared:4 - tmpfs tmpfs rw
26 21 0:17 / /proc/sys/fs/binfmt_misc rw shared:7 - binfmt_misc none rw
15 19 0:18 / /home/davidz/.gvfs rw,nosuid,nodev shared:10 - fuse.gvfs-fuse-daemon gvfs-fuse-daemon rw,user_id=500,group_id=500
17 19 8:1 /foo /bar rw shared:1 - ext3 /dev/root rw,errors=continue,data=ordered
Comment 17 Matthias Clasen 2009-03-24 18:12:01 EDT
Btw, the theory in comment 7 turns out to be wrong.
stracing a  mount --bind /foo /bar call shows that it does in fact call

mount("/foo", "/bar", 0x7fedc6bd8900, MS_MGC_VAL|MS_BIND, NULL) = 0

And still, the /proc/self/mountinfo entry shows /dev/sda3 instead of /foo
Comment 18 Matthias Clasen 2009-03-24 18:21:07 EDT
Here is my version:

[root@planemask]# mkdir /foo
[root@planemask]# mkdir /bar
[root@planemask]# mount /dev/sda3 /foo
[root@planemask]# mount --bind /foo /bar
[root@planemask]# cat /proc/self/mountinfo 
19 1 8:5 / / rw shared:1 - ext4 /dev/root rw,barrier=1,data=ordered
20 19 0:15 / /dev rw shared:2 - tmpfs /dev rw,mode=755
21 19 0:3 / /proc rw shared:5 - proc /proc rw
22 19 0:0 / /sys rw shared:8 - sysfs /sys rw
23 19 0:13 / /selinux rw shared:9 - selinuxfs none rw
16 21 0:14 / /proc/bus/usb rw shared:6 - usbfs /proc/bus/usb rw
24 20 0:10 / /dev/pts rw shared:3 - devpts devpts rw,gid=5,mode=620,ptmxmode=000
26 19 8:2 / /home rw shared:11 - ext4 /dev/sda2 rw,barrier=1,data=ordered
27 19 8:1 / /boot rw shared:13 - ext3 /dev/sda1 rw,errors=continue,user_xattr,acl,data=ordered
28 20 0:16 / /dev/shm rw shared:4 - tmpfs tmpfs rw
29 21 0:17 / /proc/sys/fs/binfmt_misc rw shared:7 - binfmt_misc none rw
30 19 0:18 / /var/lib/nfs/rpc_pipefs rw shared:14 - rpc_pipefs sunrpc rw
15 26 0:19 / /home/mclasen/.gvfs rw,nosuid,nodev shared:12 - fuse.gvfs-fuse-daemon gvfs-fuse-daemon rw,user_id=500,group_id=500
17 19 8:3 / /foo rw shared:10 - ext4 /dev/sda3 rw,barrier=1,data=ordered
18 19 8:3 / /bar rw shared:10 - ext4 /dev/sda3 rw,barrier=1,data=ordered
Comment 19 David Zeuthen 2009-03-24 18:26:45 EDT
Awesome. I get this too. /dev/sdb2 was automounted by the desktop bits.

[root@x61 ~]# mount --bind /media/foo2 /bar
[root@x61 ~]# cat /proc/self/mountinfo 
19 1 8:1 / / rw shared:1 - ext3 /dev/root rw,errors=continue,data=ordered
20 19 0:15 / /dev rw shared:2 - tmpfs /dev rw,mode=755
21 19 0:3 / /proc rw shared:5 - proc /proc rw
22 19 0:0 / /sys rw shared:8 - sysfs /sys rw
23 19 0:13 / /selinux rw shared:9 - selinuxfs none rw
16 21 0:14 / /proc/bus/usb rw shared:6 - usbfs /proc/bus/usb rw
24 20 0:10 / /dev/pts rw shared:3 - devpts devpts rw,gid=5,mode=620,ptmxmode=000
25 20 0:16 / /dev/shm rw shared:4 - tmpfs tmpfs rw
26 21 0:17 / /proc/sys/fs/binfmt_misc rw shared:7 - binfmt_misc none rw
15 19 0:18 / /home/davidz/.gvfs rw,nosuid,nodev shared:10 - fuse.gvfs-fuse-daemon gvfs-fuse-daemon rw,user_id=500,group_id=500
17 19 8:18 / /media/foo2 rw,nosuid,nodev shared:11 - vfat /dev/sdb2 rw,uid=500,gid=500,fmask=0022,dmask=0077,codepage=cp437,iocharset=utf8
18 19 8:18 / /bar rw,nosuid,nodev shared:11 - vfat /dev/sdb2 rw,uid=500,gid=500,fmask=0022,dmask=0077,codepage=cp437,iocharset=utf8
Comment 20 Karel Zak 2009-03-25 07:18:43 EDT
/proc/mount and /proc/mountinfo archaeology:

   The first discussion about "/proc/mount is broken":
   http://markmail.org/message/sppdo4n3cwsw3oyz 

   mountinfo patch:
   http://lkml.org/lkml/2008/1/29/136

It means this is not a new issue. I have doubts that any change to /proc/mounts will be accepted by kernel developers.

Note that my plan for util-linux-ng 2.16 is to add to libmount an API to provide all information about the current mounts. It should be a transparent way how to read /etc/mtab /proc/mounts and /proc/#/mountinfo files.
Comment 21 Matthias Clasen 2009-04-07 00:43:53 EDT
Should be fixed in DeviceKit-disks-004

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