Chroot in ftpd on newer kernel versions

Rob Landley rob at landley.net
Fri Oct 5 01:33:14 UTC 2012


Second try, remembering to cc: the list. (The gmail web UI is painful.)

On Tue, Oct 2, 2012 at 9:25 PM, Harald Becker <ralda at gmx.de> wrote:
> Hi All,
>
> after a lightning stroke hit our house and damaged several electronic
> devices including my router box and computer, I'm going to setup a new
> small home server machine. By this I hit on an issue with chroot in
> Busybox ftpd applet. I didn't look into this, but may be it affects
> other places too:
>
> Newer Linux kernel versions (tested with v3.5.3) seem to disable chroot
> for none root users.

Yeah, I fixed that for Aboriginal Linux back in August, here's my patch:

http://landley.net/hg/aboriginal/file/1535/sources/patches/busybox-ftpd.patch

> If ftpd is called as root it is able to chroot to
> the given directory but continues to access files with root privileges
> (not a wise decision). But if you run ftpd as a different user the
> chroot seems to fail and you are able to do a chdir to root and see
> the full list of files installed on the server machine. In addition you
> have access to all files readable by the user you are running ftpd.

In theory ftpd can do realpath() on each file it works on and then
strncmp against the starting directory (with trailing slash) to veto
files. In practice I just reverted it to the old behavior 1.19 had
because my use case is ftp-ing files into and out of a scripted qemu
instance, fully automatic and it's my code running at both ends.

Rob


More information about the busybox mailing list