When Not to Use chroot 407
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."
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.
Re: (Score:3, 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.
Any good sysadmin knows not to rely on a chroot jail to contain a process running as root. And if your MTA has to run as root, then it's a problem with the design of the MTA, not with the chroot mechanism. (If your MTA insists on running with root privileges, I highly recommend switching to Postfix if possible.)
Chroot is an excellent tool. But as with all security devices, it's up to the administrator to know precisely what it can and cannot do, rather than relying on it blindly. That's sort of what
Re: (Score:3, Interesting)
In OpenBSD chroot is used to sandbox the web server, and as someone else pointed out the documentation often encourages people to chroot daemons. Also similar software like Solaris containers and FreeBSD jails, which do pretty much the same thing as chroot, actually are for security (pretty much exclusively in the case of jails, not exclusively in the case of containers).
Also you'l
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:
Re:Or is it? (Score:4, Informative)
Re: (Score:3, Informative)
For daemons that run as root, the user should not be using the chroot command. Instead, the daemon should be doing cwd(), chroot(), setuid(). For other processes, you should (as root) do something like chroot su user command, so you drop privileges as soon as you are inside the chroot and can't escape.
Re: (Score:2)
Re: (Score:2)
Re: (Score:2)
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.
Excellent explanation (Score:2)
Re: (Score:3, Interesting)
It also doesn't make sense that certain inbound TCP ports are restricted to being bound only by root, but that's the reality we have to live with.
<Thought-experiment>
Wrap your mind around the fact that it is Microsoft Windows userland now that causes most of its insecurity. If you could cleanly separate Microsoft Windows userland and run it under an Open BSD
Re: (Score:3, Insightful)
It doesn't make sense. Using chroot(2) for security is like trying to fit a round peg into a square hole that it was never intended to go into.
You say that chroot isn't good, then make a cool analogy, but don't actually explain why it is wrong. That analogy doesn't explain to anyone what is wrong with chroot. You then go off on a totally unrelated tangent about Windows security and TCP ports.
So what's wrong with chroot?
Re: (Score:2)
You can get around that by having it listen on a higher port number and having the kernel reroute packets, but that gets messy if you have to do it for a bunch of services.
Re: (Score:2)
Reference? A quick google search for "bind chroot" finds several howto's explaining how to run bind under chroot as a non-root user. None that I can find suggest chroot and root.
Re: (Score:2)
Re: (Score:2)
Re: (Score:2)
Re: (Score:3, Insightful)
Re: (Score:2)
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.
Re: (Score:2)
Re: (Score:2)
Re: (Score:2)
Re: (Score:2, Interesting)
So is the point of chroot safety rather than security? Ie. used to circumvent the "don't do stuff as root, because mistakes can have bad consequences" thing? I'm not intimately familiar with chroot, but this is how I understand it. It's possible to break out of a chroot jail (therefore don't use it for security), but it's unlikely that you'll do so accidentally (therefore feel free to use it for safety).
Is that about right?
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.
Re: (Score:2)
What a succinct way of putting it.
Re: (Score:2)
I used to use Qmail for everything until spammers started to fill my mailq with bounces.. now it's postfix for everything.
Re:misleading...Re:Asshole Stereotype (Score:2, Insightful)
'incompetent people implementing security solutions are a real problem.'
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.
Heck, I don't even know what chroot is, which must make me dried dog piss on a hot fire hydrant in this guy's eyes.
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.
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.
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?
Re: (Score:2)
Re:misleading...Re:Asshole Stereotype (Score:4, Funny)
Fixed that for you.
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.
Re: (Score:3, Insightful)
Honestly, I've had the same problem, and what you're asking for is something that would benefit many people. I
Re: (Score:2)
I too have wanted the exact same thing.
In fact, it is starting to bother the heck out of me that servers rely on filesystem permissions to begin with, and I'm starting to think that it's something Unixes simply do wrong. Isn't it a security risk? Why do we let a user roam free around a drive, and hope that we set our permissions strictly enough everywhere?
Simply, I see no reason why an FTP or SFTP server needs to be tied to the filesystem at all. Why are FTP permissions associated with the files; the
Re: (Score:3, Insightful)
Can't you do something like this with Apache?
It's not as straightforward to configure as SlimFTP seems, but it
Re: (Score:3, Informative)
Don't be silly, there are open source developers producing and using open source software in 1001 different scenarios. Many people are using Linux
*cough* (Score:3, Informative)
Re: (Score:2)
This is a general thing: most people when they know something that other people obviously do not, they call those people incompetent or stupid, even though they are ignorant of many things that other people are not. People do it to make them feel better and compensate for
Re: (Score:2)
http://www.minstrel.org.uk/papers/sftp/
You'll need to compile your own version of OpenSSH. I'm running two instances of sshd, the default one that I can log into for administration and a hacked one for users (not on the same interface/port, obviously). I mostly followed the instructions from that page, but with this setup I don't need to use his crazy hack that uses
Possible solutions (Score:2)
You could do ssh access, without necessarily sftp (KDE's fish works with scp, I think), and deny them an actual login shell -- only allow sftp (or scp, or whatever). You could then block access to the rest of the filesystem with Unix file permissions or ACLs. Most things that they could access either aren't dangerous or are only visible to root (and maybe the file owner).
It's not easy, but consider: Ther
Re: (Score:3, Insightful)
No, you don't have to be an "all-knowledgeable ubergeek", but if you're going to discuss security in a technical forum you should enter into it with some level of knowledge that grants you entry. People who operate at level 10 don't want to hold people's hands through
Re: (Score:2)
No, he doesn't have the right to expect an answer from them, but he -can- expect a civil response, or no res
Re: (Score:2)
You're assuming a ridiculous amount of decidedly non-obvious facts...
People don't tend to maintain a list of links to every subject they've ever discussed. So somebody has to do the searching,
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?
Re: (Score:3, Insightful)
As for 'they should be the one to search'... Of course they should. But then, most people that can type without using contractions like 'ur' know that, and do. The problem is that if you only have a need, and no idea how to solve that need, what do you search for? Quite often the 'obvious' solution has a non-obvious name. He assumed that 'secure ftp' would be what he wanted. It wa
Re: (Score:2)
No, what's stupid is suggesting that a mailing-list or forum full of unpaid experts should be compelled to answer your trivial questions is the 'retarded' part.
Ummm... I don't know how to explain this to you since you seem to be somehow impaired, but it was a HELP FORUM. It was a forum specifically set up so that people could ask those sorts of questions, it was posted in the right place, and I had already searched the forum and many others to see if the question had already been asked and answered. No
Re: (Score:2)
I've seen far too many examples where people vastly exaggerate their experiences.
Re: (Score:2)
This happened 3-5 years ago on a forum that I never revisited because the people were so utterly rude. It would take my hours to find the thread, assuming it's even still available.
But my karma is generally good here, and you have access to my post history if you want to review it. Of all the things that people could accuse me of, no one who knows me would accuse me of being impolite when unprovoked or even particularly hot-tempered when provoked. I know lots of people are rude, but I'm almost always (a
Re: (Score:2)
I think I'll reserve judgment on just how incredibly polite you are.
Besides, that was only one of the points I brought up. I'm not going to take the rest of your assertions on faith, either.
Re: (Score:2)
Re: (Score:3, Insightful)
Did you really read the exchange? I mean, from a perspective not blurred by a glaze of sympathetic indignation?
makjls's cardinal sin was not asking a question in ignorance. The true error was arguing with knowledgeable people from a position of ignorance.
Alan Cox didn't get snippy until the Peanut Gallery began to presume they understood the rationale for chroot(2) better than he did.
Really, folks, ire is no substitute for understanding. Argue from a false presumption ("chroot is a security tool") and you w
FreeBSD Jails (Score:3, Informative)
Its like a virtual machine, but shares the same kernel (with restrictions) so there isn't the performance of full emulation.
Re: (Score:2)
Not for security use? (Score:3, Interesting)
Not for improving security, huh?
OK, genius, then explain why chroot() requires root privileges (or chroot capability) to execute.
It's only in the context of security that such a restriction makes any sense at all.
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.
Re: (Score:2, Interesting)
Hard link /usr/bin/su to ~/usr/bin/su. (Yes, you can create hard links to files which you don't own.)
Yes, and there's the bug.. which hasn't been fixed for 40 years.
/tmp /bin/bash /bin/bash /bin/bash foo
/bin/bash
try for yourself:
$ id
uid=1000(you) gid=1000(you)
$ cd
$ 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?
$ rm -f
rm: cannot remove `/bin/bash': Permission denied
$ rm -f foo
rm: cannot remove `foo': Operation not permitted
Awesome, the semantics of directory permissions
Re: (Score:2, Informative)
Re: (Score:3, Insightful)
ln doesn't create files, just POINTERS to them. Creating a link to bash, which was owned by you, would presumably allow to modify the contents of bash, owned by root.
/tmp to begin with, where the sticky bit is set on the folder, and only if /bin is on the same mount point as /tmp.
And that trick only works in
I can see how it would be a minor annoyance, not much of a bug.
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
Re: (Score:2)
No hardlinks to files you don't own.
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.
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.
Re: (Score:2)
simply shows that you're ignorant of what the semantics are.
Or I forgot about the sticky bit. Thanks.
allowing them to create a link to it is not an inherent risk.
'cept it makes it looks like the owner of the file created it in that directory. What's even more neat is this:
/tmp/lock_bobs_quota /tmp/lock_bobs_quota
/tmp he'll hav
$ ls -l bobs_file
-rw------- 3 bob bob 10815 2007-05-01 18:53 bobs_file
$ ln bobs_file
$ ls -l
-rw------- 3 bob bob 10815 2007-05-01 18:53 lock_bobs_quota
now when bob needs some space and he goes to rm -f bobs_file the link to the file will go away, but the file will hang around and unless bob looks in
Re: (Score:2)
Uhhh, why is a regular user allowed to create a file owned by root?
A regular user is not allowed to create a file owned by root. You have created a hard link, it is only a directory entry in a directory you have permission to write to, and directory entries do not contain file ownership information, that is stored in the inode for the file. There is only one inode no matter how many hard links there are.
Awesome, the semantics of directory permissions are not even honored anymore.. anyone else smell a kludge here?
No. But I do smell a newbie ranter.
/tmp /tmp/
/tmp?
$ ls -ld
drwxrwxrwt 14 root root 69632 2007-09-27 21:25
See that 't' in the directory permissions on
That's the sticky
Re: (Score:2)
Re: (Score:2)
You set yourself up for it. It's not like I was the only one to bite.
Re: (Score:2)
Re: (Score:3, Insightful)
Re: (Score:3, Funny)
Drop me an email, we'll arrange a meet.
Of course you would be an idiot to show.
You have no idea how many local gangbangers and thugs want to give you a beat-down for your lame unix skillz.
They fuckin' hate people who can't use the sticky bit right.
Re: (Score:2)
Re: (Score:2)
Re: (Score:2)
Duh. (Score:3, Informative)
For those of you who weren't aware how easy it can be to break out of most chroots, here's a good description of a common process:
http://www.bpfh.net/simes/computing/chroot-break.html [bpfh.net]
Re: (Score:2)
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.
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.
lacing up my track shoes (Score:2)
ok I better run now. Give me a head start, wouldja?
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: (Score:3, Insightful)
Re:Chroot as a non-security tool (Score:4, Informative)
chroot IS an effective layer (Score:2, Insightful)
Chroot IS an effective layer when you are also dropping privileges from superuser.
Obviously chrooting a "root" process does no good.
But hey, this is slashdot not reality. Go ahead and mod me down.
What the hell is wrong with these people? (Score:5, Insightful)
Re: (Score:3, Insightful)
Re: (Score:3, Insightful)
Anyone writing free software for that community have my sympathy.
[ Th
Re: (Score:3, Insightful)
Sorry, when but when I read or hear things implicit, they come out as screaming explicit. That particular conversation would be no less civil if laced with expletives and "your mom" comments.
Oversimplified... (Score:3, Informative)
That said, even done properly chroot really only provides a little protection, and only in the case of horribly configured systems... IMHO, the sole benefit of chrooting a process is that anyone who successfully breaks-in can't execute SUID/SGID applications located elsewhere on the filesystem, which very, very commonly have security holes. Proper use of either sudo, or setting-up groups that are the only ones allowed to exec SUID/SGID applications, eliminates this big security hole.
People like to say that chroot prevents attackers from running anything within the chroot, but it really doesn't... No doubt the exploit code used to break-in directly overwrites locations in memory. A similar method can be used to run any code you wish, no matter what is or isn't available inside the chroot. It certainly won't stop someone from exploiting kernel bugs, generating/reading network traffic, etc.
Of course, these are the same types of people that think their systems are safer for having removed the compilers, and other (non-SUID/SGID) binaries that harmlessly occupy HDD space.
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)
chroot neither is nor isn't a security tool (Score:4, Insightful)
The correct word would have been ignorant (Score:3, Insightful)
I'm rather weary of the "I have a bigger pen^H^H^H brain than you do" bullshit that goes on in IT.
When not to use chroot (Score:4, Funny)
2. While operating a motor vehicle.
3. While dining at an expensive restaurant.
4. While dancing.
5. While urinating.
6. While defending yourself against a murder charge.
7. While picking fleas off a gorilla's back.
8. While seasoning a fine hamburger patty.
9. While being arrested.
10. While having sex.
Re:Then what is it for? (Score:5, Informative)
Citation (Score:5, Informative)
http://blogs.sun.com/chrisg/tags/chroot [sun.com]
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.
Re: (Score:2, Funny)
Re: (Score:2, Informative)
linux doesn't have jail. However, user mode linux and the like accomplish the same thing.
I've also seen attempts to fake a jail using LD_PRELOAD funstion stubs to filter system calls. However, since the filtering is not done in the kernel, it's possible for another thread to modify the arguments after they've been verified but before they actual system call takes place (ie, a race condition).
There was a slashdot article about this a couple months ago, but damned if I can find it now.