2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
|
|
|
|
* Licensed under the GPL
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "linux/config.h"
|
2005-07-14 09:33:37 +02:00
|
|
|
#include "linux/sched.h"
|
2005-04-17 00:20:36 +02:00
|
|
|
#include "linux/slab.h"
|
2005-07-14 09:33:37 +02:00
|
|
|
#include "linux/types.h"
|
2005-04-17 00:20:36 +02:00
|
|
|
#include "asm/uaccess.h"
|
|
|
|
#include "asm/ptrace.h"
|
2005-07-14 09:33:37 +02:00
|
|
|
#include "asm/smp.h"
|
|
|
|
#include "asm/ldt.h"
|
2005-04-17 00:20:36 +02:00
|
|
|
#include "choose-mode.h"
|
|
|
|
#include "kern.h"
|
2005-07-14 09:33:37 +02:00
|
|
|
#include "mode_kern.h"
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_MODE_TT
|
|
|
|
|
2005-07-14 09:33:37 +02:00
|
|
|
extern int modify_ldt(int func, void *ptr, unsigned long bytecount);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2005-07-14 09:33:37 +02:00
|
|
|
static int do_modify_ldt_tt(int func, void *ptr, unsigned long bytecount)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
return modify_ldt(func, ptr, bytecount);
|
|
|
|
}
|
2005-07-14 09:33:37 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_MODE_SKAS
|
|
|
|
|
2005-07-14 09:33:37 +02:00
|
|
|
#include "skas.h"
|
2005-04-17 00:20:36 +02:00
|
|
|
#include "skas_ptrace.h"
|
|
|
|
|
2005-07-14 09:33:37 +02:00
|
|
|
static int do_modify_ldt_skas(int func, void *ptr, unsigned long bytecount)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
struct ptrace_ldt ldt;
|
2005-07-14 09:33:37 +02:00
|
|
|
u32 cpu;
|
|
|
|
int res;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2005-07-14 09:33:37 +02:00
|
|
|
ldt = ((struct ptrace_ldt) { .func = func,
|
|
|
|
.ptr = ptr,
|
|
|
|
.bytecount = bytecount });
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2005-07-14 09:33:37 +02:00
|
|
|
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. */
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
switch(func){
|
|
|
|
case 1:
|
2005-07-14 09:33:37 +02:00
|
|
|
case 0x11: /* write_ldt */
|
|
|
|
/* Do this check now to avoid overflows. */
|
|
|
|
if (bytecount != sizeof(struct user_desc)) {
|
|
|
|
res = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(copy_from_user(&info, ptr, sizeof(info))) {
|
|
|
|
res = -EFAULT;
|
|
|
|
goto out;
|
|
|
|
}
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2005-07-14 09:33:37 +02:00
|
|
|
p = &info;
|
|
|
|
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;
|
2005-09-21 18:38:57 +02:00
|
|
|
break;
|
2005-07-14 09:33:37 +02:00
|
|
|
default:
|
|
|
|
res = -ENOSYS;
|
2005-04-17 00:20:36 +02:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2005-07-14 09:33:37 +02:00
|
|
|
res = CHOOSE_MODE_PROC(do_modify_ldt_tt, do_modify_ldt_skas, func,
|
|
|
|
p, bytecount);
|
2005-04-17 00:20:36 +02:00
|
|
|
if(res < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
switch(func){
|
|
|
|
case 0:
|
|
|
|
case 2:
|
2005-07-14 09:33:37 +02:00
|
|
|
/* Modify_ldt was for reading and returned the number of read
|
|
|
|
* bytes.*/
|
|
|
|
if(copy_to_user(ptr, p, res))
|
2005-04-17 00:20:36 +02:00
|
|
|
res = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-07-14 09:33:37 +02:00
|
|
|
out:
|
2005-04-17 00:20:36 +02:00
|
|
|
kfree(buf);
|
2005-07-14 09:33:37 +02:00
|
|
|
return res;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|