You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
buildFHSUserEnv doesn't work for non-root users in grsecurity #21327
[spacekitteh@spaceserv:~/code/copperhead]$ nix-shell
/nix/store/qxdag2fs1qh4alr19ax3s9lqh5dw2m24-chroot-user:44:in `block in make_fcall': Operation not permitted (Errno::EPERM) from /nix/store/qxdag2fs1qh4alr19ax3s9lqh5dw2m24-chroot-user:114:in `<main>'
That's expected, I think. Grsec disables unprivileged user namespaces because it doesn't trust them. This also caused some pain with chromium/chrome sandboxing. Not sure what they did to fix it there.
The general idea is to have an initially privileged stub that sets up the sandbox, marked suid (called via wrapper most likely, in our case) to allow ordinary logins to use it. You'd need to read the buildFHSUserEnv sandbox code to see exactly what its sandbox init involves. The privileged stub would do pretty much the same thing (possibly sans user namespace, depending on whether it's just used to allow non-privileged users to perform the sandbox init).
On Dec 23, 2016, at 20:20, Sophie Taylor ***@***.***> wrote:
I don't speak Ruby.
<snip>
$unshare.call CLONE_NEWNS
<snip>
$mount.call nil, '/', nil, MS_REC | MS_SLAVE, nil
<snip>
$unshare.call CLONE_NEWNS | CLONE_NEWUSER
<snip>
write_file '/proc/self/setgroups', 'deny'
<snip>
write_file '/proc/self/uid_map', "#{uid} #{uid} 1"
write_file '/proc/self/gid_map', "#{gid} #{gid} 1"
<snip>
# Do rbind mounts.
mounts.each do |from, rto|
to = "#{root}/#{rto}"
FileUtils.mkdir_p to
$mount.call from, to, nil, MS_BIND | MS_REC, nil
end
# Don't make root private so privilege drops inside chroot are possible
File.chmod(0755, root)
These things seem to be the issue - IIRC, grsec allows reading from /proc/self/, but does it allow writing to it?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
@spacekitteh I can't talk about Grsecurity because I haven't used it much, but if I understood #17460 (comment) correctly you won't be able to use CLONE_NEWUSER and, therefore, CLONE_NEWNS as a regular user at all with current NixOS Grsecurity configuration. What this means is that you either need some sort of setuid wrapper, yes, or to disable this particular Grsecurity limitation.
See also #19047 as setuid interpreted scripts are forbidden (so Ruby is out of question).
Fakeroot won't likely help, but something like proot may (but you need to rewrite chroot-user.rb's logic as proot call). Proot has its limitations (as it's implemented as a "debugger" which overrides several syscalls).
The main issue here is that spender doesn't trust the user namespace code enough to grant unprivileged access to it. You might disagree, in which case I'd just turn off the kernel patch rather than try to circumvent it with a setuid wrapper that will basically have the same effect in a more roundabout way.
@copumpkin Exactly, see #21387 (that's why I closed it). However I left this one open because I don't know if we have any mechanism to change this grsecurity setting (e.g. with a build flag) currently.
Closing, this is a feature and not a bug :) See #21387 (comment) for a solution that doesn't require modifying buildFHSUserEnv, if you really, really need this.
Activity
copumpkin commentedon Dec 21, 2016
That's expected, I think. Grsec disables unprivileged user namespaces because it doesn't trust them. This also caused some pain with chromium/chrome sandboxing. Not sure what they did to fix it there.
spacekitteh commentedon Dec 21, 2016
I seem to remember grsecurity having a privileged_chroot_group or something? I know it has other special groups.
copumpkin commentedon Dec 21, 2016
Here's the context from last time we encountered this: #17460 (comment)
spacekitteh commentedon Dec 22, 2016
So, how can this be fixed?
joachifm commentedon Dec 22, 2016
You probably need to go via a suid wrapper
spacekitteh commentedon Dec 23, 2016
How?
joachifm commentedon Dec 23, 2016
The general idea is to have an initially privileged stub that sets up the sandbox, marked suid (called via wrapper most likely, in our case) to allow ordinary logins to use it. You'd need to read the
buildFHSUserEnvsandbox code to see exactly what its sandbox init involves. The privileged stub would do pretty much the same thing (possibly sans user namespace, depending on whether it's just used to allow non-privileged users to perform the sandbox init).Mic92 commentedon Dec 23, 2016
It would be basically mount namespaces + setuid back to the unprivileged user. An alternative would be proot: https://github.com/proot-me/PRoot This tools would introduce a little overhead due the use of ptrace.
spacekitteh commentedon Dec 24, 2016
I don't speak Ruby.
These things seem to be the issue - IIRC, grsec allows reading from /proc/self/, but does it allow writing to it?
copumpkin commentedon Dec 24, 2016
spacekitteh commentedon Dec 24, 2016
Ah, okay. So does that mean the env.rb file has to be rewritten in C or something, or?
Also, is that from GRKERNSEC_CHROOT_CAPS?
spacekitteh commentedon Dec 24, 2016
Would fakeroot work, do you think?
abbradar commentedon Dec 24, 2016
@spacekitteh I can't talk about Grsecurity because I haven't used it much, but if I understood #17460 (comment) correctly you won't be able to use
CLONE_NEWUSERand, therefore,CLONE_NEWNSas a regular user at all with current NixOS Grsecurity configuration. What this means is that you either need some sort of setuid wrapper, yes, or to disable this particular Grsecurity limitation.See also #19047 as setuid interpreted scripts are forbidden (so Ruby is out of question).
Fakeroot won't likely help, but something like proot may (but you need to rewrite
chroot-user.rb's logic asprootcall). Proot has its limitations (as it's implemented as a "debugger" which overrides several syscalls).copumpkin commentedon Dec 28, 2016
The main issue here is that spender doesn't trust the user namespace code enough to grant unprivileged access to it. You might disagree, in which case I'd just turn off the kernel patch rather than try to circumvent it with a setuid wrapper that will basically have the same effect in a more roundabout way.
abbradar commentedon Dec 28, 2016
@copumpkin Exactly, see #21387 (that's why I closed it). However I left this one open because I don't know if we have any mechanism to change this grsecurity setting (e.g. with a build flag) currently.
joachifm commentedon Dec 30, 2016
AFAIK, there's no way to disable this restriction. So if a setuid wrapper is not desired, this issue has to be closed as a wontfix.
joachifm commentedon Dec 30, 2016
Closing, this is a feature and not a bug :) See #21387 (comment) for a solution that doesn't require modifying
buildFHSUserEnv, if you really, really need this.spacekitteh commentedon Jan 1, 2017
But #21387 (comment) would disable it for EVERYTHING, whereas a stub would disable it only when setting up a FHS env, right?