8 ms·
Unprivileged Chroot()
- knorker 6y agoWhy not use unveil() (From OpenBSD) for this use case?
- shawnz 6y agoThat doesn't let you construct an arbitrarily structured virtualized filesystem like chroot does, just hide parts of the existing filesystem
- gbrown_ 6y agoCan you elaborate on this please? I'd consider unveil to be far more capable of creating "an arbitrarily structured virtualized filesystem" view than chroot. I'd also invert the thinking of "just hide parts of the existing filesystem" as it whitelists paths and access rather than blacklisting.
- ori_b 6y agoHow do you bind a /tmp/empty to /home/$USER with unveil, so that you can see and capture the files some program creates?
- gbrown_ 6y agoSorry I don't quite grok your comment. It sounds like a bind mount so I'm unsure how it relates to unveil or chroot?
- ori_b 6y agoChroot is more or less a bind mount over /. Bind mounts generalize chroot. Unveil does not, and therefore does not allow you to provide arbitrary views of the file system. It's useful for other reasons. On OpenBSD, a full web browser compromise does not lead to full file system access.
- shawnz 6y agoUnveil has no way to change the existing structure of the filesystem. With chroot it's easy: create the structure you want in a subdirectory and then chroot into it
- gbrown_ 6y agoIf changing a process root directory is really what you want to do then yes chroot is the right tool for the job. But from a perspective of "jailing" daemons as mentioned in the article I think unveil is a better API. I'm not sure what pieces of software populate directories and then chroot into them aside from maybe some build systems? But those likely create or bind in some /dev and /proc pieces which would be privileged operations anyway. And in such a case would containers not have surplanted chroot?
- shawnz 6y ago"Jailing" isn't necessarily just about security, but isolation in general. Unveil would be a stronger tool if the concern is strictly security, but also there's no reason they couldn't both be used. Chroot is itself sometimes used to provide container-style functionality, so I think it's wrong to say containers "surplanted" it.
- zokier 6y ago> And in such a case would containers not have surplanted chroot? Containers use chroot
- knorker 6y agoThey don't use fs namespaces?
- knorker 6y agoYes, but wasn't the use case to reduce access, not to fake a new root?
- shawnz 6y agoThe use case is isolation, which is not necessarily exactly the same as reducing access. For example, maybe you don't want the process to be able to easily detect that it has had its access reduced, by simulating a full-access environment. Or for example, maybe you don't care about access at all and you just want to avoid conflicts between two processes by giving them separated namespaces for their data.
- kortex 6y agoThis just feels like law of unintended consequences waiting to happen. Like the use cases are super cool, like using it with FUSE to basically redirect a file system view. But it feels like asking for trouble. You would need to know the interaction between all manner of systems that could be used to effect an escalation.
- georgyo 6y agoCan't unshare essentially do the same thing? unshare --map-current-user --root=<new root> <program> And works completely unprivileged using namespaces.
- raimue 6y agoBe aware that on some distributions such as Debian or RHEL, user namespaces are restricted by default and cannot be used like this from unprivileged user accounts. Although Debian is going to change the default with the next release. https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=898446 https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=898446
- zokier 6y agounshare calls chroot behind the scenes: https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git/tree/sys-utils/unshare.c#n643 https://git.kernel.org/pub/scm/utils/util-linux/util-linux.g...
- CyberRabbi 6y agoYes but it does so as the root user in the new user namespace, which is allowed according to existing rules. The change in question is about not requiring root in any user namespace.
- georgyo 6y agoThanks for the link! In that case, it seems completely arbitrary to not make chroot work as a normal user then.
- Blikkentrekker 6y ago> If these conditions are met, it is argued, it is safe to allow a process to call chroot(). It is safe only insofar some other software with elevated privileges whose security model assumes that only root can chroot, not run. This is an issue with security that is had to avoid; some software is written on the assumption that certain things are impossible that may become possible in the future. It is also why most capabilities are in practice useless as a tool of granularity on the average system and that all capabilities can often be constructed from a subset that is often as large as a single one, as so much software was written and designed before such capabilities existed, under the assumption that, if one have one, one have all.
- rwmj 6y agoI'm intrigued to know if Microsoft (where the patch submitter works) have a use case for this or if it's related to one of his other security projects (see http://digikod.net/ http://digikod.net/). I think it needs a strong motivating case.
- You-Are-Right 6y agoWhy you write "Microsoft" and "Security" in one sentence?
- PeterisP 6y agoFor me personally a potential application seems to be embedding general purpose languages as scripting tools within nonprivileged applications; such a chroot would make it easier for the app to grant some filesystem access to a potentially malicious script without trying to restrict the language, API and libraries used for that.
- remexre 6y agoWhy not use a mount namespace? And how are you creating a /dev without root?
- Spivak 6y agoI feel like you're assuming that mount namespaces are something greater than they actually are. You still need chroot(2) or pivot_root(2) to actually put a process into its own isolated directory. There's no magic here. Try running `unshare -m` to see what it's like in "just" a mount namespace.
- chasil 6y agoMicrosoft OpenSSH is at least faking it. 4084 2021-03-02 01:08:24.055 fatal: safely_chroot: stat("C:\\sftpjail"): No such file or directory
- whizzter 6y agoOne thing i wonder about when reading about the issues of chroot is why they just didn't make "PR_SET_NO_NEW_PRIVS" default of chroot from the beginning and make other ways to strengthen chroot security (because it was after all intended to provide security so why did backwards compatibility trump security?)
- st_goliath 6y agoPR_SET_NO_NEW_PRIVS was added in Linux 3.5 chroot() is from ancient Unix/BSD times and was in Linux since pretty much the beginning of Linux. Changing its behavior after the fact would break expected behavior of existing programs AND would break compatibility with other Unixen.
- totetsu 6y agoUnixen, is that german?
- st_goliath 6y agoInteresting. According to the German Wiktionary, yes. Back in high school (in Austria, speaking German) I've been told several times by a Unix grey beard I had as a teacher that "Unixen" is the preferred plural of Unix, similar to "VAXen" for VAX, which the English Wiktionary does seem to know about.
- whizzter 6y agoYes, it'd break compatibility, but mostly compatibility of components added after chroot if I'm not mistaken? Would escaping chroot and/or rooting by tampering with /bin/su(-do) have been possible on these older unices?
- st_goliath 6y agoThose problems were known before Linux was a thing, which is part of the reasons only root was historically allowed to do a chroot(). Even Unix v7 insists on chroot() being only called by the root user (the chroot syscall is in /usr/sys/sys/sys4.c).
- dathinab 6y agoMy reaction: Why? Oh that makes sense. Wait! Abysmal Security Nightmare! Nooooooo Don't do that, Pleeeeeeease. One of the main reason is that: 1. It increases the attack surface. 2. At least currently PR_SET_NO_NEW_PRIVS must not be relied on to be perfect for security. Must use cases use it as an additional security layer, but the chroot patch uses it as a fundamental required to be perfect building block. 3. As far as I can tell the benefit it gives is not worth the increased attack surface even if PR_SET_NO_NEW_PRIVS would work perfectly. But I might be wrong. Honestly the additional constraints it puts on chroot are good and I believe should be fulfilled for must use cases of chroot. So I think best would be either a "CAP_RESTRICTED_CHROOT" capability which allows chroot but only under given circumstances or a prctrl which "degrades" CAP_SYS_CHROOT to only work under given circumstances. In both cases programs which drop all CAP's they don't need would not be affected by this feature made for programs which use chroot. But in the current design the sandbox of ALL!!!! sandboxed programs which drop the CAP_SYS_CHROOT capability is weakened. Which IMHO is unreasonable.
- 0xbadcafebee 6y agoThe security concerns are overblown because this assumes everyone will start using chroot for everything, which isn't the case. There are plenty of use cases where you intentionally sacrifice security for usability. What's the danger here, that a program will create a chroot and that an attacker will then break out of it? So we're back to where we are now, which is not using chroots.
- dathinab 6y ago> What's the danger here, that a program will create a chroot and that an attacker will then break out of it? So we're back to where we are now, which is not using chroots. Not quite right Currently chroot needs privilegs, so a program which runs sandboxed will not ever be able to chroot and will be stuck in the sandbox. But with that patch a sandboxed program could start a chroot and then use the chroot environment to weaken or escape the sandbox it is in. So as far as I understand this change will actively weaken the security of all sandboxes which dropped the privilege to do chroot (or never had it), which are most of them. The main way you could take advantage of it would be in combination with a RCE vulnerability in a software which runs itself in a sandbox. > which is not using chroots. Currently we can make sure chroot is not used by making sure no SYS_CAP_CHROOT or similar capability is given. With the patch it will be impossible to make sure chroot is not used! Because anyone anywhere with anyuser will be able to use it. Which would be fine with the constraints the patch adds to chroot, but the problem is that it's known that one of the main constraints it adds doesn't work perfectly/has security gaps. > intentionally sacrifice security for usability. The problem is that with the patch everyone using various non-vm sandboxing mechanisms will be forced to sacrifice security for usability, it's not a "opt-in for this programs which do care". Which is why I think putting this behind another capability or similar would be best (one a unprivileged user can have).
- Ericson2314 6y agoAhh.... we just need Capsicum/CloudABI for real to end the badness. Security and expressive power one can actually understand.
- southerntofu 6y agoMaybe chroot is not the right solution, but having unprivileged containers/jails natively supported (not docker/systemd-containerd overlay) sounds useful.
- m3047 6y agoI custom compiled a kernel to support userland chroot a number of years ago; it was trivial. It served the use case just fine. There are probably people today who run things in Docker containers as root who are thinking "OMG, this is a horrible idea!". In the chroot environments I created at the time everything was statically linked and there was nothing else for the program(s) to run. Everything was audited. It didn't start with "it works on my machine, so why can't I ship my machine?" as a premise.