Q: chroot(9) returning EFAULT

Matthew Dillon dillon at apollo.backplane.com
Mon Mar 15 18:05:53 PST 2004


:Hey guys,
:
:I'm working on a syscall that has a chroot in it, and for the life
:of me, I can't figure out why chroot(9) keeps returning EFAULT.  I
:took the lead from jail(2) in kern_jail.c and I basically have
:something like this:
:
:int
:my_syscall(struct my_syscall_args *uap)
:{
:       struct chroot_args ca;
:
:       MALLOC(ca.path, const char *, MAXPATHLEN , M_TEMP, M_WAITOK);
:       error = copystr(someotherpath, ca.path, MAXPATHLEN, 0);
:       if (error)
:               return (error);
:       error = chroot(&ca);
:       if (error)
:                return (error);
:       FREE(ca.path, M_TEMP);
:}
:
:Where someotherpath was allocated by another thread but still
:exists in kernel space.  However, even if ca.path points to a
:char[MAXPATHLEN] on the stack it still returns EFAULT.  Help!  I'm
:definately missing something here and I don't see it.  Any ideas?
:
:-Paul.

    chroot() is expecting arguments in userspace, you are handing it
    kernelspace addresses.

    What you need to do is to separate chroot() into chroot() (which
    takes userspace arguments) and kern_chroot() (which takes kernelspace
    arguments).  Then you can call kern_chroot() directly.

    This is what we call 'syscall separation'.  If you (or someone) does
    the work, I'll commit the chroot/kern_chroot split.

    For an example of how to do this, look at the symlink() and kern_symlink()
    procedures in kern/vfs_syscalls.c

					-Matt
					Matthew Dillon 
					<dillon at xxxxxxxxxxxxx>





More information about the Kernel mailing list