how do you call userspace syscalls (e.g. sys_rename) from inside 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.]
Signature · 7 lines
-- 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:[email protected]"> [email protected] </a> <br />
Quoted 7 lines · Luke Kenneth Casson Leighton
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.
Quoted 7 lines
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.
Quoted 1 line
Quoted 2 lines
For every
sys_xxthere is ado_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
Quoted 6 lines · Luke Kenneth Casson Leighton
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
Quoted 9 lines · Brian Gerst
Quoted 6 lines · Luke Kenneth Casson Leighton
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.
Quoted 2 lines
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.
Quoted 17 lines · Luke Kenneth Casson Leighton
Quoted 9 lines · Brian Gerst
Quoted 6 lines · Luke Kenneth Casson Leighton
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_rmdiretc. - everything that does file access.Quoted 2 lines
In most cases needing to use syscalls from within the kernel is an indication of a design flaw.
Quoted 8 lines
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 docopy_from_user) and replacing the arguments with either a dentry or a kernel-side char* instead of an__userchar*.my alternative is to patch every single vfs-related sys_* in
fs/*.cto be able to "plug in" to these functions.
Why not implement it in user-space?
Bernd
Signature · 3 lines
Firmix Software GmbH http://www.firmix.at/
mobil: +43 664 4416156 fax: +43 1 7890849-55
Embedded Linux Development and ServicesQuoted 2 lines
call
sys_rename,sys_pread,sys_create,sys_mknod,sys_rmdiretc. - 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
Quoted 11 lines · Fabiano Ramos
Quoted 7 lines · Luke Kenneth Casson Leighton
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_xxthere is ado_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.
Quoted 8 lines
Quoted 3 lines
[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]
Signature · 7 lines
-- 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:[email protected]"> [email protected] </a> <br />
Quoted 8 lines · Luke Kenneth Casson Leighton
Quoted 6 lines · Brian Gerst
Quoted 4 lines · Luke Kenneth Casson Leighton
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?
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
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_rmdiretc. - everything that does file access.
Why? What are you trying to do that cannot be done in userspace?
--
Brian Gerst
Quoted 4 lines · Brice Goglin
Quoted 2 lines
For every
sys_xxthere is ado_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 ;)
Quoted 15 lines
For example there's no
do_epoll_ctlforsys_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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 8 lines · Brice Goglin
Quoted 2 lines
call
sys_rename,sys_pread,sys_create,sys_mknod,sys_rmdiretc. - everything that does file access.If you ever actually call
sys_thisorsys_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:
Quoted 5 lines
mm_segment_told_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.
On Fri, 2004-10-08 17:20:25 +0100, Luke Kenneth Casson Leighton <[email protected]> wrote in message <[email protected]>:
Quoted 9 lines · Brice Goglin
Quoted 6 lines
mm_segment_told_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
Signature · 4 lines
Jan-Benedict Glaw [email protected] . +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));
Quoted 4 lines · Bernd Petrovitsch
Quoted 2 lines
my alternative is to patch every single vfs-related sys_* in
fs/*.cto 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.
Signature · 7 lines
-- 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:[email protected]"> [email protected] </a> <br />
Quoted 8 lines · Brian Gerst
Quoted 6 lines
Quoted 1 line
What are you trying to do?
call
sys_rename,sys_pread,sys_create,sys_mknod,sys_rmdiretc. - 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.
Signature · 7 lines
-- 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:[email protected]"> [email protected] </a> <br />
Quoted 10 lines · Jan-Benedict Glaw
On Fri, 2004-10-08 17:20:25 +0100, Luke Kenneth Casson Leighton <[email protected]> wrote in message <[email protected]>:
Quoted 8 lines · Brice Goglin
Quoted 6 lines
mm_segment_told_fs;old_fs=get_fs();set_fs(KERNEL_DS);
<do you stuff here>set_fs(old_fs);
Quoted 4 lines
Quoted 1 line
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 :)
Quoted 3 lines · Luke Kenneth Casson Leighton
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.
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...
Quoted 22 lines · Jon Masters
Quoted 3 lines · Luke Kenneth Casson Leighton
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.
Signature · 7 lines
-- 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:[email protected]"> [email protected] </a> <br />