Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 2 | /* 32-bit compatibility syscall for 64-bit systems |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 4 | * Copyright (C) 2004-5 Red Hat, Inc. All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Written by David Howells (dhowells@redhat.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <linux/syscalls.h> |
| 9 | #include <linux/keyctl.h> |
| 10 | #include <linux/compat.h> |
David Howells | ee009e4a0 | 2011-03-07 15:06:20 +0000 | [diff] [blame] | 11 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include "internal.h" |
| 13 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | /* |
David Howells | ee009e4a0 | 2011-03-07 15:06:20 +0000 | [diff] [blame] | 15 | * Instantiate a key with the specified compatibility multipart payload and |
| 16 | * link the key into the destination keyring if one is given. |
| 17 | * |
| 18 | * The caller must have the appropriate instantiation permit set for this to |
| 19 | * work (see keyctl_assume_authority). No other permissions are required. |
| 20 | * |
| 21 | * If successful, 0 will be returned. |
| 22 | */ |
David Howells | 423b9788 | 2012-05-21 12:32:13 +0100 | [diff] [blame] | 23 | static long compat_keyctl_instantiate_key_iov( |
David Howells | ee009e4a0 | 2011-03-07 15:06:20 +0000 | [diff] [blame] | 24 | key_serial_t id, |
| 25 | const struct compat_iovec __user *_payload_iov, |
| 26 | unsigned ioc, |
| 27 | key_serial_t ringid) |
| 28 | { |
| 29 | struct iovec iovstack[UIO_FASTIOV], *iov = iovstack; |
Al Viro | b353a1f | 2015-03-17 09:59:38 -0400 | [diff] [blame] | 30 | struct iov_iter from; |
David Howells | ee009e4a0 | 2011-03-07 15:06:20 +0000 | [diff] [blame] | 31 | long ret; |
| 32 | |
Al Viro | b353a1f | 2015-03-17 09:59:38 -0400 | [diff] [blame] | 33 | if (!_payload_iov) |
| 34 | ioc = 0; |
David Howells | ee009e4a0 | 2011-03-07 15:06:20 +0000 | [diff] [blame] | 35 | |
Al Viro | b353a1f | 2015-03-17 09:59:38 -0400 | [diff] [blame] | 36 | ret = compat_import_iovec(WRITE, _payload_iov, ioc, |
| 37 | ARRAY_SIZE(iovstack), &iov, |
| 38 | &from); |
David Howells | ee009e4a0 | 2011-03-07 15:06:20 +0000 | [diff] [blame] | 39 | if (ret < 0) |
Al Viro | b353a1f | 2015-03-17 09:59:38 -0400 | [diff] [blame] | 40 | return ret; |
David Howells | ee009e4a0 | 2011-03-07 15:06:20 +0000 | [diff] [blame] | 41 | |
Al Viro | b353a1f | 2015-03-17 09:59:38 -0400 | [diff] [blame] | 42 | ret = keyctl_instantiate_key_common(id, &from, ringid); |
| 43 | kfree(iov); |
David Howells | ee009e4a0 | 2011-03-07 15:06:20 +0000 | [diff] [blame] | 44 | return ret; |
David Howells | ee009e4a0 | 2011-03-07 15:06:20 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | /* |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 48 | * The key control system call, 32-bit compatibility version for 64-bit archs |
| 49 | * |
| 50 | * This should only be called if the 64-bit arch uses weird pointers in 32-bit |
| 51 | * mode or doesn't guarantee that the top 32-bits of the argument registers on |
| 52 | * taking a 32-bit syscall are zero. If you can, you should call sys_keyctl() |
| 53 | * directly. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | */ |
Heiko Carstens | 875ec3d | 2014-03-03 16:34:41 +0100 | [diff] [blame] | 55 | COMPAT_SYSCALL_DEFINE5(keyctl, u32, option, |
| 56 | u32, arg2, u32, arg3, u32, arg4, u32, arg5) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | { |
| 58 | switch (option) { |
| 59 | case KEYCTL_GET_KEYRING_ID: |
| 60 | return keyctl_get_keyring_ID(arg2, arg3); |
| 61 | |
| 62 | case KEYCTL_JOIN_SESSION_KEYRING: |
| 63 | return keyctl_join_session_keyring(compat_ptr(arg2)); |
| 64 | |
| 65 | case KEYCTL_UPDATE: |
| 66 | return keyctl_update_key(arg2, compat_ptr(arg3), arg4); |
| 67 | |
| 68 | case KEYCTL_REVOKE: |
| 69 | return keyctl_revoke_key(arg2); |
| 70 | |
| 71 | case KEYCTL_DESCRIBE: |
| 72 | return keyctl_describe_key(arg2, compat_ptr(arg3), arg4); |
| 73 | |
| 74 | case KEYCTL_CLEAR: |
| 75 | return keyctl_keyring_clear(arg2); |
| 76 | |
| 77 | case KEYCTL_LINK: |
| 78 | return keyctl_keyring_link(arg2, arg3); |
| 79 | |
| 80 | case KEYCTL_UNLINK: |
| 81 | return keyctl_keyring_unlink(arg2, arg3); |
| 82 | |
| 83 | case KEYCTL_SEARCH: |
| 84 | return keyctl_keyring_search(arg2, compat_ptr(arg3), |
| 85 | compat_ptr(arg4), arg5); |
| 86 | |
| 87 | case KEYCTL_READ: |
| 88 | return keyctl_read_key(arg2, compat_ptr(arg3), arg4); |
| 89 | |
| 90 | case KEYCTL_CHOWN: |
| 91 | return keyctl_chown_key(arg2, arg3, arg4); |
| 92 | |
| 93 | case KEYCTL_SETPERM: |
| 94 | return keyctl_setperm_key(arg2, arg3); |
| 95 | |
| 96 | case KEYCTL_INSTANTIATE: |
| 97 | return keyctl_instantiate_key(arg2, compat_ptr(arg3), arg4, |
| 98 | arg5); |
| 99 | |
| 100 | case KEYCTL_NEGATE: |
| 101 | return keyctl_negate_key(arg2, arg3, arg4); |
| 102 | |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 103 | case KEYCTL_SET_REQKEY_KEYRING: |
| 104 | return keyctl_set_reqkey_keyring(arg2); |
| 105 | |
David Howells | 017679c | 2006-01-08 01:02:43 -0800 | [diff] [blame] | 106 | case KEYCTL_SET_TIMEOUT: |
| 107 | return keyctl_set_timeout(arg2, arg3); |
| 108 | |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 109 | case KEYCTL_ASSUME_AUTHORITY: |
| 110 | return keyctl_assume_authority(arg2); |
| 111 | |
David Howells | 70a5bb7 | 2008-04-29 01:01:26 -0700 | [diff] [blame] | 112 | case KEYCTL_GET_SECURITY: |
| 113 | return keyctl_get_security(arg2, compat_ptr(arg3), arg4); |
| 114 | |
David Howells | ee18d64 | 2009-09-02 09:14:21 +0100 | [diff] [blame] | 115 | case KEYCTL_SESSION_TO_PARENT: |
| 116 | return keyctl_session_to_parent(); |
| 117 | |
David Howells | fdd1b94 | 2011-03-07 15:06:09 +0000 | [diff] [blame] | 118 | case KEYCTL_REJECT: |
| 119 | return keyctl_reject_key(arg2, arg3, arg4, arg5); |
| 120 | |
David Howells | ee009e4a0 | 2011-03-07 15:06:20 +0000 | [diff] [blame] | 121 | case KEYCTL_INSTANTIATE_IOV: |
| 122 | return compat_keyctl_instantiate_key_iov( |
| 123 | arg2, compat_ptr(arg3), arg4, arg5); |
| 124 | |
David Howells | fd75815 | 2012-05-11 10:56:56 +0100 | [diff] [blame] | 125 | case KEYCTL_INVALIDATE: |
| 126 | return keyctl_invalidate_key(arg2); |
| 127 | |
David Howells | f36f8c7 | 2013-09-24 10:35:19 +0100 | [diff] [blame] | 128 | case KEYCTL_GET_PERSISTENT: |
| 129 | return keyctl_get_persistent(arg2, arg3); |
| 130 | |
Mat Martineau | ddbb411 | 2016-04-12 19:54:58 +0100 | [diff] [blame] | 131 | case KEYCTL_DH_COMPUTE: |
Stephan Mueller | f1c316a | 2016-08-19 20:39:09 +0200 | [diff] [blame] | 132 | return compat_keyctl_dh_compute(compat_ptr(arg2), |
| 133 | compat_ptr(arg3), |
| 134 | arg4, compat_ptr(arg5)); |
Mat Martineau | ddbb411 | 2016-04-12 19:54:58 +0100 | [diff] [blame] | 135 | |
Mat Martineau | 6563c91 | 2017-03-01 16:44:09 -0800 | [diff] [blame] | 136 | case KEYCTL_RESTRICT_KEYRING: |
| 137 | return keyctl_restrict_keyring(arg2, compat_ptr(arg3), |
| 138 | compat_ptr(arg4)); |
| 139 | |
David Howells | 00d60fd | 2018-10-09 17:46:59 +0100 | [diff] [blame] | 140 | case KEYCTL_PKEY_QUERY: |
| 141 | if (arg3 != 0) |
| 142 | return -EINVAL; |
| 143 | return keyctl_pkey_query(arg2, |
| 144 | compat_ptr(arg4), |
| 145 | compat_ptr(arg5)); |
| 146 | |
| 147 | case KEYCTL_PKEY_ENCRYPT: |
| 148 | case KEYCTL_PKEY_DECRYPT: |
| 149 | case KEYCTL_PKEY_SIGN: |
| 150 | return keyctl_pkey_e_d_s(option, |
| 151 | compat_ptr(arg2), compat_ptr(arg3), |
| 152 | compat_ptr(arg4), compat_ptr(arg5)); |
| 153 | |
| 154 | case KEYCTL_PKEY_VERIFY: |
| 155 | return keyctl_pkey_verify(compat_ptr(arg2), compat_ptr(arg3), |
| 156 | compat_ptr(arg4), compat_ptr(arg5)); |
| 157 | |
David Howells | ed0ac5c | 2019-05-20 21:51:50 +0100 | [diff] [blame] | 158 | case KEYCTL_MOVE: |
| 159 | return keyctl_keyring_move(arg2, arg3, arg4, arg5); |
| 160 | |
David Howells | 45e0f30 | 2019-05-30 14:53:10 +0100 | [diff] [blame] | 161 | case KEYCTL_CAPABILITIES: |
| 162 | return keyctl_capabilities(compat_ptr(arg2), arg3); |
| 163 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | default: |
| 165 | return -EOPNOTSUPP; |
| 166 | } |
David Howells | a8b17ed | 2011-01-20 16:38:27 +0000 | [diff] [blame] | 167 | } |