compat.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. 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. long ret;
  33. if (_payload_iov == 0 || ioc == 0)
  34. goto no_payload;
  35. ret = compat_rw_copy_check_uvector(WRITE, _payload_iov, ioc,
  36. ARRAY_SIZE(iovstack),
  37. iovstack, &iov);
  38. if (ret < 0)
  39. goto err;
  40. if (ret == 0)
  41. goto no_payload_free;
  42. ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
  43. err:
  44. if (iov != iovstack)
  45. kfree(iov);
  46. return ret;
  47. no_payload_free:
  48. if (iov != iovstack)
  49. kfree(iov);
  50. no_payload:
  51. return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
  52. }
  53. /*
  54. * The key control system call, 32-bit compatibility version for 64-bit archs
  55. *
  56. * This should only be called if the 64-bit arch uses weird pointers in 32-bit
  57. * mode or doesn't guarantee that the top 32-bits of the argument registers on
  58. * taking a 32-bit syscall are zero. If you can, you should call sys_keyctl()
  59. * directly.
  60. */
  61. asmlinkage long compat_sys_keyctl(u32 option,
  62. u32 arg2, u32 arg3, u32 arg4, u32 arg5)
  63. {
  64. switch (option) {
  65. case KEYCTL_GET_KEYRING_ID:
  66. return keyctl_get_keyring_ID(arg2, arg3);
  67. case KEYCTL_JOIN_SESSION_KEYRING:
  68. return keyctl_join_session_keyring(compat_ptr(arg2));
  69. case KEYCTL_UPDATE:
  70. return keyctl_update_key(arg2, compat_ptr(arg3), arg4);
  71. case KEYCTL_REVOKE:
  72. return keyctl_revoke_key(arg2);
  73. case KEYCTL_DESCRIBE:
  74. return keyctl_describe_key(arg2, compat_ptr(arg3), arg4);
  75. case KEYCTL_CLEAR:
  76. return keyctl_keyring_clear(arg2);
  77. case KEYCTL_LINK:
  78. return keyctl_keyring_link(arg2, arg3);
  79. case KEYCTL_UNLINK:
  80. return keyctl_keyring_unlink(arg2, arg3);
  81. case KEYCTL_SEARCH:
  82. return keyctl_keyring_search(arg2, compat_ptr(arg3),
  83. compat_ptr(arg4), arg5);
  84. case KEYCTL_READ:
  85. return keyctl_read_key(arg2, compat_ptr(arg3), arg4);
  86. case KEYCTL_CHOWN:
  87. return keyctl_chown_key(arg2, arg3, arg4);
  88. case KEYCTL_SETPERM:
  89. return keyctl_setperm_key(arg2, arg3);
  90. case KEYCTL_INSTANTIATE:
  91. return keyctl_instantiate_key(arg2, compat_ptr(arg3), arg4,
  92. arg5);
  93. case KEYCTL_NEGATE:
  94. return keyctl_negate_key(arg2, arg3, arg4);
  95. case KEYCTL_SET_REQKEY_KEYRING:
  96. return keyctl_set_reqkey_keyring(arg2);
  97. case KEYCTL_SET_TIMEOUT:
  98. return keyctl_set_timeout(arg2, arg3);
  99. case KEYCTL_ASSUME_AUTHORITY:
  100. return keyctl_assume_authority(arg2);
  101. case KEYCTL_GET_SECURITY:
  102. return keyctl_get_security(arg2, compat_ptr(arg3), arg4);
  103. case KEYCTL_SESSION_TO_PARENT:
  104. return keyctl_session_to_parent();
  105. case KEYCTL_REJECT:
  106. return keyctl_reject_key(arg2, arg3, arg4, arg5);
  107. case KEYCTL_INSTANTIATE_IOV:
  108. return compat_keyctl_instantiate_key_iov(
  109. arg2, compat_ptr(arg3), arg4, arg5);
  110. default:
  111. return -EOPNOTSUPP;
  112. }
  113. }