compat.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /* 32-bit compatibility syscall for 64-bit systems
  2. *
  3. * Copyright (C) 2004-5 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <linux/syscalls.h>
  12. #include <linux/keyctl.h>
  13. #include <linux/compat.h>
  14. #include <linux/slab.h>
  15. #include "internal.h"
  16. /*
  17. * Instantiate a key with the specified compatibility multipart payload and
  18. * link the key into the destination keyring if one is given.
  19. *
  20. * The caller must have the appropriate instantiation permit set for this to
  21. * work (see keyctl_assume_authority). No other permissions are required.
  22. *
  23. * If successful, 0 will be returned.
  24. */
  25. static long compat_keyctl_instantiate_key_iov(
  26. key_serial_t id,
  27. const struct compat_iovec __user *_payload_iov,
  28. unsigned ioc,
  29. key_serial_t ringid)
  30. {
  31. struct iovec iovstack[UIO_FASTIOV], *iov = iovstack;
  32. struct iov_iter from;
  33. long ret;
  34. if (!_payload_iov)
  35. ioc = 0;
  36. ret = compat_import_iovec(WRITE, _payload_iov, ioc,
  37. ARRAY_SIZE(iovstack), &iov,
  38. &from);
  39. if (ret < 0)
  40. return ret;
  41. ret = keyctl_instantiate_key_common(id, &from, ringid);
  42. kfree(iov);
  43. return ret;
  44. }
  45. /*
  46. * The key control system call, 32-bit compatibility version for 64-bit archs
  47. *
  48. * This should only be called if the 64-bit arch uses weird pointers in 32-bit
  49. * mode or doesn't guarantee that the top 32-bits of the argument registers on
  50. * taking a 32-bit syscall are zero. If you can, you should call sys_keyctl()
  51. * directly.
  52. */
  53. COMPAT_SYSCALL_DEFINE5(keyctl, u32, option,
  54. u32, arg2, u32, arg3, u32, arg4, u32, arg5)
  55. {
  56. switch (option) {
  57. case KEYCTL_GET_KEYRING_ID:
  58. return keyctl_get_keyring_ID(arg2, arg3);
  59. case KEYCTL_JOIN_SESSION_KEYRING:
  60. return keyctl_join_session_keyring(compat_ptr(arg2));
  61. case KEYCTL_UPDATE:
  62. return keyctl_update_key(arg2, compat_ptr(arg3), arg4);
  63. case KEYCTL_REVOKE:
  64. return keyctl_revoke_key(arg2);
  65. case KEYCTL_DESCRIBE:
  66. return keyctl_describe_key(arg2, compat_ptr(arg3), arg4);
  67. case KEYCTL_CLEAR:
  68. return keyctl_keyring_clear(arg2);
  69. case KEYCTL_LINK:
  70. return keyctl_keyring_link(arg2, arg3);
  71. case KEYCTL_UNLINK:
  72. return keyctl_keyring_unlink(arg2, arg3);
  73. case KEYCTL_SEARCH:
  74. return keyctl_keyring_search(arg2, compat_ptr(arg3),
  75. compat_ptr(arg4), arg5);
  76. case KEYCTL_READ:
  77. return keyctl_read_key(arg2, compat_ptr(arg3), arg4);
  78. case KEYCTL_CHOWN:
  79. return keyctl_chown_key(arg2, arg3, arg4);
  80. case KEYCTL_SETPERM:
  81. return keyctl_setperm_key(arg2, arg3);
  82. case KEYCTL_INSTANTIATE:
  83. return keyctl_instantiate_key(arg2, compat_ptr(arg3), arg4,
  84. arg5);
  85. case KEYCTL_NEGATE:
  86. return keyctl_negate_key(arg2, arg3, arg4);
  87. case KEYCTL_SET_REQKEY_KEYRING:
  88. return keyctl_set_reqkey_keyring(arg2);
  89. case KEYCTL_SET_TIMEOUT:
  90. return keyctl_set_timeout(arg2, arg3);
  91. case KEYCTL_ASSUME_AUTHORITY:
  92. return keyctl_assume_authority(arg2);
  93. case KEYCTL_GET_SECURITY:
  94. return keyctl_get_security(arg2, compat_ptr(arg3), arg4);
  95. case KEYCTL_SESSION_TO_PARENT:
  96. return keyctl_session_to_parent();
  97. case KEYCTL_REJECT:
  98. return keyctl_reject_key(arg2, arg3, arg4, arg5);
  99. case KEYCTL_INSTANTIATE_IOV:
  100. return compat_keyctl_instantiate_key_iov(
  101. arg2, compat_ptr(arg3), arg4, arg5);
  102. case KEYCTL_INVALIDATE:
  103. return keyctl_invalidate_key(arg2);
  104. case KEYCTL_GET_PERSISTENT:
  105. return keyctl_get_persistent(arg2, arg3);
  106. case KEYCTL_DH_COMPUTE:
  107. return compat_keyctl_dh_compute(compat_ptr(arg2),
  108. compat_ptr(arg3),
  109. arg4, compat_ptr(arg5));
  110. case KEYCTL_RESTRICT_KEYRING:
  111. return keyctl_restrict_keyring(arg2, compat_ptr(arg3),
  112. compat_ptr(arg4));
  113. default:
  114. return -EOPNOTSUPP;
  115. }
  116. }