Commit 2e5e5592 authored by Paolo 'Blaisorblade' Giarrusso's avatar Paolo 'Blaisorblade' Giarrusso Committed by Linus Torvalds

[PATCH] uml: consolidate modify_ldt

*) Reorganize the two cases of sys_modify_ldt to share all the reasonably
   common code.

*) Avoid memory allocation when unneeded (i.e.  when we are writing and the
   passed buffer size is known), thus not returning ENOMEM (which isn't
   allowed for this syscall, even if there is no strict "specification").

*) Add copy_{from,to}_user to modify_ldt for TT mode.
Signed-off-by: default avatarPaolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Cc: Jeff Dike <jdike@addtoit.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 1feb8d2d
...@@ -4,96 +4,106 @@ ...@@ -4,96 +4,106 @@
*/ */
#include "linux/config.h" #include "linux/config.h"
#include "linux/sched.h"
#include "linux/slab.h" #include "linux/slab.h"
#include "linux/types.h"
#include "asm/uaccess.h" #include "asm/uaccess.h"
#include "asm/ptrace.h" #include "asm/ptrace.h"
#include "asm/smp.h"
#include "asm/ldt.h"
#include "choose-mode.h" #include "choose-mode.h"
#include "kern.h" #include "kern.h"
#include "mode_kern.h"
#ifdef CONFIG_MODE_TT #ifdef CONFIG_MODE_TT
extern int modify_ldt(int func, void *ptr, unsigned long bytecount);
/* XXX this needs copy_to_user and copy_from_user */ extern int modify_ldt(int func, void *ptr, unsigned long bytecount);
int sys_modify_ldt_tt(int func, void __user *ptr, unsigned long bytecount) static int do_modify_ldt_tt(int func, void *ptr, unsigned long bytecount)
{ {
if (!access_ok(VERIFY_READ, ptr, bytecount))
return -EFAULT;
return modify_ldt(func, ptr, bytecount); return modify_ldt(func, ptr, bytecount);
} }
#endif #endif
#ifdef CONFIG_MODE_SKAS #ifdef CONFIG_MODE_SKAS
extern int userspace_pid[];
#include "skas.h"
#include "skas_ptrace.h" #include "skas_ptrace.h"
int sys_modify_ldt_skas(int func, void __user *ptr, unsigned long bytecount) static int do_modify_ldt_skas(int func, void *ptr, unsigned long bytecount)
{ {
struct ptrace_ldt ldt; struct ptrace_ldt ldt;
void *buf; u32 cpu;
int res, n; int res;
buf = kmalloc(bytecount, GFP_KERNEL); ldt = ((struct ptrace_ldt) { .func = func,
if(buf == NULL) .ptr = ptr,
return(-ENOMEM); .bytecount = bytecount });
res = 0; cpu = get_cpu();
res = ptrace(PTRACE_LDT, userspace_pid[cpu], 0, (unsigned long) &ldt);
put_cpu();
return res;
}
#endif
int sys_modify_ldt(int func, void __user *ptr, unsigned long bytecount)
{
struct user_desc info;
int res = 0;
void *buf = NULL;
void *p = NULL; /* What we pass to host. */
switch(func){ switch(func){
case 1: case 1:
case 0x11: case 0x11: /* write_ldt */
res = copy_from_user(buf, ptr, bytecount); /* Do this check now to avoid overflows. */
break; if (bytecount != sizeof(struct user_desc)) {
} res = -EINVAL;
goto out;
}
if(copy_from_user(&info, ptr, sizeof(info))) {
res = -EFAULT;
goto out;
}
if(res != 0){ p = &info;
res = -EFAULT; break;
case 0:
case 2: /* read_ldt */
/* The use of info avoids kmalloc on the write case, not on the
* read one. */
buf = kmalloc(bytecount, GFP_KERNEL);
if (!buf) {
res = -ENOMEM;
goto out;
}
p = buf;
default:
res = -ENOSYS;
goto out; goto out;
} }
ldt = ((struct ptrace_ldt) { .func = func, res = CHOOSE_MODE_PROC(do_modify_ldt_tt, do_modify_ldt_skas, func,
.ptr = buf, p, bytecount);
.bytecount = bytecount });
#warning Need to look up userspace_pid by cpu
res = ptrace(PTRACE_LDT, userspace_pid[0], 0, (unsigned long) &ldt);
if(res < 0) if(res < 0)
goto out; goto out;
switch(func){ switch(func){
case 0: case 0:
case 2: case 2:
n = res; /* Modify_ldt was for reading and returned the number of read
res = copy_to_user(ptr, buf, n); * bytes.*/
if(res != 0) if(copy_to_user(ptr, p, res))
res = -EFAULT; res = -EFAULT;
else
res = n;
break; break;
} }
out: out:
kfree(buf); kfree(buf);
return(res); return res;
}
#endif
int sys_modify_ldt(int func, void __user *ptr, unsigned long bytecount)
{
return(CHOOSE_MODE_PROC(sys_modify_ldt_tt, sys_modify_ldt_skas, func,
ptr, bytecount));
} }
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
#ifndef __UM_LDT_H
#define __UM_LDT_H
#include "asm/arch/ldt.h"
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment