This source file includes following definitions.
- read_ldt
- write_ldt
- sys_modify_ldt
1
2
3
4
5
6
7 #include <linux/config.h>
8 #include <linux/errno.h>
9 #include <linux/sched.h>
10 #include <linux/string.h>
11 #include <asm/segment.h>
12 #include <asm/system.h>
13 #include <linux/ldt.h>
14
15 static int read_ldt(void * ptr, unsigned long bytecount)
16 {
17 int error;
18 void * address = current->ldt;
19 unsigned long size;
20
21 if (!ptr)
22 return -EINVAL;
23 size = PAGE_SIZE;
24 if (!address) {
25 address = &default_ldt;
26 size = sizeof(default_ldt);
27 }
28 if (size > bytecount)
29 size = bytecount;
30 error = verify_area(VERIFY_WRITE, ptr, size);
31 if (error)
32 return error;
33 memcpy_tofs(ptr, address, size);
34 return size;
35 }
36
37 static int write_ldt(void * ptr, unsigned long bytecount)
38 {
39 struct modify_ldt_ldt_s ldt_info;
40 unsigned long *lp;
41 unsigned long base, limit;
42 int error, i;
43
44 if (bytecount != sizeof(ldt_info))
45 return -EINVAL;
46 error = verify_area(VERIFY_READ, ptr, sizeof(ldt_info));
47 if (error)
48 return error;
49
50 memcpy_fromfs(&ldt_info, ptr, sizeof(ldt_info));
51
52 if (ldt_info.contents == 3 || ldt_info.entry_number >= 512)
53 return -EINVAL;
54
55 limit = ldt_info.limit;
56 base = ldt_info.base_addr;
57 if (ldt_info.limit_in_pages)
58 limit *= PAGE_SIZE;
59
60 limit += base;
61 if (limit < base || limit >= 0xC0000000)
62 return -EINVAL;
63
64 if (!current->ldt) {
65 for (i=1 ; i<NR_TASKS ; i++) {
66 if (task[i] == current) {
67 if (!(current->ldt = (struct desc_struct*) get_free_page(GFP_KERNEL)))
68 return -ENOMEM;
69 set_ldt_desc(gdt+(i<<1)+FIRST_LDT_ENTRY, current->ldt, 512);
70 load_ldt(i);
71 }
72 }
73 }
74
75 lp = (unsigned long *) ¤t->ldt[ldt_info.entry_number];
76 *lp = ((ldt_info.base_addr & 0x0000ffff) << 16) |
77 (ldt_info.limit & 0x0ffff);
78 *(lp+1) = (ldt_info.base_addr & 0xff000000) |
79 ((ldt_info.base_addr & 0x00ff0000)>>16) |
80 (ldt_info.limit & 0xf0000) |
81 (ldt_info.contents << 10) |
82 ((ldt_info.read_exec_only ^ 1) << 9) |
83 (ldt_info.seg_32bit << 22) |
84 (ldt_info.limit_in_pages << 23) |
85 0xf000;
86 return 0;
87 }
88
89 asmlinkage int sys_modify_ldt(int func, void *ptr, unsigned long bytecount)
90 {
91 if (func == 0)
92 return read_ldt(ptr, bytecount);
93 if (func == 1)
94 return write_ldt(ptr, bytecount);
95 return -ENOSYS;
96 }