Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 4802
b: refs/heads/master
c: 2e5e559
h: refs/heads/master
v: v3
  • Loading branch information
Paolo 'Blaisorblade' Giarrusso authored and Linus Torvalds committed Jul 14, 2005
1 parent e8a3bcc commit a126da4
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 53 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 1feb8d2d7396748fb3bd6795d09bbfbdd4c03dff
refs/heads/master: 2e5e55923e315e8198f46f24f7ca37e1fd9aa102
114 changes: 62 additions & 52 deletions trunk/arch/um/sys-i386/ldt.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,96 +4,106 @@
*/

#include "linux/config.h"
#include "linux/sched.h"
#include "linux/slab.h"
#include "linux/types.h"
#include "asm/uaccess.h"
#include "asm/ptrace.h"
#include "asm/smp.h"
#include "asm/ldt.h"
#include "choose-mode.h"
#include "kern.h"
#include "mode_kern.h"

#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);
}

#endif

#ifdef CONFIG_MODE_SKAS
extern int userspace_pid[];

#include "skas.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;
void *buf;
int res, n;
u32 cpu;
int res;

buf = kmalloc(bytecount, GFP_KERNEL);
if(buf == NULL)
return(-ENOMEM);
ldt = ((struct ptrace_ldt) { .func = func,
.ptr = ptr,
.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){
case 1:
case 0x11:
res = copy_from_user(buf, ptr, bytecount);
break;
}
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;
}

if(res != 0){
res = -EFAULT;
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;
default:
res = -ENOSYS;
goto out;
}

ldt = ((struct ptrace_ldt) { .func = func,
.ptr = buf,
.bytecount = bytecount });
#warning Need to look up userspace_pid by cpu
res = ptrace(PTRACE_LDT, userspace_pid[0], 0, (unsigned long) &ldt);
res = CHOOSE_MODE_PROC(do_modify_ldt_tt, do_modify_ldt_skas, func,
p, bytecount);
if(res < 0)
goto out;

switch(func){
case 0:
case 2:
n = res;
res = copy_to_user(ptr, buf, n);
if(res != 0)
/* Modify_ldt was for reading and returned the number of read
* bytes.*/
if(copy_to_user(ptr, p, res))
res = -EFAULT;
else
res = n;
break;
}

out:
out:
kfree(buf);
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));
return res;
}



/*
* 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:
*/
5 changes: 5 additions & 0 deletions trunk/include/asm-um/ldt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#ifndef __UM_LDT_H
#define __UM_LDT_H

#include "asm/arch/ldt.h"
#endif

0 comments on commit a126da4

Please sign in to comment.