actual sys_indirect code
PATCH v2 1/4 actual sys_indirect code
This is the actual architecture-independent part of the system call implementation.
b/include/linux/indirect.h | 13 ++++++++++++ b/include/linux/syscalls.h | 3 ++ b/kernel/Makefile | 2 - b/kernel/indirect.c | 46 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/sched.h | 4 +++ 5 files changed, 67 insertions(+), 1 deletion(-)
include/linux/sched.h +4 -0
@@ -80,6 +80,7 @@ struct sched_param {#include <linux/rcupdate.h> #include <linux/futex.h> #include <linux/rtmutex.h> +#include <linux/indirect.h> #include <linux/time.h> #include <linux/param.h>
@@ -1174,6 +1175,9 @@ struct task_struct {int make_it_fail;#endif struct prop_local_single dirties; + +/* Additional system call parameters. */ +union indirect_params indirect_params; };/*
include/linux/syscalls.h +3 -0
@@ -54,6 +54,7 @@ struct compat_stat;struct compat_timeval ;struct robust_list_head ;struct getcpu_cache ; +struct indirect_registers ;#include <linux/types.h> #include <linux/aio_abi.h>
@@ -611,6 +612,8 @@ asmlinkage long sys_timerfd(int ufd, int clockid, int flags, const struct itimerspec __user *utmr);asmlinkage long sys_eventfd (unsigned int count);asmlinkage long sys_fallocate (int fd,int mode,loff_t offset,loff_t len); +asmlinkage long sys_indirect (struct indirect_registers __user *userregs, +void __user *userparams,size_t paramslen);int kernel_execve (const char *filename,char *const argv[],char *const envp[]);
kernel/Makefile +1 -1
@@ -9,7 +9,7 @@ obj-y = sched.o fork.o exec_domain.o panic.o printk.o profile.o \ rcupdate.o extable.o params.o posix-timers.o \ kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \ hrtimer.o rwsem.o latency.o nsproxy.o srcu.o \ - utsname.o notifier.o + utsname.o notifier.o indirect.o obj-$(CONFIG_SYSCTL) += sysctl_check.o obj-$(CONFIG_STACKTRACE) += stacktrace.o
include/linux/indirect.h new file +13 -0
@@ -0,0 +1,13 @@ +#ifndef _LINUX_INDIRECT_H +#define _LINUX_INDIRECT_H + +#include <asm/indirect.h> + + +union indirect_params { +struct { +int flags; + } file_flags; +}; + +#endif
kernel/indirect.c new file +46 -0
46 lines not on this page · raw message
Quoted 27 lines · Ulrich Drepper
This is the actual architecture-independent part of the system call implementation.
kernel/indirect.c new file +23
-0+ +long sys_indirect (struct indirect_registers __user *userregs, +void __user *userparams,size_t paramslen) +{ +struct indirect_registers regs; +long result; + +if (copy_from_user (®s, userregs,sizeof (regs))) +return -EFAULT ; + +switch (INDIRECT_SYSCALL (®s)) + { +#ifdef __NR_accept +case __NR_accept: +#endif +#ifdef __NR_socketpair +case __NR_socketpair: +#endif +#ifdef __NR_socket +case __NR_socket: +#endif +#ifdef __NR_socketcall +case __NR_socketcall:
kernel/indirect.c line 38
Quoted 10 lines
kernel/indirect.c new file +10
-0+#endif +break ; + +default : +return -EINVAL ; + } + +if (paramslen >sizeof (union indirect_params )) +return -EINVAL ; +if (copy_from_user (¤t->indirect_params, userparams, paramslen))
Here, you should clear current->indirect_params before returning -EFAULT
{
memset(¤t->indirect_params, 0, paramslen);Review
Quoted 1 line
(quoted diff) +1
-0+ return -EFAULT;
}
copy_from_user could do a partial copy (so dirty first bytes of indirect_params) and all furthers calls to socket()/open() and so on could be broken.
Quoted 8 lines
kernel/indirect.c new file +7
-1+ + result =CALL_INDIRECT (®s); + +memset (¤t->indirect_params,'\0' , paramslen); + +return result; +} -