DragonFly BSD
DragonFly kernel List (threaded) for 2004-03
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: Q: chroot(9) returning EFAULT

From: Matthew Dillon <dillon@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 15 Mar 2004 18:03:18 -0800 (PST)

: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:
: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?

    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

					Matthew Dillon 

[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]