linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* how do you call userspace syscalls (e.g. sys_rename) from inside kernel
@ 2004-10-08 13:04 Luke Kenneth Casson Leighton
  2004-10-08 13:07 ` Fabiano Ramos
                   ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Luke Kenneth Casson Leighton @ 2004-10-08 13:04 UTC (permalink / raw)
  To: linux-kernel

could someone kindly advise me on the location of some example code in
the kernel which calls one of the userspace system calls from inside the
kernel?

alternatively if this has never been considered before, please could
someone advise me as to how it might be achieved?

thank you,

l.

[p.s. i found asm/unistd.h, i found the macros syscall012345
etc., i believe i don't quite understand what these are for, and
may be on the wrong track.]

-- 
--
Truth, honesty and respect are rare commodities that all spring from
the same well: Love.  If you love yourself and everyone and everything
around you, funnily and coincidentally enough, life gets a lot better.
--
<a href="http://lkcl.net">      lkcl.net      </a> <br />
<a href="mailto:lkcl@lkcl.net"> lkcl@lkcl.net </a> <br />


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

* Re: how do you call userspace syscalls (e.g. sys_rename) from inside kernel
  2004-10-08 13:04 how do you call userspace syscalls (e.g. sys_rename) from inside kernel Luke Kenneth Casson Leighton
@ 2004-10-08 13:07 ` Fabiano Ramos
  2004-10-08 13:38   ` Brice Goglin
  2004-10-08 15:35   ` Luke Kenneth Casson Leighton
  2004-10-08 14:02 ` Brian Gerst
  2004-10-12  0:15 ` Jon Masters
  2 siblings, 2 replies; 20+ messages in thread
From: Fabiano Ramos @ 2004-10-08 13:07 UTC (permalink / raw)
  To: Luke Kenneth Casson Leighton; +Cc: linux-kernel

On Fri, 2004-10-08 at 14:04 +0100, Luke Kenneth Casson Leighton wrote:
> could someone kindly advise me on the location of some example code in
> the kernel which calls one of the userspace system calls from inside the
> kernel?
> 
> alternatively if this has never been considered before, please could
> someone advise me as to how it might be achieved?
> 

you cannot do that. For every sys_xx there is a do_xx, that can
be called from inside the kernel.

> thank you,
> 
> l.
> 
> [p.s. i found asm/unistd.h, i found the macros syscall012345
> etc., i believe i don't quite understand what these are for, and
> may be on the wrong track.]

These are are available for you to make syscalls from user mode
without library support (usually that brand new syscall you added).
They are basically wrappers that expand into C code. _syscallx, 
where x is the number of arguments the syscall needs.

> 


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

* Re: how do you call userspace syscalls (e.g. sys_rename) from inside kernel
  2004-10-08 13:07 ` Fabiano Ramos
@ 2004-10-08 13:38   ` Brice Goglin
  2004-10-08 15:04     ` Fabiano Ramos
  2004-10-08 15:35   ` Luke Kenneth Casson Leighton
  1 sibling, 1 reply; 20+ messages in thread
From: Brice Goglin @ 2004-10-08 13:38 UTC (permalink / raw)
  To: Fabiano Ramos; +Cc: linux-kernel

> For every sys_xx there is a do_xx, that can
> be called from inside the kernel.

Well, not every sys_xx, but most of them :)
For example there's no do_epoll_ctl for sys_epoll_ctl.
I requested this one a long time ago but didn't get it.

Regards,

Brice Goglin
================================================
Ph.D Student
Laboratoire de l'Informatique et du Parallélisme
CNRS-ENS Lyon-INRIA-UCB Lyon

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

* Re: how do you call userspace syscalls (e.g. sys_rename) from inside kernel
  2004-10-08 13:04 how do you call userspace syscalls (e.g. sys_rename) from inside kernel Luke Kenneth Casson Leighton
  2004-10-08 13:07 ` Fabiano Ramos
@ 2004-10-08 14:02 ` Brian Gerst
  2004-10-08 15:18   ` Luke Kenneth Casson Leighton
  2004-10-12  0:15 ` Jon Masters
  2 siblings, 1 reply; 20+ messages in thread
