Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 1 Dec 2005 13:45:47 +0200
From:      Andrey Simonenko <simon@comsys.ntu-kpi.kiev.ua>
To:        Daniel Rudy <dr2867@pacbell.net>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: Page fault in kernel mode from LKM
Message-ID:  <20051201114547.GA1843@pm513-1.comsys.ntu-kpi.kiev.ua>
In-Reply-To: <438E9BDF.4060902@pacbell.net>
References:  <438E9BDF.4060902@pacbell.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Nov 30, 2005 at 10:44:47PM -0800, Daniel Rudy wrote:
> 
> 
> http://pastebin.com/444571
> 
> I'm not sure WHY it keeps panicing the system.  This is code that is
> part of a klm that I'm writing.  Any ideas?
> 

It would be better to insert code of your KLD in your letter.
I think your KLD module has some problems.

You cannot access vm_map without holding lock on vm_map,
use vm_map_lock() and vm_map_unlock() for this.

If some program is multithreaded, then some thread can use
sbrk() (which calls obreak()) and you will have race condition
between your functions mod_xfrom_allocate() and mod_xform_free().

As I understand mod_syscall_open() is a wrapper for open() syscall
and its address is setuped in p_sysent->sv_table.  If my assumption
is correct, then your wrapper gets pointer to uap, which is already
in the kernel space.  Read i386/trap.c:syscall(), copyin() already
was called for the address in the user space.

Why you do not see this mistake?  Because return value of copyin()
and copyout() should be checked.  I think you get EFAULT from copyin,
since uap is in stack, which is in KVM.  You correctly noticed that
original open() returns EFAULT, this is because supplied buffer has
garbage.

If I understood your code correctly, then it looks like, that
you need to revisit logic of your wrapper, and allocate memory
only for arguments which are in the user space.  Also, I'm not
sure why you decided (again incorrectly) to copy *uap back to
user space, it can confuse program.

Hope this can help.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20051201114547.GA1843>