signal_compat.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #include <linux/compat.h>
  2. #include <linux/uaccess.h>
  3. int copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from)
  4. {
  5. int err = 0;
  6. bool ia32 = test_thread_flag(TIF_IA32);
  7. if (!access_ok(VERIFY_WRITE, to, sizeof(compat_siginfo_t)))
  8. return -EFAULT;
  9. put_user_try {
  10. /* If you change siginfo_t structure, please make sure that
  11. this code is fixed accordingly.
  12. It should never copy any pad contained in the structure
  13. to avoid security leaks, but must copy the generic
  14. 3 ints plus the relevant union member. */
  15. put_user_ex(from->si_signo, &to->si_signo);
  16. put_user_ex(from->si_errno, &to->si_errno);
  17. put_user_ex((short)from->si_code, &to->si_code);
  18. if (from->si_code < 0) {
  19. put_user_ex(from->si_pid, &to->si_pid);
  20. put_user_ex(from->si_uid, &to->si_uid);
  21. put_user_ex(ptr_to_compat(from->si_ptr), &to->si_ptr);
  22. } else {
  23. /*
  24. * First 32bits of unions are always present:
  25. * si_pid === si_band === si_tid === si_addr(LS half)
  26. */
  27. put_user_ex(from->_sifields._pad[0],
  28. &to->_sifields._pad[0]);
  29. switch (from->si_code >> 16) {
  30. case __SI_FAULT >> 16:
  31. break;
  32. case __SI_SYS >> 16:
  33. put_user_ex(from->si_syscall, &to->si_syscall);
  34. put_user_ex(from->si_arch, &to->si_arch);
  35. break;
  36. case __SI_CHLD >> 16:
  37. if (ia32) {
  38. put_user_ex(from->si_utime, &to->si_utime);
  39. put_user_ex(from->si_stime, &to->si_stime);
  40. } else {
  41. put_user_ex(from->si_utime, &to->_sifields._sigchld_x32._utime);
  42. put_user_ex(from->si_stime, &to->_sifields._sigchld_x32._stime);
  43. }
  44. put_user_ex(from->si_status, &to->si_status);
  45. /* FALL THROUGH */
  46. default:
  47. case __SI_KILL >> 16:
  48. put_user_ex(from->si_uid, &to->si_uid);
  49. break;
  50. case __SI_POLL >> 16:
  51. put_user_ex(from->si_fd, &to->si_fd);
  52. break;
  53. case __SI_TIMER >> 16:
  54. put_user_ex(from->si_overrun, &to->si_overrun);
  55. put_user_ex(ptr_to_compat(from->si_ptr),
  56. &to->si_ptr);
  57. break;
  58. /* This is not generated by the kernel as of now. */
  59. case __SI_RT >> 16:
  60. case __SI_MESGQ >> 16:
  61. put_user_ex(from->si_uid, &to->si_uid);
  62. put_user_ex(from->si_int, &to->si_int);
  63. break;
  64. }
  65. }
  66. } put_user_catch(err);
  67. return err;
  68. }
  69. int copy_siginfo_from_user32(siginfo_t *to, compat_siginfo_t __user *from)
  70. {
  71. int err = 0;
  72. u32 ptr32;
  73. if (!access_ok(VERIFY_READ, from, sizeof(compat_siginfo_t)))
  74. return -EFAULT;
  75. get_user_try {
  76. get_user_ex(to->si_signo, &from->si_signo);
  77. get_user_ex(to->si_errno, &from->si_errno);
  78. get_user_ex(to->si_code, &from->si_code);
  79. get_user_ex(to->si_pid, &from->si_pid);
  80. get_user_ex(to->si_uid, &from->si_uid);
  81. get_user_ex(ptr32, &from->si_ptr);
  82. to->si_ptr = compat_ptr(ptr32);
  83. } get_user_catch(err);
  84. return err;
  85. }