blob: b975f8f11124b7f79112a3bced90673c9f5d7f5a [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
David Howells973c9f42011-01-20 16:38:33 +00002/* 32-bit compatibility syscall for 64-bit systems
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
David Howells3e301482005-06-23 22:00:56 -07004 * Copyright (C) 2004-5 Red Hat, Inc. All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Written by David Howells (dhowells@redhat.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <linux/syscalls.h>
9#include <linux/keyctl.h>
10#include <linux/compat.h>
David Howellsee009e4a02011-03-07 15:06:20 +000011#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include "internal.h"
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014/*
David Howellsee009e4a02011-03-07 15:06:20 +000015 * 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 Howells423b97882012-05-21 12:32:13 +010023static long compat_keyctl_instantiate_key_iov(
David Howellsee009e4a02011-03-07 15:06:20 +000024 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 Virob353a1f2015-03-17 09:59:38 -040030 struct iov_iter from;
David Howellsee009e4a02011-03-07 15:06:20 +000031 long ret;
32
Al Virob353a1f2015-03-17 09:59:38 -040033 if (!_payload_iov)
34 ioc = 0;
David Howellsee009e4a02011-03-07 15:06:20 +000035
Al Virob353a1f2015-03-17 09:59:38 -040036 ret = compat_import_iovec(WRITE, _payload_iov, ioc,
37 ARRAY_SIZE(iovstack), &iov,
38 &from);
David Howellsee009e4a02011-03-07 15:06:20 +000039 if (ret < 0)
Al Virob353a1f2015-03-17 09:59:38 -040040 return ret;
David Howellsee009e4a02011-03-07 15:06:20 +000041
Al Virob353a1f2015-03-17 09:59:38 -040042 ret = keyctl_instantiate_key_common(id, &from, ringid);
43 kfree(iov);
David Howellsee009e4a02011-03-07 15:06:20 +000044 return ret;
David Howellsee009e4a02011-03-07 15:06:20 +000045}
46
47/*
David Howells973c9f42011-01-20 16:38:33 +000048 * The key control system call, 32-bit compatibility version for 64-bit archs
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 */
Heiko Carstens875ec3d2014-03-03 16:34:41 +010050COMPAT_SYSCALL_DEFINE5(keyctl, u32, option,
51 u32, arg2, u32, arg3, u32, arg4, u32, arg5)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052{
53 switch (option) {
54 case KEYCTL_GET_KEYRING_ID:
55 return keyctl_get_keyring_ID(arg2, arg3);
56
57 case KEYCTL_JOIN_SESSION_KEYRING:
58 return keyctl_join_session_keyring(compat_ptr(arg2));
59
60 case KEYCTL_UPDATE:
61 return keyctl_update_key(arg2, compat_ptr(arg3), arg4);
62
63 case KEYCTL_REVOKE:
64 return keyctl_revoke_key(arg2);
65
66 case KEYCTL_DESCRIBE:
67 return keyctl_describe_key(arg2, compat_ptr(arg3), arg4);
68
69 case KEYCTL_CLEAR:
70 return keyctl_keyring_clear(arg2);
71
72 case KEYCTL_LINK:
73 return keyctl_keyring_link(arg2, arg3);
74
75 case KEYCTL_UNLINK:
76 return keyctl_keyring_unlink(arg2, arg3);
77
78 case KEYCTL_SEARCH:
79 return keyctl_keyring_search(arg2, compat_ptr(arg3),
80 compat_ptr(arg4), arg5);
81
82 case KEYCTL_READ:
83 return keyctl_read_key(arg2, compat_ptr(arg3), arg4);
84
85 case KEYCTL_CHOWN:
86 return keyctl_chown_key(arg2, arg3, arg4);
87
88 case KEYCTL_SETPERM:
89 return keyctl_setperm_key(arg2, arg3);
90
91 case KEYCTL_INSTANTIATE:
92 return keyctl_instantiate_key(arg2, compat_ptr(arg3), arg4,
93 arg5);
94
95 case KEYCTL_NEGATE:
96 return keyctl_negate_key(arg2, arg3, arg4);
97
David Howells3e301482005-06-23 22:00:56 -070098 case KEYCTL_SET_REQKEY_KEYRING:
99 return keyctl_set_reqkey_keyring(arg2);
100
David Howells017679c2006-01-08 01:02:43 -0800101 case KEYCTL_SET_TIMEOUT:
102 return keyctl_set_timeout(arg2, arg3);
103
David Howellsb5f545c2006-01-08 01:02:47 -0800104 case KEYCTL_ASSUME_AUTHORITY:
105 return keyctl_assume_authority(arg2);
106
David Howells70a5bb72008-04-29 01:01:26 -0700107 case KEYCTL_GET_SECURITY:
108 return keyctl_get_security(arg2, compat_ptr(arg3), arg4);
109
David Howellsee18d642009-09-02 09:14:21 +0100110 case KEYCTL_SESSION_TO_PARENT:
111 return keyctl_session_to_parent();
112
David Howellsfdd1b942011-03-07 15:06:09 +0000113 case KEYCTL_REJECT:
114 return keyctl_reject_key(arg2, arg3, arg4, arg5);
115
David Howellsee009e4a02011-03-07 15:06:20 +0000116 case KEYCTL_INSTANTIATE_IOV:
117 return compat_keyctl_instantiate_key_iov(
118 arg2, compat_ptr(arg3), arg4, arg5);
119
David Howellsfd758152012-05-11 10:56:56 +0100120 case KEYCTL_INVALIDATE:
121 return keyctl_invalidate_key(arg2);
122
David Howellsf36f8c72013-09-24 10:35:19 +0100123 case KEYCTL_GET_PERSISTENT:
124 return keyctl_get_persistent(arg2, arg3);
125
Mat Martineauddbb4112016-04-12 19:54:58 +0100126 case KEYCTL_DH_COMPUTE:
Stephan Muellerf1c316a2016-08-19 20:39:09 +0200127 return compat_keyctl_dh_compute(compat_ptr(arg2),
128 compat_ptr(arg3),
129 arg4, compat_ptr(arg5));
Mat Martineauddbb4112016-04-12 19:54:58 +0100130
Mat Martineau6563c912017-03-01 16:44:09 -0800131 case KEYCTL_RESTRICT_KEYRING:
132 return keyctl_restrict_keyring(arg2, compat_ptr(arg3),
133 compat_ptr(arg4));
134
David Howells00d60fd2018-10-09 17:46:59 +0100135 case KEYCTL_PKEY_QUERY:
136 if (arg3 != 0)
137 return -EINVAL;
138 return keyctl_pkey_query(arg2,
139 compat_ptr(arg4),
140 compat_ptr(arg5));
141
142 case KEYCTL_PKEY_ENCRYPT:
143 case KEYCTL_PKEY_DECRYPT:
144 case KEYCTL_PKEY_SIGN:
145 return keyctl_pkey_e_d_s(option,
146 compat_ptr(arg2), compat_ptr(arg3),
147 compat_ptr(arg4), compat_ptr(arg5));
148
149 case KEYCTL_PKEY_VERIFY:
150 return keyctl_pkey_verify(compat_ptr(arg2), compat_ptr(arg3),
151 compat_ptr(arg4), compat_ptr(arg5));
152
David Howellsed0ac5c2019-05-20 21:51:50 +0100153 case KEYCTL_MOVE:
154 return keyctl_keyring_move(arg2, arg3, arg4, arg5);
155
David Howells45e0f302019-05-30 14:53:10 +0100156 case KEYCTL_CAPABILITIES:
157 return keyctl_capabilities(compat_ptr(arg2), arg3);
158
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 default:
160 return -EOPNOTSUPP;
161 }
David Howellsa8b17ed2011-01-20 16:38:27 +0000162}