compat.c 3.6 KB

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