Main Page | Report this Page
 
   
Linux Forum Index  »  Linux Development - Applications  »  How to call a function in user space from inside the...
Page 1 of 1    
Author Message
Claudio Daffra...
Posted: Thu Sep 04, 2008 2:29 am
Guest
How to call a function in user space from inside the kernel


thx in advance

claudio daffra
Claudio Daffra...
Posted: Thu Sep 04, 2008 2:31 am
Guest
How to call a function in user space from inside the kernel ?

I've come across this problem while working on an my ATM network
driver. When opening a channel the ATM application calls the driver
with a pointer to a receive function that should be called whenever
data is received on that channel.

If I use this pointer (which points into user space) inside the driver
as shown below the whole systems crashes appearently because I'm
trying to execute a user program in kernel mode.

...
receive_ptr(buffer, buffer_size);
...

Does anyone know how to fix this problem?

thx again

claudio
Claudio Daffra...
Posted: Thu Sep 04, 2008 10:41 am
Guest
thank you very much to reply me

regards

claudio daffra
Jens Thoms Toerring...
Posted: Thu Sep 04, 2008 2:27 pm
Guest
Claudio Daffra <daffra.claudio at (no spam) gmail.com> wrote:
Quote:
How to call a function in user space from inside the kernel ?

That would be a huge security problem if you would do so. The
user then could execute arbitrary code with all the permissions
the kernel has. And not only that: any bug in your program could
crash the whole kernel. Neither is acceptable in a multi-tasking,
multi-user system.

Quote:
I've come across this problem while working on an my ATM network
driver. When opening a channel the ATM application calls the driver
with a pointer to a receive function that should be called whenever
data is received on that channel.

If I use this pointer (which points into user space) inside the driver
as shown below the whole systems crashes appearently because I'm
trying to execute a user program in kernel mode.

...
receive_ptr(buffer, buffer_size);
...

How do you expect this to work? The kernel and the user-land
program live in different address spaces. That's why you have
to use copy_from_user() or copy_to_user() in the module in order
to get at data in user-space and copy data from kernel to user
space.

Since making such copies is possible it in principle is also
possible to find out about a translation from kernel to user-
land address space, so theoretically you could figure out the
adress where the function is. But then there's still the pro-
blem that the memory where the function is might be swapped
out, so your code for calling the user-land function would
have to make sure that all of the user-and program and all of
it's data are in memory (which could be impossible if this is
more than the available physical memory...)

If you want your user-land program to be notfified when there
are data to be read it simply could wait for data, if necessary
in a dedicated thread, instead of trying to construct something
which is probably impossible to get right, would open up a huge
security hole and might crash the kernel from a simple user-land
program.
Regards, Jens
--
\ Jens Thoms Toerring ___ jt at (no spam) toerring.de
\__________________________ http://toerring.de
Jasen Betts...
Posted: Fri Sep 05, 2008 6:54 am
Guest
On 2008-09-04, Claudio Daffra <daffra.claudio at (no spam) gmail.com> wrote:
Quote:
How to call a function in user space from inside the kernel

AFAIK Can't

maybe you could use a signal (perhaps SIGIO) to run the user function
and have the user function then communicate with the kernel.

Bye.
Jasen
 
Page 1 of 1       All times are GMT - 5 Hours
The time now is Fri Dec 05, 2008 3:45 am