Skip to contentSkip to conversation

2.6.18 - check for chroot, broken root and cwd values in procfs

DISCUSSION Bastian Blank 4 participants 5 messages Oct 12, 2006 – Oct 21, 2006

lore
Share & tools
lore
#0 lore raw

Hi folks

The commit 778c1144771f0064b6f51bee865cceb0d996f2f9 replaced the old root-based security checks in procfs with processed based ones.

This makes the old check for chroot "[ -r /proc/1/root ]" unusable as readlink on it now always succedds. Also it provides buggy values inside a chroot, both /proc/1/root and /proc/self/root points to / but in real they are different.

Is this a desired output or can I call this a bug? If the behaviour is correct, is there a replacement for this check?

Bastian

Signature · 2 lines
Behind every great man, there is a woman -- urging him on.
		-- Harry Mudd, "I, Mudd", stardate 4513.3
#1 lore raw
Quoted 2 lines · Bastian Blank

Is this a desired output or can I call this a bug? If the behaviour is correct, is there a replacement for this check?

[ "$(stat -c "%d/%i" /)" = "$(stat -Lc "%d/%i" /proc/1/root)" ]

Andreas.

Signature · 4 lines
Andreas Schwab, SuSE Labs, [email protected]
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
#2 lore raw
In reply to Bastian Blank
Quoted 2 lines · Bastian Blank

The commit 778c1144771f0064b6f51bee865cceb0d996f2f9 replaced the old root-based security checks in procfs with processed based ones.

The new behaviour even allows a user to escape from the chroot by using chdir to /proc/$pid/cwd or /proc/$pid/root of a process he owns and lives outside of the chroot.

Bastian

Signature · 2 lines
Punishment becomes ineffective after a certain point.  Men become insensitive.
		-- Eneg, "Patterns of Force", stardate 2534.7
#3 lore raw
Quoted 7 lines · Bastian Blank
Quoted 2 lines · Bastian Blank

The commit 778c1144771f0064b6f51bee865cceb0d996f2f9 replaced the old root-based security checks in procfs with processed based ones.

The new behaviour even allows a user to escape from the chroot by using chdir to /proc/$pid/cwd or /proc/$pid/root of a process he owns and lives outside of the chroot.

Yep. It makes it obvious that you can do that.

If you were in a chroot you could always ptrace a process you own that was outside of the chroot, and cause it to do things, such as open a unix domain socket and pass you it's current root directory.

chroot by itself has never been much of a jail.

Eric

#4 lore raw
Quoted 10 lines · Eric W. Biederman
Quoted 7 lines · Bastian Blank
Quoted 2 lines · Bastian Blank

The commit 778c1144771f0064b6f51bee865cceb0d996f2f9 replaced the old root-based security checks in procfs with processed based ones.

The new behaviour even allows a user to escape from the chroot by using chdir to /proc/$pid/cwd or /proc/$pid/root of a process he owns and lives outside of the chroot.

Quoted 5 lines

Yep. It makes it obvious that you can do that.

If you were in a chroot you could always ptrace a process you own that was outside of the chroot, and cause it to do things, such as open a unix domain socket and pass you it's current root directory.

yes, but it's a bit trickier than remotely telling a script to basically do chdir("/proc/1/cwd").

Quoted 1 line

chroot by itself has never been much of a jail.

OK, but that's not a reason for breaking trivial protection against trivial escape methods.

Also, people sometimes compose build environments using chroot, which at least protect them from accidental escape and corruption of the root FS. It is a bit scary to know that a poorly designed install script could break out of the chroot by abusing /proc or simply doing dirty things such as "find / -follow" for any valid purpose under such an environment.

Chroot is a useful tool for build and test environments, it's dangerous to break it that way.

I'd clearly prefer that tasks outside the chroot show broken links for cwd, root and exe under /proc.

Regards,
willy