Utilities don't take into account capabilities
The utilities such as mount don't take into account capabilities and always fail for non root users which is wrong.
This is really, really, really annoying when working in a sandboxed non root shell with pseudo capabilities.
One possible solution to my problem is do some complicated checking for capabilities that I don't even know how would work. I believe a better and simpler approach that would work for possible future extensions as well would be to simply drop privileges whenever one is unprivileged and attempt to do the task as normally. If you felt like it, a warning along the lines of "warning:
user is unprivileged, attempting mount without privileges" could be made. As a bonus, failed system calls can sometimes leave important diagnostic information in the dmesg.
Thank you,
Steven Stewart-Gallus
Quoted 5 lines · Steven Stewart-Gallus
The utilities such as mount don't take into account capabilities and always fail for non root users which is wrong.
This is really, really, really annoying when working in a sandboxed non root shell with pseudo capabilities.
----
I was just going to ask what capabilities need to be set for mount to work.
Seriously... What capabilities does mount need in order to function?
If this is in the 'util-linux', shouldn't these be utilities for linux? I.e.
the default linux kernel supports capabilities these days...no?
Quoted 1 line
Seriously... What capabilities does mount need in order to function?
I can help out with this one.
Quoted 2 lines
CAP_SYS_ADMIN
* Perform a range of system administration operations including:
quotactl(2),
Quoted 1 line
mount(2), umount(2), swapon(2), swapoff(2), sethostname(2), and
setdomain‐
Quoted 2 lines
name(2);
* perform privileged syslog(2) operations (since Linux 2.6.37,
CAP_SYSLOG should
Quoted 2 lines
be used to permit such operations);
* performIPC_SETandIPC_RMIDoperations on arbitrary System V IPC
objects;
Quoted 1 line
* perform operations on trusted and security Extended Attributes (see
attr(5));
Quoted 2 lines
* use
lookup_dcookie(2);
* useioprio_set(2)to assignIOPRIO_CLASS_RTand (before Linux
2.6.25)
Quoted 3 lines
IOPRIO_CLASS_IDLEI/O scheduling classes;
* forge UID when passing socket credentials;
* exceed/proc/sys/fs/file-max, the system-wide limit on the
number of open
Quoted 1 line
files, in system calls that open files (e.g., accept(2), execve(2),
open(2),
Quoted 7 lines
pipe(2));
* employCLONE_NEWNSflag with clone(2) and unshare(2);
* call setns(2);
* performKEYCTL_CHOWNandKEYCTL_SETPERMkeyctl(2) operations;
* perform madvise(2)MADV_HWPOISONoperation.From CAPABILITIES(7) in the Linux Programmer's Manual.
Quoted 5 lines · Steven Stewart-Gallus
Quoted 2 lines
Seriously... What capabilities does mount need in order to function?
I can help out with this one.
----
awesome... but, um... was hoping the author of mount could tell me what caps I needed to enable to use his program w/a non-root user... ;-)... oh well... um...now as to when we can get a version that doesn't check for UID & EUID==0?
well... maybe in the works?
Quoted 8 lines
From: Linda Walsh <[email protected]>
Quoted 5 lines · Steven Stewart-Gallus
Quoted 2 lines
Seriously... What capabilities does mount need in order to function?
I can help out with this one.
Quoted 7 lines
----
awesome... but, um... was hoping the author of mount could tell me what caps I needed to enable to use his program w/a non-root user... ;-)... oh well... um...now as to when we can get a version that doesn't check for UID & EUID==0?well... maybe in the works?
I believe there's a complication... I'm no expert, but I vaguely recall from some previous thread that there are situations where 'mount' isn't purely a front-end for the kernel mount() call. Instead, 'mount' wants to set up some things and then call mount().
The example that comes to mind is setting up a file on a loopback device, then mounting the loopback device. But I think there were other situations like this.
The problem being, that 'mount' wants to verify that the mount() call will succeed *first* before attempting the set-up operations. And some of the setup operations require root capabilities.
There's also the complication of the "users" and "user=" options, which are to permit a user to do something he doesn't actually have the capabilities for.
Dale
Quoted 9 lines · Dale R. Worley
I believe there's a complication... I'm no expert, but I vaguely recall from some previous thread that there are situations where 'mount' isn't purely a front-end for the kernel
mount()call. Instead, 'mount' wants to set up some things and then callmount().The example that comes to mind is setting up a file on a loopback device, then mounting the loopback device. But I think there were other situations like this.
----
In such cases, to execute the operation, check the max caps needed
to perform the operation.
Quoted 8 lines
The problem being, that 'mount' wants to verify that the
mount()call will succeed *first* before attempting the set-up operations. And some of the setup operations require root capabilities.There's also the complication of the "users" and "user=" options, which are to permit a user to do something he doesn't actually have the capabilities for.
----
Separate issue. I.e. should permission come from the entry in
'fstab', or
should it come from what logins are set w/what caps. I think (?) from historical perspectives, the user is enabled to perform a specific operation if they are specifically mentioned. Else, go/w caps user has to complete successful operation.
Would that cover it?
Quoted 3 lines
From: Linda Walsh <[email protected]>
Would that cover it?
I have no idea. I just wanted to warn you that it's probably trickier to do well than it appears at first.
Dale
Quoted 6 lines · On Sat 16 Aug 2014 21:57:56 Steven Stewart-Gallus wrote:
The utilities such as mount don't take into account capabilities and always fail for non root users which is wrong.
This is really, really, really annoying when working in a sandboxed non root shell with pseudo capabilities.
Quoted 8 lines
One possible solution to my problem is do some complicated checking for capabilities that I don't even know how would work. I believe a better and simpler approach that would work for possible future extensions as well would be to simply drop privileges whenever one is unprivileged and attempt to do the task as normally. If you felt like it, a warning along the lines of "warning: user is unprivileged, attempting mount without privileges" could be made. As a bonus, failed system calls can sometimes leave important diagnostic information in the dmesg.
guessing the sandbox isn't really meant for security purposes since CAP_SYS_ADMIN can easily be used to recover just about every other capability.
http://lwn.net/Articles/486306/
especially considering access to mount means you're allowed to mount arbitrary filesystems w/arbitrary content including set*id progs.
so what exactly is the point of trying to support CAP_SYS_ADMIN ?
note: i'm not arguing about whether the current UID checks in mount are even useful ... it'd make the code simpler to just assume the privs exist, else it'll get errors from the respective syscalls and the user of a misconfigured system can deal with it themselves.
-mike
Quoted 3 lines
guessing the sandbox isn't really meant for security purposes since
CAP_SYS_ADMINcan easily be used to recover just about every other
capability. http://lwn.net/Articles/486306/
capabilities in a CLONE_NEW_USER sandbox only apply to the sandbox and not things outside of the sandbox such as devices.
Karel Zak
maintainerQuoted 3 lines · Steven Stewart-Gallus
Quoted 3 lines
guessing the sandbox isn't really meant for security purposes since
CAP_SYS_ADMINcan easily be used to recover just about every other
capability. http://lwn.net/Articles/486306/
The currently supported scenario is that you can remove suid from mount(8) and replace it with cap_dac_override,cap_sys_admin+ep. Note that in this case mount(8) still requires 'user' in fstab of course.
The disadvantage is that mount(8) is not able to update for example /etc/mtab (or /run/mount/utab), because cap_sys_admin is just subset of the original suid privileges.
Quoted 2 lines
capabilities in a
CLONE_NEW_USERsandbox only apply to the sandbox and not things outside of the sandbox such as devices.
Well, user namespace is little bit different story and we already talked about it (in May).
http://www.spinics.net/lists/util-linux-ng/msg09309.html
The idea is that we can drop privileges rather than exit with "only root can..." error message. I'd like to try it during this release cycle.
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
I see, so the issue is already known. Thank you.
Quoted 4 lines · Karel Zak
The currently supported scenario is that you can remove suid from
mount(8) and replace it with cap_dac_override,cap_sys_admin+ep. Note that in this case mount(8) still requires 'user' in fstab of course.
---
Is this planned, as the source I looked at still had uid==0 checks.
Quoted 4 lines
The disadvantage is that mount(8) is not able to update for example
/etc/mtab(or/run/mount/utab), becausecap_sys_adminis just subset of the original suid privileges.
This does point out an important issue -- should things likecap_sys_admin also allow updating of run/mount/utab? I would say "maybe":
Updating /etc/mtab -- IF it is a separate file system object would
require write access to the file. That could be handled with an ACL, or CAP_DAC_OVERRIDE. But the former "/run/mount/utab" -- isn't that a kernel based file? I.e. a pointer to /proc/self/mounts? Either way -- if it is a separate file, then it would be updated based on access and privilege, but if it is a representation of kernel state, then it seems CAP_SYS_ADMIN would be sufficient, no?
Linda