ldt.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
  3. * Licensed under the GPL
  4. */
  5. #include "linux/config.h"
  6. #include "linux/sched.h"
  7. #include "linux/slab.h"
  8. #include "linux/types.h"
  9. #include "asm/uaccess.h"
  10. #include "asm/ptrace.h"
  11. #include "asm/smp.h"
  12. #include "asm/ldt.h"
  13. #include "choose-mode.h"
  14. #include "kern.h"
  15. #include "mode_kern.h"
  16. #ifdef CONFIG_MODE_TT
  17. extern int modify_ldt(int func, void *ptr, unsigned long bytecount);
  18. static int do_modify_ldt_tt(int func, void *ptr, unsigned long bytecount)
  19. {
  20. return modify_ldt(func, ptr, bytecount);
  21. }
  22. #endif
  23. #ifdef CONFIG_MODE_SKAS
  24. #include "skas.h"
  25. #include "skas_ptrace.h"
  26. static int do_modify_ldt_skas(int func, void *ptr, unsigned long bytecount)
  27. {
  28. struct ptrace_ldt ldt;
  29. u32 cpu;
  30. int res;
  31. ldt = ((struct ptrace_ldt) { .func = func,
  32. .ptr = ptr,
  33. .bytecount = bytecount });
  34. cpu = get_cpu();
  35. res = ptrace(PTRACE_LDT, userspace_pid[cpu], 0, (unsigned long) &ldt);
  36. put_cpu();
  37. return res;
  38. }
  39. #endif
  40. int sys_modify_ldt(int func, void __user *ptr, unsigned long bytecount)
  41. {
  42. struct user_desc info;
  43. int res = 0;
  44. void *buf = NULL;
  45. void *p = NULL; /* What we pass to host. */
  46. switch(func){
  47. case 1:
  48. case 0x11: /* write_ldt */
  49. /* Do this check now to avoid overflows. */
  50. if (bytecount != sizeof(struct user_desc)) {
  51. res = -EINVAL;
  52. goto out;
  53. }
  54. if(copy_from_user(&info, ptr, sizeof(info))) {
  55. res = -EFAULT;
  56. goto out;
  57. }
  58. p = &info;
  59. break;
  60. case 0:
  61. case 2: /* read_ldt */
  62. /* The use of info avoids kmalloc on the write case, not on the
  63. * read one. */
  64. buf = kmalloc(bytecount, GFP_KERNEL);
  65. if (!buf) {
  66. res = -ENOMEM;
  67. goto out;
  68. }
  69. p = buf;
  70. default:
  71. res = -ENOSYS;
  72. goto out;
  73. }
  74. res = CHOOSE_MODE_PROC(do_modify_ldt_tt, do_modify_ldt_skas, func,
  75. p, bytecount);
  76. if(res < 0)
  77. goto out;
  78. switch(func){
  79. case 0:
  80. case 2:
  81. /* Modify_ldt was for reading and returned the number of read
  82. * bytes.*/
  83. if(copy_to_user(ptr, p, res))
  84. res = -EFAULT;
  85. break;
  86. }
  87. out:
  88. kfree(buf);
  89. return res;
  90. }