Bug 615719 - tmpfs mount fails with 'user' option.
Summary: tmpfs mount fails with 'user' option.
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: util-linux-ng
Version: 13
Hardware: All
OS: Linux
low
medium
Target Milestone: ---
Assignee: Karel Zak
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: 616393
TreeView+ depends on / blocked
 
Reported: 2010-07-18 09:38 UTC by Stephen J Alexander
Modified: 2010-08-02 10:21 UTC (History)
4 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
: 616393 (view as bug list)
Environment:
Last Closed: 2010-07-29 11:12:56 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Stephen J Alexander 2010-07-18 09:38:24 UTC
Description of problem:
Mount of tmpfs where fstab contains "user" option still requires root privilege.

Version-Release number of selected component (if applicable):
util-linux-ng-2.17.2-5.fc13.i686
Problem appears present at least back to Fedora12.

How reproducible:
100%

Steps to Reproduce:
1. Add fstab entry like
tmpfs  /mnt/ramdisk tmpfs user,noauto		0 0	
2. Create mountpoint
mkdir /mnt/ramdisk
3. Attempt to mount from non-root account:
mount /mnt/ramdisk

  
Actual results:
[stevea@nidula mount]$ tail -1 /etc/fstab
tmpfs			/mnt/ramdisk		tmpfs	user,noauto,ro		0 0	
[stevea@nidula mount]$ ls -ld /mnt/ramdisk/
drwxrwxrwt 2 root root 40 Jul 18 04:03 /mnt/ramdisk/
[stevea@nidula mount]$ mount /mnt/ramdisk
mount: only root can do that
[stevea@nidula mount]$ 

Expected results:
tmpfs should mount at /mnt/ramdisk WITHOUT requiring root privilege.

Additional info:
This problem results from the correction to bug 476964
https://bugzilla.redhat.com/show_bug.cgi?id=476964
The script /sbin/mount.tmpfs is called from mount, and in turn  exec's "mount -i-t tmpfs -o user,...".   For obvious reasons the mount command cannot accept the "-o user" option from the command line.  The script solution to 476964 does not correctly preserve mount functionality.

Comment 1 sándor snepp 2010-07-18 21:31:26 UTC
i can confirm that the problem is exactly as descibed on fedora 13 (goddard) with the latest updates installed.

Comment 2 Karel Zak 2010-07-19 13:51:32 UTC
(In reply to comment #0)
> Expected results:
> tmpfs should mount at /mnt/ramdisk WITHOUT requiring root privilege.
> 
> Additional info:
> This problem results from the correction to bug 476964
> https://bugzilla.redhat.com/show_bug.cgi?id=476964
> The script /sbin/mount.tmpfs is called from mount, and in turn  exec's "mount
> -i-t tmpfs -o user,...".   For obvious reasons the mount command cannot accept
> the "-o user" option from the command line.  The script solution to 476964 does
> not correctly preserve mount functionality. 

I don't see other way how to fix this problem than move mount.tmpfs functionality to mount(8). 

The question is if we want to support user-mounts for tmpfs without a context= setting. It would be better if admin specifies context(s) for the mounts.

The solution/workaround is to add

   tmpfs   /mnt/ramdisk  tmpfs user,noauto,ro,rootcontext=<CXT>  0 0 

where <CXT> is for example a context from  "ls --scontext -d /mnt/ramdisk".

Comment 3 Daniel Walsh 2010-07-19 15:00:08 UTC
If you do not specify a file context it will default to tmpfs_t.  If the script eliminated the user option would it work?

Comment 4 Karel Zak 2010-07-19 19:48:22 UTC
(In reply to comment #3)
> If you do not specify a file context it will default to tmpfs_t.  If the script
> eliminated the user option would it work?    

No, mount(8) checks if the user is root. For non-root users it runs in very restricted mode where all options have be specified in fstab only.

(In reply to comment #2) 
> The solution/workaround is to add
> 
>    tmpfs   /mnt/ramdisk  tmpfs user,noauto,ro,rootcontext=<CXT>  0 0 
> 
> where <CXT> is for example a context from  "ls --scontext -d /mnt/ramdisk".    

Sorry, this is nonsense. The script still calls 

   /bin/mount "$@" -i -t tmpfs

so it won't work for non-root users.

Comment 5 Karel Zak 2010-07-19 19:58:51 UTC
The mount.tmpfs script has to detect that user= option is used and then call
mount(8) without any option, something like

 if ! echo "$@" | grep -q -E '\-o.*user';  then
    exec /bin/mount -i "$2"
 fi

then you can specify a context in fstab (or default to tmpfs_t). I'll update the script ASAP. (Sorry again for the comment #2.)

Comment 6 Karel Zak 2010-07-20 07:30:33 UTC
Proposed patch:

--- mount.tmpfs	12 Apr 2010 13:19:23 -0000	1.5
+++ mount.tmpfs	20 Jul 2010 07:28:09 -0000
@@ -18,6 +18,24 @@
       ;;
 esac
 
+restricted=1
+ruid=$(id --user --real)
+euid=$(id --user)
+
+if [ $ruid -eq 0 ] && [ $ruid -eq $euid ]; then
+  restricted=0
+fi
+
+# mount(8) in restricted mode (for non-root users) does not allow to use any
+# mount options, types or so on command line. We have to call mount(8) with
+# mountpoint only.  All necessary options have to be defined in /etc/fstab.
+#
+# https://bugzilla.redhat.com/show_bug.cgi?id=615719
+#
+if [ $restricted -eq 1 ]; then
+  exec /bin/mount -i "$2"
+fi
+
 # Remount with context mount options is unsupported
 # http://bugzilla.redhat.com/show_bug.cgi?id=563267
 #

Comment 7 Fedora Update System 2010-07-20 08:52:54 UTC
util-linux-ng-2.17.2-6.fc13 has been submitted as an update for Fedora 13.
http://admin.fedoraproject.org/updates/util-linux-ng-2.17.2-6.fc13

Comment 8 Stephen J Alexander 2010-07-20 17:31:16 UTC
I've tested util-linux-ng-2.17.2-6.fc13  for x86_64.

Works as expected.
Please close.

Comment 9 Fedora Update System 2010-07-27 02:27:39 UTC
util-linux-ng-2.17.2-6.fc13 has been pushed to the Fedora 13 stable repository.  If problems still persist, please make note of it in this bug report.

Comment 10 Fedora Update System 2010-08-02 10:21:20 UTC
util-linux-ng-2.18-2.fc14 has been submitted as an update for Fedora 14.
http://admin.fedoraproject.org/updates/util-linux-ng-2.18-2.fc14


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