From: Brian Gerst @ 2004-10-08 14:02 UTC (permalink / raw)
  To: Luke Kenneth Casson Leighton; +Cc: linux-kernel

Luke Kenneth Casson Leighton wrote:
> could someone kindly advise me on the location of some example code in
> the kernel which calls one of the userspace system calls from inside the
> kernel?
> 
> alternatively if this has never been considered before, please could
> someone advise me as to how it might be achieved?

What are you trying to do?  In most cases needing to use syscalls from 
within the kernel is an indication of a design flaw.  The most common 
case is loading firmware, which should use request_firmware() instead.

--
				Brian Gerst

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

* Re: how do you call userspace syscalls (e.g. sys_rename) from inside kernel
  2004-10-08 13:38   ` Brice Goglin
@ 2004-10-08 15:04     ` Fabiano Ramos
  0 siblings, 0 replies; 20+ messages in thread
From: Fabiano Ramos @ 2004-10-08 15:04 UTC (permalink / raw)
  To: Brice.Goglin; +Cc: linux-kernel

On Fri, 2004-10-08 at 15:38 +0200, Brice Goglin wrote:
> > For every sys_xx there is a do_xx, that can
> > be called from inside the kernel.
> 
> Well, not every sys_xx, but most of them :)

yes, you're right. ptrace() is another example.
Too quick of an answer from may part  ;)


> For example there's no do_epoll_ctl for sys_epoll_ctl.
> I requested this one a long time ago but didn't get it.
> 
> Regards,
> 
> Brice Goglin
> ================================================
> Ph.D Student
> Laboratoire de l'Informatique et du Parallélisme
> CNRS-ENS Lyon-INRIA-UCB Lyon
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/


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

* Re: how do you call userspace syscalls (e.g. sys_rename) from inside kernel
  2004-10-08 15:18   ` Luke Kenneth Casson Leighton
@ 2004-10-08 15:12     ` Bernd Petrovitsch
  2004-10-08 17:03       ` Luke Kenneth Casson Leighton
  2004-10-08 15:18     ` Brice Goglin
  2004-10-08 15:27     ` Brian Gerst
  2 siblings, 1 reply; 20+ messages in thread
From: Bernd Petrovitsch @ 2004-10-08 15:12 UTC (permalink / raw)
  To: Luke Kenneth Casson Leighton; +Cc: Brian Gerst, linux-kernel

On Fri, 2004-10-08 at 16:18 +0100, Luke Kenneth Casson Leighton wrote:
> On Fri, Oct 08, 2004 at 10:02:08AM -0400, Brian Gerst wrote:
> > Luke Kenneth Casson Leighton wrote:
> > >could someone kindly advise me on the location of some example code in
> > >the kernel which calls one of the userspace system calls from inside the
> > >kernel?
> > >
> > >alternatively if this has never been considered before, please could
> > >someone advise me as to how it might be achieved?
> > 
> > What are you trying to do?  
> 
>  call sys_rename, sys_pread, sys_create, sys_mknod, sys_rmdir
>  etc. - everything that does file access.
> 
> > In most cases needing to use syscalls from 
> > within the kernel is an indication of a design flaw.  
> 
>  in this case it's an attempt to avoid cutting and pasting
>  the entire contents of sys_rename, sys_pread, sys_this,
>  sys_that, removing the first couple and last few lines (that
>  do copy_from_user) and replacing the arguments with either
>  a dentry or a kernel-side char* instead of an __user char*.
> 
>  my alternative is to patch every single vfs-related sys_* in fs/*.c to
>  be able to "plug in" to these functions.

Why not implement it in user-space?

	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] 20+ messages in thread

* Re: how do you call userspace syscalls (e.g. sys_rename) from inside kernel
  2004-10-08 14:02 ` Brian Gerst
@ 2004-10-08 15:18   ` Luke Kenneth Casson Leighton
  2004-10-08 15:12     ` Bernd Petrovitsch
                       ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Luke Kenneth Casson Leighton @ 2004-10-08 15:18 UTC (permalink / raw)
  To: Brian Gerst; +Cc: linux-kernel

