Slashdot Log In
When Not to Use chroot
Posted by
CowboyNeal
on Thu Sep 27, 2007 07:53 PM
from the trust-no-one dept.
from the trust-no-one dept.
Hyena writes "Linux guru Alan Cox is quoted as saying 'chroot is not and never has been a security tool' in a KernelTrap article summarizing a lengthy thread on the Linux Kernel mailing list. The discussion began with a patch attempting to 'fix a security hole' in the Unix chroot command, trying to improve the ability of chroot to contain a process. When it was pointed out that people have been using chroot as a security tool for years, another kernel hacker retorted, 'incompetent people implementing security solutions are a real problem.' A quick search on the terms 'chroot+security' quickly reveals that many people have long thought (wrongly) that chroot's purpose was for improving security."
Related Stories
Firehose:"Chroot Is Not and Never Has Been a Security T by Anonymous Coward
[+]
Chroot in OpenSSH 62 comments
bsdphx writes "OpenSSH developers Damien Miller and Markus Friedl have recently added a nifty feature to make life easier for admins. Now you can easily lock an SSH session into a chroot directory, restrict them to a built-in sftp server and apply these settings per user. And it's dead simple to do. If you need to allow semi-trusted people on your computers, then you want this bad!"
This discussion has been archived.
No new comments can be posted.
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
misleading... (Score:5, Informative)
Or is it? (Score:5, Interesting)
I think that this was once (or may currently be) the case with bind and various MTA's. Standard practice for many daemons now is to start as root and fork as another non-privileged user, but not every daemon has this option.
Parent
Re:For daemons that don't run as root (Score:5, Informative)
Just because you can only run a command as a superuser doesn't mean that all of the child processes of that command have to be run as the superuser. If this were the case, since init runs as root you would not have a multiuser system.
Parent
Re:Or is it? (Score:5, Informative)
Well a good place to start would be at http://en.wikipedia.org/wiki/Chroot [wikipedia.org] because one of the first things I did when this article came up was to double-check my understanding of chroot right there. FTFW:
Parent
Re:misleading... (Score:5, Insightful)
Honestly, I might be in the classification of people who don't understand, but I resent the implication of "incompetent". I really hate the idea that you have to be an all-knowledgeable ubergeek, or else stay completely away from computers.
It seems like a simple issue: people have obviously felt the need to jail users for security reasons. They've been lead by someone to believe that chroot is a solution. If chroot isn't the solution, then why not give people a better solution instead of calling them incompetent.
It reminds me of a discussion that I was involved in a while back. I'll tell the story:
So all I wanted was to know how to do something, and everyone thought it was a lot of fun to tell me how incompetent I was. If the answer is so obvious, why not explain it? More to the point, if you're such a fricken genius, why not figure out a way to get people the functionality they want in a form they'll understand? I still don't understand why secure authentication is a silly thing to want.
Assuming that everyone running a server is going to be a super-genius who wants to spend all day researching everything-- having that expectation is retarded. I've been working in IT for a while, and I'll tell you right now that there are an awful lot of admins that are way dumber than I am. A solution that only super-geniuses can figure out isn't a practical solution because no one will use it.
So if a lot of people want to jail users into a specific directory for various reasons, why can't we have that functionality? If one particular method (in this case, chroot) doesn't do a good job of jailing users, then can one of the super-geniuses out there come up with a good/real/practical/secure method for accomplishing that?
If you can't, please refrain from name-calling because they want to do something that you can't figure out how to accomplish.
Parent
Re:misleading... (Score:4, Funny)
People don't tend to maintain a list of links to every subject they've ever discussed. So somebody has to do the searching, rightfully it should be the one who wants to know the answer...
Weren't you the one who just asked me elsewhere to post a link to the thread I was referring to?
Parent
Re:misleading... (Score:4, Informative)
Using chroot on a process is like handing a person a map with an X on the destination. You've shown them where they're supposed to go, you haven't really done anything to prevent them from running off in another direction.
Parent
Re:misleading...Re:Asshole Stereotype (Score:5, Informative)
Anyway, I do understand the perspective behind your reaction, but it doesn't fit in this specific case.
Parent
Re:misleading...Re:Asshole Stereotype (Score:5, Insightful)
Man, things like this make me want to NOT switch to Linux... Even though I had a better experience with Ubuntu that I did Vista.
It's absolutely true and it is not limited to linux.
Let's take it a few more steps further as an example:
'incompetent people performing surgery are a real problem.'
'incompetent people running the government are a real problem.'
If you don't even know what chroot() is, then you are not the target of the man's complaint.
Parent
Re:misleading...Re:Asshole Stereotype (Score:5, Insightful)
Go ahead. One of the (many) differences between Vista and Linux is that if you want to, you can march up to any of the core Linux kernel architects and tell them they have some fundamental long-standing unix interface totally wrong. The flip side of that is that they also won't stop anyone from flaming you if you do that.
And that's exactly what happened here. This guy wasn't posting a question on a local LUG. He was posting to the Linux kernel mailing list--the place where people actually meet to do kernel development. And he wasn't asking a question, he was arguing with people like Al Viro, a primary architect of the Linux filesystem api's. Which would be great if he was correct. But in fact he was totally wrong. And even that would be OK if he took the time to do his homework and to listen carefully when people explained the issue to him.
But he didn't really, so as a result he got a few flames. Some of the posters to lkml aren't polite in such a situation. I think that's kind of understandable, though actually agree that that's a problem. Are the core Vista kernel developers any better? Who knows? Does the general public doesn't have the option of participating in their development forums?
Parent
chroot, security and other uses (Score:4, Informative)
Only if it can get access to a broken SUID program, etc. I always though the point of a chroot in a security context was that the chroot only had the absolute minimum environment the task being isolated had to have, thus there shouldn't be too much in there to worry about getting exploited. Which is very useful.
Of course there are lots of uses for chroot that have nothing to do with security. Like keeping a whole 32bit environment seperate from the main 64bit install, wonderful tools like mock which allow keeping multiple distros on multiple arches installed and usable for building packages, etc.
Parent
Yeah, okay. (Score:4, Insightful)
Locks on your house aren't for security, they're just to keep the door closed if a cat pushes on it, right?
Seatbelts aren't to prevent you from flying through a windshield, they're just there so you don't slide around while taking corners.
Sorry, chroot *is* a security tool; it's very much useful for security. Maybe it wasn't written as one - maybe it was never intended to be one, but it *is* one now, no matter what Alan Cox says.
Software, especially open source software, is a lot like language. Despite the best efforts of nitpicking English teachers everywhere, the meaning of both words and code are whatever the vast majority agrees upon. And regardless of that, you may call me crazy, but the ability to restrict what a user can and can't access; what a process can or can't access, sounds like a security tool to me.
Chroot as a non-security tool (Score:5, Insightful)
If you system that won't boot due to a boot sector problem Boot from a CD, mount your partitions, chroot to your root partition and run lilo/grub/... to rewrite your boot sector.
If you system that won't boot due to init script problems Boot from a CD, mount your partitions, chroot to your root partition and run run your full init process. If you run into problems, rerun your init scripts rather than rebooting.
Unfortunately, many people think chroot is a security tool so many people don't think it in non-security contexts.
Re:Chroot as a non-security tool (Score:4, Informative)
Parent
What the hell is wrong with these people? (Score:5, Insightful)
Are they serious? (Score:5, Insightful)
Of course chroot() doesn't do any good if a process inside of it is running as root. This is very well known. However, that doesn't make chroot() useless, it is still plenty useful. If you execute chroot() and then a seteuid(uid) where uid>0, then you prevent a hole/bug in your program from being exploited in a way that will allow file access/execution outside the chroot. That *is* a security advantage.
The point of "chroot security", cases where chroot is used to improve security, isn't to contain a malicious root user. The point is to prevent privilege escalation. You can create a chroot without any directories with mode 7771 privileges (a la
What some people think, apparently due to pure ignorance, is that chroot() is an end-all solution that will prevent even a root-owned process from accessing files outside the chroot, or worse, thinking that it protects the memory subsytem in any way. It doesn't. Even if the discussed patch was applied to the kernel, a root-owned process could still alter kernel memory, access raw devices, etc.
Improvements in ACLs under Linux minimize some of the needs for a chroot, other than the fact that a chroot is still much easier to configure and ACLs do not handle all of the use-cases that a chroot can solve. (and visa-versa, chroot cannot solve all of the problems solved by ACLs) Additionally, a chroot *and* ACLs can be used together for further-improved security.
Overtaken by virualization (Score:4, Interesting)
Re:Duh. (Score:4, Insightful)
Isn't it just easier to remount the device?
News flash: root can break security. World ends at 10:00. Film at 11.
Parent
Re:Not for security use? (Score:5, Informative)
1. Create ~/etc/master.passwd with an empty root password.
2. Hard link
3. Copy
4. chroot ~
5. ~/bin/sh is now an unrestricted root shell.
Parent
Re:Not for security use? (Score:5, Insightful)
$ ls -l
-rwxr-xr-x 1 root root 700560 2007-04-11 09:32
$ ln
$ ls -l foo
-rwxr-xr-x 2 root root 700560 2007-04-11 09:32 foo
Uhhh, why is a regular user allowed to create a file owned by root?
You haven't created a file owned by root. You've created an i-node pointing to the data blocks of a file owned by root.
If root were to rm
Your way, I could do the following on a file with 600 permission:
cd
ln
chmod 666 mine
cat mine
Nice and easy way to get around a 600 permission.
The behavior is correct, not a bug.
Regards,
--Keith
Parent
Re:Not for security use? (Score:5, Informative)
>
> You haven't created a file owned by root. You've created an i-node pointing to the
> data blocks of a file owned by root.
No, you didn't.
You created a directory entry pointing to the i-node of the file which is also pointed
by the 'sh' entry in the
You can delete a hard link to a file owned by anyone if you have write permission on the directory that contains a link:
zoltan@gep:~> ln
zoltan@gep:~> ls -l foo
-rwxr-xr-x 2 root root 572200 2005-09-10 03:43 foo
zoltan@gep:~> rm foo
rm: remove write-protected regular file `foo'? y
zoltan@gep:~>
On the other hand, if you try it in
zoltan@gep:~> cd
zoltan@gep:/tmp> ln
zoltan@gep:/tmp> ls -l foo
-rwxr-xr-x 2 root root 572200 2005-09-10 03:43 foo
zoltan@gep:/tmp> rm foo
rm: remove write-protected regular file `foo'? y
rm: cannot remove `foo': Operation not permitted
zoltan@gep:/tmp>
The reason for that strange behaviour is this:
zoltan@gep:/tmp> ls -ld
drwxr-x--- 114 zoltan users 16248 2007-09-28 14:23
drwxrwxrwt 32 root root 3176 2007-09-28 14:25
The
Is it a bug? Well, it's certainly a feature... Is it a security problem? I don't know, I am no security expert, but I haven't heard of an exploit based on links and the sticky bit yet.
Parent
Re:Not for security use? (Score:4, Informative)
They're not. They are, however, allowed to create a name in a directory (a link) that points to an existing inode. Since the inode has all of the owner and permission data, and the user is not allowed to modify the inode, allowing them to create a link to it is not an inherent risk.
Awesome, the semantics of directory permissions are not even honored anymore.. anyone else smell a kludge here?
Yes, they are.
Parent
Re:Then what is it for? (Score:5, Informative)
Parent
Citation (Score:5, Informative)
http://blogs.sun.com/chrisg/tags/chroot [sun.com]
Parent
Re:Then what is it for? (Score:5, Interesting)
* tinyHTTP (AppWeb, Apache, etc.)
* SQLite (MySQL, Postgres, etc.)
* [chroot-path-0]/www/html/*
* Other ([chroot-path-0]/usr/lib, [chroot-path-0]/bin, etc.)
and repeat...
Now you have 5 chroot'ed web environments to help your test team (of 5) speed up Alpha testing. May be fraught with bad security? That's not the point.
Parent