Re: access_ok inside kernelspace -- part II --

Vasili Goutas (vgo@ratio.de)
Thu, 21 Oct 1999 17:23:18 +0200


On Thu, 21 Oct 1999, Alan Cox wrote:
>> work for, by using set_fs()/get_fs() to be able to call sys_open(),
>> sys_write(), sys_read() and sys_close.=20
>> At the beginning all seems ok, but after unloading at some time I get
>> segmantation faults. The seq. faults came from processes like sendmail o=
>> r
>> cron, and I wandered why.=20
>
>It normally means your driver scribbled on memory it didnt own.

But I get it using vmalloc and testet it also with kmalloc. The behavior was
the same.

>
>> I have to say, that my driver is programmed in C++ and I created a Class =
>> for
>> FileAccess. To be sure that it has nothing to do with C++ I wrote a litle
>
>be very careful not to put too much on the stack, also remember that
>new/delete need their own helpers in kernel space and exceptions dont work
I owerloaded the operators so I can use them.
void * TMemManager::operator new(size_t size)
{
void *ptr;
ptr = kmalloc( size, GFP_KERNEL);
for(size_t i=0; i<size; i++)
{
((UCHAR*)ptr)[i] = 0;
}

return ptr;
};

void TMemManager::operator delete(void *DeadObject, size_t size)
{
UNREFERENCED_PARAMETER(size)
kfree( DeadObject );
};

The C++ compiler shows me a lot of warnings which the C compiler does not,
like unreferenced parameter and assignment of -1 to unsigned
variables. I patched the header to be able to see the warnings created by my
code. If someone is interrested in this patch ...

>
>> An other problem is that the file descriptor cannot be createt ones and u=
>> sed in
>> different functions. I tryed getting the file descr. in init_module with
>
>You can't use file descriptors easily in kernel space. Unless you are doing
>accesses specifically in one process context you will cause grief

--
Vasilios Goutas
Software-Development
RATIO Entwicklungen GmbH
Phone:+49-(0)40-369007-0   Admiralitätstr. 59
Fax:+49-(0)40-369007-25    20459 Hamburg
Email: mailto:vgo@ratio.de

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/