David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 1 | /* 32-bit compatibility syscall for 64-bit systems |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 3 | * Copyright (C) 2004-5 Red Hat, Inc. All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/syscalls.h> |
| 13 | #include <linux/keyctl.h> |
| 14 | #include <linux/compat.h> |
David Howells | ee009e4a0 | 2011-03-07 15:06:20 +0000 | [diff] [blame] | 15 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include "internal.h" |
| 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | /* |
David Howells | ee009e4a0 | 2011-03-07 15:06:20 +0000 | [diff] [blame] | 19 | * Instantiate a key with the specified compatibility multipart payload and |
| 20 | * link the key into the destination keyring if one is given. |
| 21 | * |
| 22 | * The caller must have the appropriate instantiation permit set for this to |
| 23 | * work (see keyctl_assume_authority). No other permissions are required. |
| 24 | * |
| 25 | * If successful, 0 will be returned. |
| 26 | */ |
David Howells | 423b9788 | 2012-05-21 12:32:13 +0100 | [diff] [blame] | 27 | static long compat_keyctl_instantiate_key_iov( |
David Howells | ee009e4a0 | 2011-03-07 15:06:20 +0000 | [diff] [blame] | 28 | key_serial_t id, |
| 29 | const struct compat_iovec __user *_payload_iov, |
| 30 | unsigned ioc, |
| 31 | key_serial_t ringid) |
| 32 | { |
| 33 | struct iovec iovstack[UIO_FASTIOV], *iov = iovstack; |
| 34 | long ret; |
| 35 | |
David Howells | 423b9788 | 2012-05-21 12:32:13 +0100 | [diff] [blame] | 36 | if (!_payload_iov || !ioc) |
David Howells | ee009e4a0 | 2011-03-07 15:06:20 +0000 | [diff] [blame] | 37 | goto no_payload; |
| 38 | |
| 39 | ret = compat_rw_copy_check_uvector(WRITE, _payload_iov, ioc, |
| 40 | ARRAY_SIZE(iovstack), |
Christopher Yeoh | ac34ebb | 2012-05-31 16:26:42 -0700 | [diff] [blame] | 41 | iovstack, &iov); |
David Howells | ee009e4a0 | 2011-03-07 15:06:20 +0000 | [diff] [blame] | 42 | if (ret < 0) |
Mathieu Desnoyers | 8aec0f5 | 2013-02-25 10:20:36 -0500 | [diff] [blame] | 43 | goto err; |
David Howells | ee009e4a0 | 2011-03-07 15:06:20 +0000 | [diff] [blame] | 44 | if (ret == 0) |
| 45 | goto no_payload_free; |
| 46 | |
| 47 | ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid); |
Mathieu Desnoyers | 8aec0f5 | 2013-02-25 10:20:36 -0500 | [diff] [blame] | 48 | err: |
David Howells | ee009e4a0 | 2011-03-07 15:06:20 +0000 | [diff] [blame] | 49 | if (iov != iovstack) |
| 50 | kfree(iov); |
| 51 | return ret; |
| 52 | |
| 53 | no_payload_free: |
| 54 | if (iov != iovstack) |
| 55 | kfree(iov); |
| 56 | no_payload: |
| 57 | return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid); |
| 58 | } |
| 59 | |
| 60 | /* |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 61 | * The key control system call, 32-bit compatibility version for 64-bit archs |
| 62 | * |
| 63 | * This should only be called if the 64-bit arch uses weird pointers in 32-bit |
| 64 | * mode or doesn't guarantee that the top 32-bits of the argument registers on |
| 65 | * taking a 32-bit syscall are zero. If you can, you should call sys_keyctl() |
| 66 | * directly. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | */ |
| 68 | asmlinkage long compat_sys_keyctl(u32 option, |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 69 | u32 arg2, u32 arg3, u32 arg4, u32 arg5) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | { |
| 71 | switch (option) { |
| 72 | case KEYCTL_GET_KEYRING_ID: |
| 73 | return keyctl_get_keyring_ID(arg2, arg3); |
| 74 | |
| 75 | case KEYCTL_JOIN_SESSION_KEYRING: |
| 76 | return keyctl_join_session_keyring(compat_ptr(arg2)); |
| 77 | |
| 78 | case KEYCTL_UPDATE: |
| 79 | return keyctl_update_key(arg2, compat_ptr(arg3), arg4); |
| 80 | |
| 81 | case KEYCTL_REVOKE: |
| 82 | return keyctl_revoke_key(arg2); |
| 83 | |
| 84 | case KEYCTL_DESCRIBE: |
| 85 | return keyctl_describe_key(arg2, compat_ptr(arg3), arg4); |
| 86 | |
| 87 | case KEYCTL_CLEAR: |
| 88 | return keyctl_keyring_clear(arg2); |
| 89 | |
| 90 | case KEYCTL_LINK: |
| 91 | return keyctl_keyring_link(arg2, arg3); |
| 92 | |
| 93 | case KEYCTL_UNLINK: |
| 94 | return keyctl_keyring_unlink(arg2, arg3); |
| 95 | |
| 96 | case KEYCTL_SEARCH: |
| 97 | return keyctl_keyring_search(arg2, compat_ptr(arg3), |
| 98 | compat_ptr(arg4), arg5); |
| 99 | |
| 100 | case KEYCTL_READ: |
| 101 | return keyctl_read_key(arg2, compat_ptr(arg3), arg4); |
| 102 | |
| 103 | case KEYCTL_CHOWN: |
| 104 | return keyctl_chown_key(arg2, arg3, arg4); |
| 105 | |
| 106 | case KEYCTL_SETPERM: |
| 107 | return keyctl_setperm_key(arg2, arg3); |
| 108 | |
| 109 | case KEYCTL_INSTANTIATE: |
| 110 | return keyctl_instantiate_key(arg2, compat_ptr(arg3), arg4, |
| 111 | arg5); |
| 112 | |
| 113 | case KEYCTL_NEGATE: |
| 114 | return keyctl_negate_key(arg2, arg3, arg4); |
| 115 | |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 116 | case KEYCTL_SET_REQKEY_KEYRING: |
| 117 | return keyctl_set_reqkey_keyring(arg2); |
| 118 | |
David Howells | 017679c | 2006-01-08 01:02:43 -0800 | [diff] [blame] | 119 | case KEYCTL_SET_TIMEOUT: |
| 120 | return keyctl_set_timeout(arg2, arg3); |
| 121 | |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 122 | case KEYCTL_ASSUME_AUTHORITY: |
| 123 | return keyctl_assume_authority(arg2); |
| 124 | |
David Howells | 70a5bb7 | 2008-04-29 01:01:26 -0700 | [diff] [blame] | 125 | case KEYCTL_GET_SECURITY: |
| 126 | return keyctl_get_security(arg2, compat_ptr(arg3), arg4); |
| 127 | |
David Howells | ee18d64 | 2009-09-02 09:14:21 +0100 | [diff] [blame] | 128 | case KEYCTL_SESSION_TO_PARENT: |
| 129 | return keyctl_session_to_parent(); |
| 130 | |
David Howells | fdd1b94 | 2011-03-07 15:06:09 +0000 | [diff] [blame] | 131 | case KEYCTL_REJECT: |
| 132 | return keyctl_reject_key(arg2, arg3, arg4, arg5); |
| 133 | |
David Howells | ee009e4a0 | 2011-03-07 15:06:20 +0000 | [diff] [blame] | 134 | case KEYCTL_INSTANTIATE_IOV: |
| 135 | return compat_keyctl_instantiate_key_iov( |
| 136 | arg2, compat_ptr(arg3), arg4, arg5); |
| 137 | |
David Howells | fd75815 | 2012-05-11 10:56:56 +0100 | [diff] [blame] | 138 | case KEYCTL_INVALIDATE: |
| 139 | return keyctl_invalidate_key(arg2); |
| 140 | |
David Howells | f36f8c7 | 2013-09-24 10:35:19 +0100 | [diff] [blame] | 141 | case KEYCTL_GET_PERSISTENT: |
| 142 | return keyctl_get_persistent(arg2, arg3); |
| 143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | default: |
| 145 | return -EOPNOTSUPP; |
| 146 | } |
David Howells | a8b17ed | 2011-01-20 16:38:27 +0000 | [diff] [blame] | 147 | } |