ldt.c 2.0 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6
/*
 * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
 * Licensed under the GPL
 */

#include "linux/config.h"
7
#include "linux/sched.h"
L
Linus Torvalds 已提交
8
#include "linux/slab.h"
9
#include "linux/types.h"
L
Linus Torvalds 已提交
10 11
#include "asm/uaccess.h"
#include "asm/ptrace.h"
12 13
#include "asm/smp.h"
#include "asm/ldt.h"
L
Linus Torvalds 已提交
14 15
#include "choose-mode.h"
#include "kern.h"
16
#include "mode_kern.h"
L
Linus Torvalds 已提交
17 18 19

#ifdef CONFIG_MODE_TT

20
extern int modify_ldt(int func, void *ptr, unsigned long bytecount);
L
Linus Torvalds 已提交
21

22
static int do_modify_ldt_tt(int func, void *ptr, unsigned long bytecount)
L
Linus Torvalds 已提交
23 24 25
{
	return modify_ldt(func, ptr, bytecount);
}
26

L
Linus Torvalds 已提交
27 28 29 30
#endif

#ifdef CONFIG_MODE_SKAS

31
#include "skas.h"
L
Linus Torvalds 已提交
32 33
#include "skas_ptrace.h"

34
static int do_modify_ldt_skas(int func, void *ptr, unsigned long bytecount)
L
Linus Torvalds 已提交
35 36
{
	struct ptrace_ldt ldt;
37 38
	u32 cpu;
	int res;
L
Linus Torvalds 已提交
39

40 41 42
	ldt = ((struct ptrace_ldt) { .func	= func,
				     .ptr	= ptr,
				     .bytecount = bytecount });
L
Linus Torvalds 已提交
43

44 45 46 47 48 49 50 51 52 53 54 55 56 57
	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. */
L
Linus Torvalds 已提交
58 59 60

	switch(func){
	case 1:
61 62 63 64 65 66 67 68 69 70 71
	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;
		}
L
Linus Torvalds 已提交
72

73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
		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;
L
Linus Torvalds 已提交
88 89 90
		goto out;
	}

91 92
	res = CHOOSE_MODE_PROC(do_modify_ldt_tt, do_modify_ldt_skas, func,
				p, bytecount);
L
Linus Torvalds 已提交
93 94 95 96 97 98
	if(res < 0)
		goto out;

	switch(func){
	case 0:
	case 2:
99 100 101
		/* Modify_ldt was for reading and returned the number of read
		 * bytes.*/
		if(copy_to_user(ptr, p, res))
L
Linus Torvalds 已提交
102 103 104 105
			res = -EFAULT;
		break;
	}

106
out:
L
Linus Torvalds 已提交
107
	kfree(buf);
108
	return res;
L
Linus Torvalds 已提交
109
}