On Fri, Oct 08, 2004 at 10:02:08AM -0400, Brian Gerst wrote:
> Luke Kenneth Casson Leighton wrote:
> >could someone kindly advise me on the location of some example code in
> >the kernel which calls one of the userspace system calls from inside the
> >kernel?
> >
> >alternatively if this has never been considered before, please could
> >someone advise me as to how it might be achieved?
> 
> What are you trying to do?  

 call sys_rename, sys_pread, sys_create, sys_mknod, sys_rmdir
 etc. - everything that does file access.

> In most cases needing to use syscalls from 
> within the kernel is an indication of a design flaw.  

 in this case it's an attempt to avoid cutting and pasting
 the entire contents of sys_rename, sys_pread, sys_this,
 sys_that, removing the first couple and last few lines (that
 do copy_from_user) and replacing the arguments with either
 a dentry or a kernel-side char* instead of an __user char*.

 my alternative is to patch every single vfs-related sys_* in fs/*.c to
 be able to "plug in" to these functions.

 l.


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

* Re: how do you call userspace syscalls (e.g. sys_rename) from inside kernel
  2004-10-08 15:18   ` Luke Kenneth Casson Leighton
  2004-10-08 15:12     ` Bernd Petrovitsch
@ 2004-10-08 15:18     ` Brice Goglin
  2004-10-08 16:20       ` Luke Kenneth Casson Leighton
  2004-10-08 15:27     ` Brian Gerst
  2 siblings, 1 reply; 20+ messages in thread
From: Brice Goglin @ 2004-10-08 15:18 UTC (permalink / raw)
  To: Luke Kenneth Casson Leighton; +Cc: linux-kernel

>  call sys_rename, sys_pread, sys_create, sys_mknod, sys_rmdir
>  etc. - everything that does file access.

If you ever actually call sys_this or sys_that ... from
the kernel, you'll have to do something like this to avoid
copy_from/to_user to fail because the target buffer is not
in kernel space:

mm_segment_t old_fs;
old_fs = get_fs();
set_fs(KERNEL_DS);
<do you stuff here>
set_fs(old_fs);

Just look for set_fs in the kernel source to find examples.
--
Brice Goglin
================================================
Ph.D Student
Laboratoire de l'Informatique et du Parallélisme
CNRS-ENS Lyon-INRIA-UCB Lyon
France

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

* Re: how do you call userspace syscalls (e.g. sys_rename) from inside kernel
  2004-10-08 15:18   ` Luke Kenneth Casson Leighton
  2004-10-08 15:12     ` Bernd Petrovitsch
  2004-10-08 15:18     ` Brice Goglin
@ 2004-10-08 15:27     ` Brian Gerst
  2004-10-08 17:04       ` Luke Kenneth Casson Leighton
  2 siblings, 1 reply; 20+ messages in thread
From: Brian Gerst @ 2004-10-08 15:27 UTC (permalink / raw)
  To: Luke Kenneth Casson Leighton; +Cc: linux-kernel

Luke Kenneth Casson Leighton wrote:
> On Fri, Oct 08, 2004 at 10:02:08AM -0400, Brian Gerst wrote:
> 
>>Luke Kenneth Casson Leighton wrote:
>>
>>>could someone kindly advise me on the location of some example code in
>>>the kernel which calls one of the userspace system calls from inside the
>>>kernel?
>>>
>>>alternatively if this has never been considered before, please could
>>>someone advise me as to how it might be achieved?
>>
>>What are you trying to do?  
> 
> 
>  call sys_rename, sys_pread, sys_create, sys_mknod, sys_rmdir
>  etc. - everything that does file access.
> 

Why?  What are you trying to do that cannot be done in userspace?

--
				Brian Gerst

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

* Re: how do you call userspace syscalls (e.g. sys_rename) from inside kernel
  2004-10-08 13:07 ` Fabiano Ramos
  2004-10-08 13:38   ` Brice Goglin
@ 2004-10-08 15:35   ` Luke Kenneth Casson Leighton
  1 sibling, 0 replies; 20+ messages in thread
From: Luke Kenneth Casson Leighton @ 2004-10-08 15:35 UTC (permalink / raw)
  To: Fabiano Ramos; +Cc: linux-kernel

On Fri, Oct 08, 2004 at 10:07:04AM -0300, Fabiano Ramos wrote:
> On Fri, 2004-10-08 at 14:04 +0100, Luke Kenneth Casson Leighton wrote:
> > could someone kindly advise me on the location of some example code in
> > the kernel which calls one of the userspace system calls from inside the
> > kernel?
> > 
> > alternatively if this has never been considered before, please could
> > someone advise me as to how it might be achieved?
> > 
> 
> you cannot do that. For every sys_xx there is a do_xx, that can
> be called from inside the kernel.
 
 so, there's a do_rename (yes i found that and ISTRC that when
 i used it i can't exactly remember what the problem was:
 either i got an error code -14 or i got "warning symbol
 do_rename not found" when my module was linked together,
 even though it says EXPORT_SYMBOL(do_rename) in fs/namei.c,
 so i was forced to cut/paste sys_rename)

 and there's a do_open no there isn't, there's filp_open.

 and a do_pread64 no there isn't i had to cut/paste sys_pread64
 which was okay because it's pretty basic, just call vfs_read.

 and a do_mkdir no there isn't so i had to cut/paste that.


 basically what i am doing is writing a file system "proxy"
 module which re-calls back into the filesystem with a prefix
 onto the front of the pathname.

> > [p.s. i found asm/unistd.h, i found the macros syscall012345
> > etc., i believe i don't quite understand what these are for, and
> > may be on the wrong track.]
> 
> These are are available for you to make syscalls from user mode
> without library support (usually that brand new syscall you added).
> They are basically wrappers that expand into C code. _syscallx, 
> where x is the number of arguments the syscall needs.
 
 so, it's for use the other way round.  okay, thanks for keeping me off
 a broken line of enquiry.

 [oh, and i'll be abandoning this line of enquiry _entirely_ if i find
 that supermount-ng can do the same job - namely manage to keep
 userspace programs happy when users rip out media]
 
-- 
--
Truth, honesty and respect are rare commodities that all spring from
the same well: Love.  If you love yourself and everyone and everything
around you, funnily and coincidentally enough, life gets a lot better.
--
<a href="http://lkcl.net">      lkcl.net      </a> <br />
<a href="mailto:lkcl@lkcl.net"> lkcl@lkcl.net </a> <br />


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

* Re: how do you call userspace syscalls (e.g. sys_rename) from inside kernel
  2004-10-08 15:18     ` Brice Goglin
@ 2004-10-08 16:20       ` Luke Kenneth Casson Leighton
  2004-10-08 16:37         ` Jan-Benedict Glaw
  0 siblings, 1 reply; 20+ messages in thread
From: Luke Kenneth Casson Leighton @ 2004-10-08 16:20 UTC (permalink / raw)
  To: Brice.Goglin; +Cc: linux-kernel

On Fri, Oct 08, 2004 at 05:18:40PM +0200, Brice Goglin wrote:
> > call sys_rename, sys_pread, sys_create, sys_mknod, sys_rmdir
> > etc. - everything that does file access.
> 
> If you ever actually call sys_this or sys_that ... from
> the kernel, you'll have to do something like this to avoid
> copy_from/to_user to fail because the target buffer is not
> in kernel space:
> 
> mm_segment_t old_fs;
> old_fs = get_fs();
> set_fs(KERNEL_DS);
> <do you stuff here>
> set_fs(old_fs);
 
 that's it!  that's what i was looking for.  thank you.

 l.

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

* Re: how do you call userspace syscalls (e.g. sys_rename) from inside kernel
  2004-10-08 16:20       ` Luke Kenneth Casson Leighton
@ 2004-10-08 16:37         ` Jan-Benedict Glaw
  2004-10-08 17:37           ` Luke Kenneth Casson Leighton
  0 siblings, 1 reply; 20+ messages in thread
From: Jan-Benedict Glaw @ 2004-10-08 16:37 UTC (permalink / raw)
  To: Luke Kenneth Casson Leighton; +Cc: Brice.Goglin, linux-kernel

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

On Fri, 2004-10-08 17:20:25 +0100, Luke Kenneth Casson Leighton <lkcl@lkcl.net>
wrote in message <20041008162025.GL5551@lkcl.net>:
> On Fri, Oct 08, 2004 at 05:18:40PM +0200, Brice Goglin wrote:

> > mm_segment_t old_fs;
> > old_fs = get_fs();
> > set_fs(KERNEL_DS);
> > <do you stuff here>
> > set_fs(old_fs);
>  
>  that's it!  that's what i was looking for.  thank you.

Most probably, this is not what you were looking for. You just don't
know that yet (-:

MfG, JBG

-- 
Jan-Benedict Glaw       jbglaw@lug-owl.de    . +49-172-7608481             _ O _
"Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg  _ _ O
 fuer einen Freien Staat voll Freier Bürger" | im Internet! |   im Irak!   O O O
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));

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

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

* Re: how do you call userspace syscalls (e.g. sys_rename) from inside kernel
  2004-10-08 15:12     ` Bernd Petrovitsch
@ 2004-10-08 17:03       ` Luke Kenneth Casson Leighton
  0 siblings, 0 replies; 20+ messages in thread
From: Luke Kenneth Casson Leighton @ 2004-10-08 17:03 UTC (permalink / raw)
  To: Bernd Petrovitsch; +Cc: Brian Gerst, linux-kernel

On Fri, Oct 08, 2004 at 05:12:51PM +0200, Bernd Petrovitsch wrote:

> >  my alternative is to patch every single vfs-related sys_* in fs/*.c to
> >  be able to "plug in" to these functions.
> 
> Why not implement it in user-space?
 
 that is the base that i am working from (fuse).

 the problem comes when adding support to fuse for xattrs, and the
 subsequent use of those xattrs for SE/Linux.

 security/selinux/hooks.c cannot cope with the -512 response
 "please try later" which the fuse module always always always
 sends, in order for fuse to give the userspace daemon a chance
 to wake up and smell the roses.

 ... and i sure ain't gonna hack selinux about!
 
 l.

-- 
--
Truth, honesty and respect are rare commodities that all spring from
the same well: Love.  If you love yourself and everyone and everything
around you, funnily and coincidentally enough, life gets a lot better.
--
<a href="http://lkcl.net">      lkcl.net      </a> <br />
<a href="mailto:lkcl@lkcl.net"> lkcl@lkcl.net </a> <br />


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

* Re: how do you call userspace syscalls (e.g. sys_rename) from inside kernel
  2004-10-08 15:27     ` Brian Gerst
@ 2004-10-08 17:04       ` Luke Kenneth Casson Leighton
  0 siblings, 0 replies; 20+ messages in thread
From: Luke Kenneth Casson Leighton @ 2004-10-08 17:04 UTC (permalink / raw)
  To: Brian Gerst; +Cc: linux-kernel

On Fri, Oct 08, 2004 at 11:27:47AM -0400, Brian Gerst wrote:

> >>What are you trying to do?  
> >
> >
> > call sys_rename, sys_pread, sys_create, sys_mknod, sys_rmdir
> > etc. - everything that does file access.
> >
> 
> Why?  What are you trying to do that cannot be done in userspace?
 
 see other message: i'm trying to combine fuse + its example program
 fusexmp into a kernelspace module: when i added xattrs i get a -512
 pleasetrylater response which selinux cannot cope with.

 l.

-- 
--
Truth, honesty and respect are rare commodities that all spring from
the same well: Love.  If you love yourself and everyone and everything
around you, funnily and coincidentally enough, life gets a lot better.
--
<a href="http://lkcl.net">      lkcl.net      </a> <br />
<a href="mailto:lkcl@lkcl.net"> lkcl@lkcl.net </a> <br />


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

* Re: how do you call userspace syscalls (e.g. sys_rename) from inside kernel
  2004-10-08 16:37         ` Jan-Benedict Glaw
@ 2004-10-08 17:37           ` Luke Kenneth Casson Leighton
  0 siblings, 0 replies; 20+ messages in thread
From: Luke Kenneth Casson Leighton @ 2004-10-08 17:37 UTC (permalink / raw)
  To: Brice.Goglin, linux-kernel

On Fri, Oct 08, 2004 at 06:37:01PM +0200, Jan-Benedict Glaw wrote:
> On Fri, 2004-10-08 17:20:25 +0100, Luke Kenneth Casson Leighton <lkcl@lkcl.net>
> wrote in message <20041008162025.GL5551@lkcl.net>:
> > On Fri, Oct 08, 2004 at 05:18:40PM +0200, Brice Goglin wrote:
> 
> > > mm_segment_t old_fs;
> > > old_fs = get_fs();
> > > set_fs(KERNEL_DS);
> > > <do you stuff here>
> > > set_fs(old_fs);
> >  
> >  that's it!  that's what i was looking for.  thank you.
> 
> Most probably, this is not what you were looking for. You just don't
> know that yet (-:
 
 *grin*.  yeh, like someone else privately responded saying i might want
 to look at compat_alloc_userspace() instead :)



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

* Re: how do you call userspace syscalls (e.g. sys_rename) from inside kernel
  2004-10-08 13:04 how do you call userspace syscalls (e.g. sys_rename) from inside kernel Luke Kenneth Casson Leighton
  2004-10-08 13:07 ` Fabiano Ramos
  2004-10-08 14:02 ` Brian Gerst
@ 2004-10-12  0:15 ` Jon Masters
  2004-10-12 13:16   ` Luke Kenneth Casson Leighton
  2 siblings, 1 reply; 20+ messages in thread
From: Jon Masters @ 2004-10-12  0:15 UTC (permalink / raw)
  To: Luke Kenneth Casson Leighton; +Cc: linux-kernel

On Fri, 8 Oct 2004 14:04:42 +0100, Luke Kenneth Casson Leighton
<lkcl@lkcl.net> wrote:
> could someone kindly advise me on the location of some example code in
> the kernel which calls one of the userspace system calls from inside the
> kernel?

Hi Luke,

I enjoyed your recent talk at OxLUG in which you mentioned this
briefly. Could you please send me the source that you are working on
so that I can take a look and make suggestions if tha'ts useful - I
posted to the OxLUG list but you're not actually on it and although I
now have your address from someone, this post reminded me.

I've copied lkml for two reasons - a). Someone else might want to take
a look. b). I sat and talked with Luke for a while about this, he's
not a typical "I want to do stuff in the kernel I should be doing from
userspace" kind of person in my opinion (there might still be a better
way but until I see more what he's actually doing then I can't work
out what).

Jon.

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

* Re: how do you call userspace syscalls (e.g. sys_rename) from inside kernel
  2004-10-12  0:15 ` Jon Masters
@ 2004-10-12 13:16   ` Luke Kenneth Casson Leighton
  0 siblings, 0 replies; 20+ messages in thread
From: Luke Kenneth Casson Leighton @ 2004-10-12 13:16 UTC (permalink / raw)
  To: jonathan; +Cc: linux-kernel

hiya jon,

i'm placing _a_ version at http://hands.com/~lkcl/fuse.xattr.2.tgz.

it's the "mostly userspace" version, with hacked-up xattrs that "track"
what the userspace code does, inside the kernel.

due to having to implement fuse "getxattr" and friends in
kernel-space (in order to avoid having the -512 error message
returned to selinux/hooks.c), there are two locations in the
code where you must specify the proxy point:

1) example/fusexmp.c you must change "/home/sez" to your-directory.

2) kernel/util.c likewise.

in 1) it is the location where userspace file access occurs.  2) is
obviously matching the userspace xattr access.

i _do_ have a version of fuse where
pretty-much-everything-but-the-inode-allocation-which-is-done-in-libfuse-has-been-moved-to-kernel.

i've been examining a number of kernel modules (ncpfs primarily)
in an attempt to understand how to move libfuse's userspace
inode allocation system into kernelspace.

i'm tempted to abandon fuse and use lufs instead... that has a directory
cache in userspace but at least it appears to allocate inodes in
kernel (using iunique()).

hmmm...


On Tue, Oct 12, 2004 at 01:15:34AM +0100, Jon Masters wrote:
> On Fri, 8 Oct 2004 14:04:42 +0100, Luke Kenneth Casson Leighton
> <lkcl@lkcl.net> wrote:
> > could someone kindly advise me on the location of some example code in
> > the kernel which calls one of the userspace system calls from inside the
> > kernel?
> 
> Hi Luke,
> 
> I enjoyed your recent talk at OxLUG in which you mentioned this
> briefly. Could you please send me the source that you are working on
> so that I can take a look and make suggestions if tha'ts useful - I
> posted to the OxLUG list but you're not actually on it and although I
> now have your address from someone, this post reminded me.
> 
> I've copied lkml for two reasons - a). Someone else might want to take
> a look. b). I sat and talked with Luke for a while about this, he's
> not a typical "I want to do stuff in the kernel I should be doing from
> userspace" kind of person in my opinion (there might still be a better
> way but until I see more what he's actually doing then I can't work
> out what).
> 
> Jon.

-- 
--
Truth, honesty and respect are rare commodities that all spring from
the same well: Love.  If you love yourself and everyone and everything
around you, funnily and coincidentally enough, life gets a lot better.
--
<a href="http://lkcl.net">      lkcl.net      </a> <br />
<a href="mailto:lkcl@lkcl.net"> lkcl@lkcl.net </a> <br />


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

* RE: how do you call userspace syscalls (e.g. sys_rename) from inside kernel
  2004-10-10 23:13 Aboo Valappil
  2004-10-10 23:35 ` Arnd Bergmann
@ 2004-10-11  9:56 ` Jirka Kosina
  1 sibling, 0 replies; 20+ messages in thread
From: Jirka Kosina @ 2004-10-11  9:56 UTC (permalink / raw)
  To: Aboo Valappil; +Cc: Luke Kenneth Casson Leighton, Fabiano Ramos, linux-kernel

On Mon, 11 Oct 2004, Aboo Valappil wrote:

> In the past I looked in to open, read and write a file from a kernel
> module.  But problem I faced using the kernel function was that it
> checks for the permissions of the file and path against the "current"
> process. For eg: open_namei() function ... My requirement was to open
> the file regardless of the permissions on the file and also not by
> modifying task_struct of the current process to change the permissions
> first ! I also wanted not associate the file with the current/any
> processes.  Any ideas on this ?

1) This is offtopic on LKML, kernelnewbies might be more apropriate list
2) look at set_fs() and filp_open() calls, they might be useful for you
3) Think twice if opening files from kernel is the thing you are willing 
to do

-- 
JiKos.


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

* Re: how do you call userspace syscalls (e.g. sys_rename) from inside kernel
  2004-10-10 23:13 Aboo Valappil
@ 2004-10-10 23:35 ` Arnd Bergmann
  2004-10-11  9:56 ` Jirka Kosina
  1 sibling, 0 replies; 20+ messages in thread
From: Arnd Bergmann @ 2004-10-10 23:35 UTC (permalink / raw)
  To: Aboo Valappil; +Cc: Luke Kenneth Casson Leighton, Fabiano Ramos, linux-kernel

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

On Maandag 11 Oktober 2004 01:13, Aboo Valappil wrote:
> I also wanted not associate the file with the current/any
> processes. 
> 
> Any ideas on this ?
> 
> Then I thought of using a work around and avoid opening files in kernel
> mode.

Most of the code that traditionally used to read files from inside the
kernel can be converted to calling request_firmware(). The basic
idea is that you have a user space helper that writes the data into
the kernel instead of the other way round.

	Arnd <><

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

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

* RE: how do you call userspace syscalls (e.g. sys_rename) from inside kernel
@ 2004-10-10 23:13 Aboo Valappil
  2004-10-10 23:35 ` Arnd Bergmann
  2004-10-11  9:56 ` Jirka Kosina
  0 siblings, 2 replies; 20+ messages in thread
From: Aboo Valappil @ 2004-10-10 23:13 UTC (permalink / raw)
  To: Luke Kenneth Casson Leighton, Fabiano Ramos; +Cc: linux-kernel

Hi,

In the past I looked in to open, read and write a file from a kernel
module.  But problem I faced using the kernel function was that it
checks for the permissions of the file and path against the "current"
process. For eg: open_namei() function ... My requirement was to open
the file regardless of the permissions on the file and also not by
modifying task_struct of the current process to change the permissions
first ! I also wanted not associate the file with the current/any
processes. 

Any ideas on this ?

Then I thought of using a work around and avoid opening files in kernel
mode.

Thanks

Aboo


-----Original Message-----
From: linux-kernel-owner@vger.kernel.org
[mailto:linux-kernel-owner@vger.kernel.org] On Behalf Of Luke Kenneth
Casson Leighton
Sent: Saturday, October 09, 2004 1:35 AM
To: Fabiano Ramos
Cc: linux-kernel@vger.kernel.org
Subject: Re: how do you call userspace syscalls (e.g. sys_rename) from
inside kernel

On Fri, Oct 08, 2004 at 10:07:04AM -0300, Fabiano Ramos wrote:
> On Fri, 2004-10-08 at 14:04 +0100, Luke Kenneth Casson Leighton wrote:
> > could someone kindly advise me on the location of some example code
in
> > the kernel which calls one of the userspace system calls from inside
the
> > kernel?
> > 
> > alternatively if this has never been considered before, please could
> > someone advise me as to how it might be achieved?
> > 
> 
> you cannot do that. For every sys_xx there is a do_xx, that can
> be called from inside the kernel.
 
 so, there's a do_rename (yes i found that and ISTRC that when
 i used it i can't exactly remember what the problem was:
 either i got an error code -14 or i got "warning symbol
 do_rename not found" when my module was linked together,
 even though it says EXPORT_SYMBOL(do_rename) in fs/namei.c,
 so i was forced to cut/paste sys_rename)

 and there's a do_open no there isn't, there's filp_open.

 and a do_pread64 no there isn't i had to cut/paste sys_pread64
 which was okay because it's pretty basic, just call vfs_read.

 and a do_mkdir no there isn't so i had to cut/paste that.


 basically what i am doing is writing a file system "proxy"
 module which re-calls back into the filesystem with a prefix
 onto the front of the pathname.

> > [p.s. i found asm/unistd.h, i found the macros syscall012345
> > etc., i believe i don't quite understand what these are for, and
> > may be on the wrong track.]
> 
> These are are available for you to make syscalls from user mode
> without library support (usually that brand new syscall you added).
> They are basically wrappers that expand into C code. _syscallx, 
> where x is the number of arguments the syscall needs.
 
 so, it's for use the other way round.  okay, thanks for keeping me off
 a broken line of enquiry.

 [oh, and i'll be abandoning this line of enquiry _entirely_ if i find
 that supermount-ng can do the same job - namely manage to keep
 userspace programs happy when users rip out media]
 
-- 
--
Truth, honesty and respect are rare commodities that all spring from
the same well: Love.  If you love yourself and everyone and everything
around you, funnily and coincidentally enough, life gets a lot better.
--
<a href="http://lkcl.net">      lkcl.net      </a> <br />
<a href="mailto:lkcl@lkcl.net"> lkcl@lkcl.net </a> <br />

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

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

end of thread, other threads:[~2004-10-12 13:05 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-08 13:04 how do you call userspace syscalls (e.g. sys_rename) from inside kernel Luke Kenneth Casson Leighton
2004-10-08 13:07 ` Fabiano Ramos
2004-10-08 13:38   ` Brice Goglin
2004-10-08 15:04     ` Fabiano Ramos
2004-10-08 15:35   ` Luke Kenneth Casson Leighton
2004-10-08 14:02 ` Brian Gerst
2004-10-08 15:18   ` Luke Kenneth Casson Leighton
2004-10-08 15:12     ` Bernd Petrovitsch
2004-10-08 17:03       ` Luke Kenneth Casson Leighton
2004-10-08 15:18     ` Brice Goglin
2004-10-08 16:20       ` Luke Kenneth Casson Leighton
2004-10-08 16:37         ` Jan-Benedict Glaw
2004-10-08 17:37           ` Luke Kenneth Casson Leighton
2004-10-08 15:27     ` Brian Gerst
2004-10-08 17:04       ` Luke Kenneth Casson Leighton
2004-10-12  0:15 ` Jon Masters
2004-10-12 13:16   ` Luke Kenneth Casson Leighton
2004-10-10 23:13 Aboo Valappil
2004-10-10 23:35 ` Arnd Bergmann
2004-10-11  9:56 ` Jirka Kosina

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).