blob: 36c80bf5b89c6f28a7c6010aa6b72f373bf4d1e1 [file] [log] [blame]
David Howells973c9f42011-01-20 16:38:33 +00001/* 32-bit compatibility syscall for 64-bit systems
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
David Howells3e301482005-06-23 22:00:56 -07003 * Copyright (C) 2004-5 Red Hat, Inc. All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * 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 Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/syscalls.h>
13#include <linux/keyctl.h>
14#include <linux/compat.h>
David Howellsee009e4a02011-03-07 15:06:20 +000015#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include "internal.h"
17
Linus Torvalds1da177e2005-04-16 15:20:36 -070018/*
David Howellsee009e4a02011-03-07 15:06:20 +000019 * 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 Howells423b97882012-05-21 12:32:13 +010027static long compat_keyctl_instantiate_key_iov(
David Howellsee009e4a02011-03-07 15:06:20 +000028 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;
Al Virob353a1f2015-03-17 09:59:38 -040034 struct iov_iter from;
David Howellsee009e4a02011-03-07 15:06:20 +000035 long ret;
36
Al Virob353a1f2015-03-17 09:59:38 -040037 if (!_payload_iov)
38 ioc = 0;
David Howellsee009e4a02011-03-07 15:06:20 +000039
Al Virob353a1f2015-03-17 09:59:38 -040040 ret = compat_import_iovec(WRITE, _payload_iov, ioc,
41 ARRAY_SIZE(iovstack), &iov,
42 &from);
David Howellsee009e4a02011-03-07 15:06:20 +000043 if (ret < 0)
Al Virob353a1f2015-03-17 09:59:38 -040044 return ret;
David Howellsee009e4a02011-03-07 15:06:20 +000045
Al Virob353a1f2015-03-17 09:59:38 -040046 ret = keyctl_instantiate_key_common(id, &from, ringid);
47 kfree(iov);
David Howellsee009e4a02011-03-07 15:06:20 +000048 return ret;
David Howellsee009e4a02011-03-07 15:06:20 +000049}
50
51/*
David Howells973c9f42011-01-20 16:38:33 +000052 * The key control system call, 32-bit compatibility version for 64-bit archs
53 *
54 * This should only be called if the 64-bit arch uses weird pointers in 32-bit
55 * mode or doesn't guarantee that the top 32-bits of the argument registers on
56 * taking a 32-bit syscall are zero. If you can, you should call sys_keyctl()
57 * directly.
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 */
Heiko Carstens875ec3d2014-03-03 16:34:41 +010059COMPAT_SYSCALL_DEFINE5(keyctl, u32, option,
60 u32, arg2, u32, arg3, u32, arg4, u32, arg5)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061{
62 switch (option) {
63 case KEYCTL_GET_KEYRING_ID:
64 return keyctl_get_keyring_ID(arg2, arg3);
65
66 case KEYCTL_JOIN_SESSION_KEYRING:
67 return keyctl_join_session_keyring(compat_ptr(arg2));
68
69 case KEYCTL_UPDATE:
70 return keyctl_update_key(arg2, compat_ptr(arg3), arg4);
71
72 case KEYCTL_REVOKE:
73 return keyctl_revoke_key(arg2);
74
75 case KEYCTL_DESCRIBE:
76 return keyctl_describe_key(arg2, compat_ptr(arg3), arg4);
77
78 case KEYCTL_CLEAR:
79 return keyctl_keyring_clear(arg2);
80
81 case KEYCTL_LINK:
82 return keyctl_keyring_link(arg2, arg3);
83
84 case KEYCTL_UNLINK:
85 return keyctl_keyring_unlink(arg2, arg3);
86
87 case KEYCTL_SEARCH:
88 return keyctl_keyring_search(arg2, compat_ptr(arg3),
89 compat_ptr(arg4), arg5);
90
91 case KEYCTL_READ:
92 return keyctl_read_key(arg2, compat_ptr(arg3), arg4);
93
94 case KEYCTL_CHOWN:
95 return keyctl_chown_key(arg2, arg3, arg4);
96
97 case KEYCTL_SETPERM:
98 return keyctl_setperm_key(arg2, arg3);
99
100 case KEYCTL_INSTANTIATE:
101 return keyctl_instantiate_key(arg2, compat_ptr(arg3), arg4,
102 arg5);
103
104 case KEYCTL_NEGATE:
105 return keyctl_negate_key(arg2, arg3, arg4);
106
David Howells3e301482005-06-23 22:00:56 -0700107 case KEYCTL_SET_REQKEY_KEYRING:
108 return keyctl_set_reqkey_keyring(arg2);
109
David Howells017679c2006-01-08 01:02:43 -0800110 case KEYCTL_SET_TIMEOUT:
111 return keyctl_set_timeout(arg2, arg3);
112
David Howellsb5f545c2006-01-08 01:02:47 -0800113 case KEYCTL_ASSUME_AUTHORITY:
114 return keyctl_assume_authority(arg2);
115
David Howells70a5bb72008-04-29 01:01:26 -0700116 case KEYCTL_GET_SECURITY:
117 return keyctl_get_security(arg2, compat_ptr(arg3), arg4);
118
David Howellsee18d642009-09-02 09:14:21 +0100119 case KEYCTL_SESSION_TO_PARENT:
120 return keyctl_session_to_parent();
121
David Howellsfdd1b942011-03-07 15:06:09 +0000122 case KEYCTL_REJECT:
123 return keyctl_reject_key(arg2, arg3, arg4, arg5);
124
David Howellsee009e4a02011-03-07 15:06:20 +0000125 case KEYCTL_INSTANTIATE_IOV:
126 return compat_keyctl_instantiate_key_iov(
127 arg2, compat_ptr(arg3), arg4, arg5);
128
David Howellsfd758152012-05-11 10:56:56 +0100129 case KEYCTL_INVALIDATE:
130 return keyctl_invalidate_key(arg2);
131
David Howellsf36f8c72013-09-24 10:35:19 +0100132 case KEYCTL_GET_PERSISTENT:
133 return keyctl_get_persistent(arg2, arg3);
134
Mat Martineauddbb4112016-04-12 19:54:58 +0100135 case KEYCTL_DH_COMPUTE:
136 return keyctl_dh_compute(compat_ptr(arg2), compat_ptr(arg3),
Stephan Mueller4693fc72016-05-26 23:38:12 +0200137 arg4, compat_ptr(arg5));
Mat Martineauddbb4112016-04-12 19:54:58 +0100138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 default:
140 return -EOPNOTSUPP;
141 }
David Howellsa8b17ed2011-01-20 16:38:27 +0000142}