linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: userspace vs. kernelspace address
       [not found] <20050128075209.GA14153@vagabond>
@ 2005-01-28 21:40 ` Rock Gordon
  2005-01-29  4:23   ` Om
  2005-01-30 15:37   ` Bernd Petrovitsch
  0 siblings, 2 replies; 4+ messages in thread
From: Rock Gordon @ 2005-01-28 21:40 UTC (permalink / raw)
  To: Jan Hudec; +Cc: linux-kernel, kernelnewbies, Bernd Petrovitsch

Hi everbody,

Thanks for your replies.

Lemme explain my problem a little bit more .... I have
a thread that does exactly similar things in
kernel-mode and user-mode (depending on how you
invoked it; of course, the kernel one is forked using
kernel_thread(), and the user one is from
pthread_create()). The architecture-dependant stuff is
taken care of by extensive use of __KERNEL__ macro
testing.

This particular thread gets a packet of data, the
header of which contains address to where it should be
copying the payload associated with that packet. The
kernel-mode thread will need to decide how to copy
data into another process' address space, so will the
user-mode thread.

However I think my copy_to_user and copy_from_user are
failing since the kernel-mode thread is copying data
into another process's address space, and I am not
sure how to do this. Do the get_fs() and set_fs()
combinations let you do that? If not, then how do I do
it?

Something like when you invoke the ->write or ->read
functions, you need to copy the requisite data into
the buffer the application provided you with.

Thanks and regards,
Rock


--- Jan Hudec <bulb@ucw.cz> wrote:

> On Fri, Jan 28, 2005 at 01:06:21 +0100, Bernd
> Petrovitsch wrote:
> > On Thu, 2005-01-27 at 09:14 -0800, Rock Gordon
> wrote:
> > > If I'm given a particular address, how do I test
> > > whether that address is from userspace or from
> kernel
> > > space?
> > 
> > You don't.
> > 
> > > I need to make these decisions from either
> inside a
> > > kernel module or a userspace program. The idea
> is I
> > > use memcpy() in the user-user version,
> > > copy_from/to_user in the kernel-kernel version,
> and
> > > prohibit the others.
> > 
> > You need to know where the address is from and use
> the correct function.
> 
> If the interface is defined as taking userland
> address, than kernel
> function passing a kernel address in is responsible
> for calling
> set_fs(KERNEL_DS) before and undoing it after. That
> way the
> copy_to/from_user does not complain.
> 
>
-------------------------------------------------------------------------------
> 						 Jan 'Bulb' Hudec <bulb@ucw.cz>
> 

> ATTACHMENT part 2 application/pgp-signature
name=signature.asc




		
__________________________________ 
Do you Yahoo!? 
Take Yahoo! Mail with you! Get it on your mobile phone. 
http://mobile.yahoo.com/maildemo 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: userspace vs. kernelspace address
  2005-01-28 21:40 ` userspace vs. kernelspace address Rock Gordon
@ 2005-01-29  4:23   ` Om
  2005-01-30  8:41     ` Jan Hudec
  2005-01-30 15:37   ` Bernd Petrovitsch
  1 sibling, 1 reply; 4+ messages in thread
From: Om @ 2005-01-29  4:23 UTC (permalink / raw)
  To: Rock Gordon; +Cc: Jan Hudec, linux-kernel, kernelnewbies, Bernd Petrovitsch

On Fri, Jan 28, 2005 at 01:40:51PM -0800, Rock Gordon wrote:
> Hi everbody,
> 
> Thanks for your replies.
> 
> However I think my copy_to_user and copy_from_user are
> failing since the kernel-mode thread is copying data
> into another process's address space, and I am not
> sure how to do this. Do the get_fs() and set_fs()
> combinations let you do that? If not, then how do I do
My idea is on kernel thread is limited. But I think it is not possible to
any userspace address from any kernel thread because they do not have access
to it. Their proc_struct->mm field is empty.
I am not sure whether set_fs and get_fs help in this case.

HTH,
Om

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: userspace vs. kernelspace address
  2005-01-29  4:23   ` Om
@ 2005-01-30  8:41     ` Jan Hudec
  0 siblings, 0 replies; 4+ messages in thread
From: Jan Hudec @ 2005-01-30  8:41 UTC (permalink / raw)
  To: Om; +Cc: Rock Gordon, linux-kernel, kernelnewbies, Bernd Petrovitsch

[-- Attachment #1: Type: text/plain, Size: 1105 bytes --]

On Fri, Jan 28, 2005 at 20:23:55 -0800, Om wrote:
> On Fri, Jan 28, 2005 at 01:40:51PM -0800, Rock Gordon wrote:
> > Hi everbody,
> > 
> > Thanks for your replies.
> > 
> > However I think my copy_to_user and copy_from_user are
> > failing since the kernel-mode thread is copying data
> > into another process's address space, and I am not
> > sure how to do this. Do the get_fs() and set_fs()
> > combinations let you do that? If not, then how do I do
> My idea is on kernel thread is limited. But I think it is not possible to
> any userspace address from any kernel thread because they do not have access
> to it. Their proc_struct->mm field is empty.

Right. You can't access any user-space from kernel thread, because it
does not have any.

> I am not sure whether set_fs and get_fs help in this case.

Sure it can. set_fs(KERNEL_DS) sets things so, that if you pass kernel
address to copy_to/from_user, it will silently accept it and copy
to/from there.

-------------------------------------------------------------------------------
						 Jan 'Bulb' Hudec <bulb@ucw.cz>

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: userspace vs. kernelspace address
  2005-01-28 21:40 ` userspace vs. kernelspace address Rock Gordon
  2005-01-29  4:23   ` Om
@ 2005-01-30 15:37   ` Bernd Petrovitsch
  1 sibling, 0 replies; 4+ messages in thread
From: Bernd Petrovitsch @ 2005-01-30 15:37 UTC (permalink / raw)
  To: Rock Gordon; +Cc: Jan Hudec, linux-kernel, kernelnewbies

On Fri, 2005-01-28 at 13:40 -0800, Rock Gordon wrote:
> Lemme explain my problem a little bit more .... I have
> a thread that does exactly similar things in
> kernel-mode and user-mode (depending on how you
> invoked it; of course, the kernel one is forked using
> kernel_thread(), and the user one is from
> pthread_create()). The architecture-dependant stuff is
> taken care of by extensive use of __KERNEL__ macro
> testing.

You can than use the same macros for getting to correct copying
function.

	Bernd
-- 
Firmix Software GmbH                   http://www.firmix.at/
mobil: +43 664 4416156                 fax: +43 1 7890849-55
          Embedded Linux Development and Services




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-01-30 15:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20050128075209.GA14153@vagabond>
2005-01-28 21:40 ` userspace vs. kernelspace address Rock Gordon
2005-01-29  4:23   ` Om
2005-01-30  8:41     ` Jan Hudec
2005-01-30 15:37   ` Bernd Petrovitsch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).