David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 1 | /* Userspace key control operations |
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 | |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/sched.h> |
| 15 | #include <linux/slab.h> |
| 16 | #include <linux/syscalls.h> |
Bryan Schumaker | 59e6b9c | 2012-02-24 14:14:50 -0500 | [diff] [blame^] | 17 | #include <linux/key.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/keyctl.h> |
| 19 | #include <linux/fs.h> |
Randy.Dunlap | c59ede7 | 2006-01-11 12:17:46 -0800 | [diff] [blame] | 20 | #include <linux/capability.h> |
Davi Arnaut | 0cb409d | 2006-03-24 03:18:43 -0800 | [diff] [blame] | 21 | #include <linux/string.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/err.h> |
David Howells | 38bbca6 | 2008-04-29 01:01:19 -0700 | [diff] [blame] | 23 | #include <linux/vmalloc.h> |
David Howells | 70a5bb7 | 2008-04-29 01:01:26 -0700 | [diff] [blame] | 24 | #include <linux/security.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <asm/uaccess.h> |
| 26 | #include "internal.h" |
| 27 | |
Davi Arnaut | 0cb409d | 2006-03-24 03:18:43 -0800 | [diff] [blame] | 28 | static int key_get_type_from_user(char *type, |
| 29 | const char __user *_type, |
| 30 | unsigned len) |
| 31 | { |
| 32 | int ret; |
| 33 | |
| 34 | ret = strncpy_from_user(type, _type, len); |
Davi Arnaut | 0cb409d | 2006-03-24 03:18:43 -0800 | [diff] [blame] | 35 | if (ret < 0) |
Dan Carpenter | 4303ef1 | 2010-06-11 17:30:05 +0100 | [diff] [blame] | 36 | return ret; |
Davi Arnaut | 0cb409d | 2006-03-24 03:18:43 -0800 | [diff] [blame] | 37 | if (ret == 0 || ret >= len) |
| 38 | return -EINVAL; |
Davi Arnaut | 0cb409d | 2006-03-24 03:18:43 -0800 | [diff] [blame] | 39 | if (type[0] == '.') |
| 40 | return -EPERM; |
Davi Arnaut | 0cb409d | 2006-03-24 03:18:43 -0800 | [diff] [blame] | 41 | type[len - 1] = '\0'; |
Davi Arnaut | 0cb409d | 2006-03-24 03:18:43 -0800 | [diff] [blame] | 42 | return 0; |
| 43 | } |
| 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | /* |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 46 | * Extract the description of a new key from userspace and either add it as a |
| 47 | * new key to the specified keyring or update a matching key in that keyring. |
| 48 | * |
| 49 | * The keyring must be writable so that we can attach the key to it. |
| 50 | * |
| 51 | * If successful, the new key's serial number is returned, otherwise an error |
| 52 | * code is returned. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | */ |
Heiko Carstens | 1e7bfb2 | 2009-01-14 14:14:29 +0100 | [diff] [blame] | 54 | SYSCALL_DEFINE5(add_key, const char __user *, _type, |
| 55 | const char __user *, _description, |
| 56 | const void __user *, _payload, |
| 57 | size_t, plen, |
| 58 | key_serial_t, ringid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | { |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 60 | key_ref_t keyring_ref, key_ref; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | char type[32], *description; |
| 62 | void *payload; |
Davi Arnaut | 0cb409d | 2006-03-24 03:18:43 -0800 | [diff] [blame] | 63 | long ret; |
David Howells | 38bbca6 | 2008-04-29 01:01:19 -0700 | [diff] [blame] | 64 | bool vm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
| 66 | ret = -EINVAL; |
David Howells | 38bbca6 | 2008-04-29 01:01:19 -0700 | [diff] [blame] | 67 | if (plen > 1024 * 1024 - 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | goto error; |
| 69 | |
| 70 | /* draw all the data into kernel space */ |
Davi Arnaut | 0cb409d | 2006-03-24 03:18:43 -0800 | [diff] [blame] | 71 | ret = key_get_type_from_user(type, _type, sizeof(type)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | if (ret < 0) |
| 73 | goto error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
Davi Arnaut | 0cb409d | 2006-03-24 03:18:43 -0800 | [diff] [blame] | 75 | description = strndup_user(_description, PAGE_SIZE); |
| 76 | if (IS_ERR(description)) { |
| 77 | ret = PTR_ERR(description); |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 78 | goto error; |
Davi Arnaut | 0cb409d | 2006-03-24 03:18:43 -0800 | [diff] [blame] | 79 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
| 81 | /* pull the payload in if one was supplied */ |
| 82 | payload = NULL; |
| 83 | |
David Howells | 38bbca6 | 2008-04-29 01:01:19 -0700 | [diff] [blame] | 84 | vm = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | if (_payload) { |
| 86 | ret = -ENOMEM; |
| 87 | payload = kmalloc(plen, GFP_KERNEL); |
David Howells | 38bbca6 | 2008-04-29 01:01:19 -0700 | [diff] [blame] | 88 | if (!payload) { |
| 89 | if (plen <= PAGE_SIZE) |
| 90 | goto error2; |
| 91 | vm = true; |
| 92 | payload = vmalloc(plen); |
| 93 | if (!payload) |
| 94 | goto error2; |
| 95 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
| 97 | ret = -EFAULT; |
| 98 | if (copy_from_user(payload, _payload, plen) != 0) |
| 99 | goto error3; |
| 100 | } |
| 101 | |
| 102 | /* find the target keyring (which must be writable) */ |
David Howells | 5593122 | 2009-09-02 09:13:45 +0100 | [diff] [blame] | 103 | keyring_ref = lookup_user_key(ringid, KEY_LOOKUP_CREATE, KEY_WRITE); |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 104 | if (IS_ERR(keyring_ref)) { |
| 105 | ret = PTR_ERR(keyring_ref); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | goto error3; |
| 107 | } |
| 108 | |
| 109 | /* create or update the requested key and add it to the target |
| 110 | * keyring */ |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 111 | key_ref = key_create_or_update(keyring_ref, type, description, |
Arun Raghavan | 6b79ccb | 2008-04-29 01:01:28 -0700 | [diff] [blame] | 112 | payload, plen, KEY_PERM_UNDEF, |
| 113 | KEY_ALLOC_IN_QUOTA); |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 114 | if (!IS_ERR(key_ref)) { |
| 115 | ret = key_ref_to_ptr(key_ref)->serial; |
| 116 | key_ref_put(key_ref); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | } |
| 118 | else { |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 119 | ret = PTR_ERR(key_ref); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | } |
| 121 | |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 122 | key_ref_put(keyring_ref); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | error3: |
David Howells | 38bbca6 | 2008-04-29 01:01:19 -0700 | [diff] [blame] | 124 | if (!vm) |
| 125 | kfree(payload); |
| 126 | else |
| 127 | vfree(payload); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | error2: |
| 129 | kfree(description); |
| 130 | error: |
| 131 | return ret; |
David Howells | a8b17ed | 2011-01-20 16:38:27 +0000 | [diff] [blame] | 132 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | /* |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 135 | * Search the process keyrings and keyring trees linked from those for a |
| 136 | * matching key. Keyrings must have appropriate Search permission to be |
| 137 | * searched. |
| 138 | * |
| 139 | * If a key is found, it will be attached to the destination keyring if there's |
| 140 | * one specified and the serial number of the key will be returned. |
| 141 | * |
| 142 | * If no key is found, /sbin/request-key will be invoked if _callout_info is |
| 143 | * non-NULL in an attempt to create a key. The _callout_info string will be |
| 144 | * passed to /sbin/request-key to aid with completing the request. If the |
| 145 | * _callout_info string is "" then it will be changed to "-". |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | */ |
Heiko Carstens | 1e7bfb2 | 2009-01-14 14:14:29 +0100 | [diff] [blame] | 147 | SYSCALL_DEFINE4(request_key, const char __user *, _type, |
| 148 | const char __user *, _description, |
| 149 | const char __user *, _callout_info, |
| 150 | key_serial_t, destringid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | { |
| 152 | struct key_type *ktype; |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 153 | struct key *key; |
| 154 | key_ref_t dest_ref; |
David Howells | 4a38e12 | 2008-04-29 01:01:24 -0700 | [diff] [blame] | 155 | size_t callout_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | char type[32], *description, *callout_info; |
Davi Arnaut | 0cb409d | 2006-03-24 03:18:43 -0800 | [diff] [blame] | 157 | long ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
| 159 | /* pull the type into kernel space */ |
Davi Arnaut | 0cb409d | 2006-03-24 03:18:43 -0800 | [diff] [blame] | 160 | ret = key_get_type_from_user(type, _type, sizeof(type)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | if (ret < 0) |
| 162 | goto error; |
David Howells | 1260f80 | 2005-08-04 11:50:01 +0100 | [diff] [blame] | 163 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | /* pull the description into kernel space */ |
Davi Arnaut | 0cb409d | 2006-03-24 03:18:43 -0800 | [diff] [blame] | 165 | description = strndup_user(_description, PAGE_SIZE); |
| 166 | if (IS_ERR(description)) { |
| 167 | ret = PTR_ERR(description); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | goto error; |
Davi Arnaut | 0cb409d | 2006-03-24 03:18:43 -0800 | [diff] [blame] | 169 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
| 171 | /* pull the callout info into kernel space */ |
| 172 | callout_info = NULL; |
David Howells | 4a38e12 | 2008-04-29 01:01:24 -0700 | [diff] [blame] | 173 | callout_len = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | if (_callout_info) { |
Davi Arnaut | 0cb409d | 2006-03-24 03:18:43 -0800 | [diff] [blame] | 175 | callout_info = strndup_user(_callout_info, PAGE_SIZE); |
| 176 | if (IS_ERR(callout_info)) { |
| 177 | ret = PTR_ERR(callout_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | goto error2; |
Davi Arnaut | 0cb409d | 2006-03-24 03:18:43 -0800 | [diff] [blame] | 179 | } |
David Howells | 4a38e12 | 2008-04-29 01:01:24 -0700 | [diff] [blame] | 180 | callout_len = strlen(callout_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | /* get the destination keyring if specified */ |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 184 | dest_ref = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | if (destringid) { |
David Howells | 5593122 | 2009-09-02 09:13:45 +0100 | [diff] [blame] | 186 | dest_ref = lookup_user_key(destringid, KEY_LOOKUP_CREATE, |
| 187 | KEY_WRITE); |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 188 | if (IS_ERR(dest_ref)) { |
| 189 | ret = PTR_ERR(dest_ref); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | goto error3; |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | /* find the key type */ |
| 195 | ktype = key_type_lookup(type); |
| 196 | if (IS_ERR(ktype)) { |
| 197 | ret = PTR_ERR(ktype); |
| 198 | goto error4; |
| 199 | } |
| 200 | |
| 201 | /* do the search */ |
David Howells | 4a38e12 | 2008-04-29 01:01:24 -0700 | [diff] [blame] | 202 | key = request_key_and_link(ktype, description, callout_info, |
| 203 | callout_len, NULL, key_ref_to_ptr(dest_ref), |
David Howells | 7e047ef | 2006-06-26 00:24:50 -0700 | [diff] [blame] | 204 | KEY_ALLOC_IN_QUOTA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | if (IS_ERR(key)) { |
| 206 | ret = PTR_ERR(key); |
| 207 | goto error5; |
| 208 | } |
| 209 | |
David Howells | 4aab1e8 | 2011-03-11 17:57:33 +0000 | [diff] [blame] | 210 | /* wait for the key to finish being constructed */ |
| 211 | ret = wait_for_key_construction(key, 1); |
| 212 | if (ret < 0) |
| 213 | goto error6; |
| 214 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | ret = key->serial; |
| 216 | |
David Howells | 4aab1e8 | 2011-03-11 17:57:33 +0000 | [diff] [blame] | 217 | error6: |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 218 | key_put(key); |
Justin P. Mattock | c5b60b5 | 2010-04-21 00:02:11 -0700 | [diff] [blame] | 219 | error5: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | key_type_put(ktype); |
Justin P. Mattock | c5b60b5 | 2010-04-21 00:02:11 -0700 | [diff] [blame] | 221 | error4: |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 222 | key_ref_put(dest_ref); |
Justin P. Mattock | c5b60b5 | 2010-04-21 00:02:11 -0700 | [diff] [blame] | 223 | error3: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | kfree(callout_info); |
Justin P. Mattock | c5b60b5 | 2010-04-21 00:02:11 -0700 | [diff] [blame] | 225 | error2: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | kfree(description); |
Justin P. Mattock | c5b60b5 | 2010-04-21 00:02:11 -0700 | [diff] [blame] | 227 | error: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | return ret; |
David Howells | a8b17ed | 2011-01-20 16:38:27 +0000 | [diff] [blame] | 229 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | /* |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 232 | * Get the ID of the specified process keyring. |
| 233 | * |
| 234 | * The requested keyring must have search permission to be found. |
| 235 | * |
| 236 | * If successful, the ID of the requested keyring will be returned. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | */ |
| 238 | long keyctl_get_keyring_ID(key_serial_t id, int create) |
| 239 | { |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 240 | key_ref_t key_ref; |
David Howells | 5593122 | 2009-09-02 09:13:45 +0100 | [diff] [blame] | 241 | unsigned long lflags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | long ret; |
| 243 | |
David Howells | 5593122 | 2009-09-02 09:13:45 +0100 | [diff] [blame] | 244 | lflags = create ? KEY_LOOKUP_CREATE : 0; |
| 245 | key_ref = lookup_user_key(id, lflags, KEY_SEARCH); |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 246 | if (IS_ERR(key_ref)) { |
| 247 | ret = PTR_ERR(key_ref); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | goto error; |
| 249 | } |
| 250 | |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 251 | ret = key_ref_to_ptr(key_ref)->serial; |
| 252 | key_ref_put(key_ref); |
Justin P. Mattock | c5b60b5 | 2010-04-21 00:02:11 -0700 | [diff] [blame] | 253 | error: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | return ret; |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 255 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | /* |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 258 | * Join a (named) session keyring. |
| 259 | * |
| 260 | * Create and join an anonymous session keyring or join a named session |
| 261 | * keyring, creating it if necessary. A named session keyring must have Search |
| 262 | * permission for it to be joined. Session keyrings without this permit will |
| 263 | * be skipped over. |
| 264 | * |
| 265 | * If successful, the ID of the joined session keyring will be returned. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | */ |
| 267 | long keyctl_join_session_keyring(const char __user *_name) |
| 268 | { |
| 269 | char *name; |
Davi Arnaut | 0cb409d | 2006-03-24 03:18:43 -0800 | [diff] [blame] | 270 | long ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
| 272 | /* fetch the name from userspace */ |
| 273 | name = NULL; |
| 274 | if (_name) { |
Davi Arnaut | 0cb409d | 2006-03-24 03:18:43 -0800 | [diff] [blame] | 275 | name = strndup_user(_name, PAGE_SIZE); |
| 276 | if (IS_ERR(name)) { |
| 277 | ret = PTR_ERR(name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | goto error; |
Davi Arnaut | 0cb409d | 2006-03-24 03:18:43 -0800 | [diff] [blame] | 279 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | /* join the session */ |
| 283 | ret = join_session_keyring(name); |
Vegard Nossum | 0d54ee1 | 2009-01-17 17:45:45 +0100 | [diff] [blame] | 284 | kfree(name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
Justin P. Mattock | c5b60b5 | 2010-04-21 00:02:11 -0700 | [diff] [blame] | 286 | error: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | return ret; |
David Howells | a8b17ed | 2011-01-20 16:38:27 +0000 | [diff] [blame] | 288 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | /* |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 291 | * Update a key's data payload from the given data. |
| 292 | * |
| 293 | * The key must grant the caller Write permission and the key type must support |
| 294 | * updating for this to work. A negative key can be positively instantiated |
| 295 | * with this call. |
| 296 | * |
| 297 | * If successful, 0 will be returned. If the key type does not support |
| 298 | * updating, then -EOPNOTSUPP will be returned. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | */ |
| 300 | long keyctl_update_key(key_serial_t id, |
| 301 | const void __user *_payload, |
| 302 | size_t plen) |
| 303 | { |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 304 | key_ref_t key_ref; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | void *payload; |
| 306 | long ret; |
| 307 | |
| 308 | ret = -EINVAL; |
| 309 | if (plen > PAGE_SIZE) |
| 310 | goto error; |
| 311 | |
| 312 | /* pull the payload in if one was supplied */ |
| 313 | payload = NULL; |
| 314 | if (_payload) { |
| 315 | ret = -ENOMEM; |
| 316 | payload = kmalloc(plen, GFP_KERNEL); |
| 317 | if (!payload) |
| 318 | goto error; |
| 319 | |
| 320 | ret = -EFAULT; |
| 321 | if (copy_from_user(payload, _payload, plen) != 0) |
| 322 | goto error2; |
| 323 | } |
| 324 | |
| 325 | /* find the target key (which must be writable) */ |
David Howells | 5593122 | 2009-09-02 09:13:45 +0100 | [diff] [blame] | 326 | key_ref = lookup_user_key(id, 0, KEY_WRITE); |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 327 | if (IS_ERR(key_ref)) { |
| 328 | ret = PTR_ERR(key_ref); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | goto error2; |
| 330 | } |
| 331 | |
| 332 | /* update the key */ |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 333 | ret = key_update(key_ref, payload, plen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 335 | key_ref_put(key_ref); |
Justin P. Mattock | c5b60b5 | 2010-04-21 00:02:11 -0700 | [diff] [blame] | 336 | error2: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | kfree(payload); |
Justin P. Mattock | c5b60b5 | 2010-04-21 00:02:11 -0700 | [diff] [blame] | 338 | error: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | return ret; |
David Howells | a8b17ed | 2011-01-20 16:38:27 +0000 | [diff] [blame] | 340 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | /* |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 343 | * Revoke a key. |
| 344 | * |
| 345 | * The key must be grant the caller Write or Setattr permission for this to |
| 346 | * work. The key type should give up its quota claim when revoked. The key |
| 347 | * and any links to the key will be automatically garbage collected after a |
| 348 | * certain amount of time (/proc/sys/kernel/keys/gc_delay). |
| 349 | * |
| 350 | * If successful, 0 is returned. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | */ |
| 352 | long keyctl_revoke_key(key_serial_t id) |
| 353 | { |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 354 | key_ref_t key_ref; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | long ret; |
| 356 | |
David Howells | 5593122 | 2009-09-02 09:13:45 +0100 | [diff] [blame] | 357 | key_ref = lookup_user_key(id, 0, KEY_WRITE); |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 358 | if (IS_ERR(key_ref)) { |
| 359 | ret = PTR_ERR(key_ref); |
David Howells | 0c2c9a3 | 2009-09-02 09:13:50 +0100 | [diff] [blame] | 360 | if (ret != -EACCES) |
| 361 | goto error; |
| 362 | key_ref = lookup_user_key(id, 0, KEY_SETATTR); |
| 363 | if (IS_ERR(key_ref)) { |
| 364 | ret = PTR_ERR(key_ref); |
| 365 | goto error; |
| 366 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | } |
| 368 | |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 369 | key_revoke(key_ref_to_ptr(key_ref)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | ret = 0; |
| 371 | |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 372 | key_ref_put(key_ref); |
Justin P. Mattock | c5b60b5 | 2010-04-21 00:02:11 -0700 | [diff] [blame] | 373 | error: |
David Howells | 1260f80 | 2005-08-04 11:50:01 +0100 | [diff] [blame] | 374 | return ret; |
David Howells | a8b17ed | 2011-01-20 16:38:27 +0000 | [diff] [blame] | 375 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | /* |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 378 | * Clear the specified keyring, creating an empty process keyring if one of the |
| 379 | * special keyring IDs is used. |
| 380 | * |
| 381 | * The keyring must grant the caller Write permission for this to work. If |
| 382 | * successful, 0 will be returned. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | */ |
| 384 | long keyctl_keyring_clear(key_serial_t ringid) |
| 385 | { |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 386 | key_ref_t keyring_ref; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | long ret; |
| 388 | |
David Howells | 5593122 | 2009-09-02 09:13:45 +0100 | [diff] [blame] | 389 | keyring_ref = lookup_user_key(ringid, KEY_LOOKUP_CREATE, KEY_WRITE); |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 390 | if (IS_ERR(keyring_ref)) { |
| 391 | ret = PTR_ERR(keyring_ref); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | goto error; |
| 393 | } |
| 394 | |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 395 | ret = keyring_clear(key_ref_to_ptr(keyring_ref)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 397 | key_ref_put(keyring_ref); |
Justin P. Mattock | c5b60b5 | 2010-04-21 00:02:11 -0700 | [diff] [blame] | 398 | error: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | return ret; |
David Howells | a8b17ed | 2011-01-20 16:38:27 +0000 | [diff] [blame] | 400 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | /* |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 403 | * Create a link from a keyring to a key if there's no matching key in the |
| 404 | * keyring, otherwise replace the link to the matching key with a link to the |
| 405 | * new key. |
| 406 | * |
| 407 | * The key must grant the caller Link permission and the the keyring must grant |
| 408 | * the caller Write permission. Furthermore, if an additional link is created, |
| 409 | * the keyring's quota will be extended. |
| 410 | * |
| 411 | * If successful, 0 will be returned. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | */ |
| 413 | long keyctl_keyring_link(key_serial_t id, key_serial_t ringid) |
| 414 | { |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 415 | key_ref_t keyring_ref, key_ref; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | long ret; |
| 417 | |
David Howells | 5593122 | 2009-09-02 09:13:45 +0100 | [diff] [blame] | 418 | keyring_ref = lookup_user_key(ringid, KEY_LOOKUP_CREATE, KEY_WRITE); |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 419 | if (IS_ERR(keyring_ref)) { |
| 420 | ret = PTR_ERR(keyring_ref); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | goto error; |
| 422 | } |
| 423 | |
David Howells | 5593122 | 2009-09-02 09:13:45 +0100 | [diff] [blame] | 424 | key_ref = lookup_user_key(id, KEY_LOOKUP_CREATE, KEY_LINK); |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 425 | if (IS_ERR(key_ref)) { |
| 426 | ret = PTR_ERR(key_ref); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | goto error2; |
| 428 | } |
| 429 | |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 430 | ret = key_link(key_ref_to_ptr(keyring_ref), key_ref_to_ptr(key_ref)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 432 | key_ref_put(key_ref); |
Justin P. Mattock | c5b60b5 | 2010-04-21 00:02:11 -0700 | [diff] [blame] | 433 | error2: |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 434 | key_ref_put(keyring_ref); |
Justin P. Mattock | c5b60b5 | 2010-04-21 00:02:11 -0700 | [diff] [blame] | 435 | error: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | return ret; |
David Howells | a8b17ed | 2011-01-20 16:38:27 +0000 | [diff] [blame] | 437 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | /* |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 440 | * Unlink a key from a keyring. |
| 441 | * |
| 442 | * The keyring must grant the caller Write permission for this to work; the key |
| 443 | * itself need not grant the caller anything. If the last link to a key is |
| 444 | * removed then that key will be scheduled for destruction. |
| 445 | * |
| 446 | * If successful, 0 will be returned. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | */ |
| 448 | long keyctl_keyring_unlink(key_serial_t id, key_serial_t ringid) |
| 449 | { |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 450 | key_ref_t keyring_ref, key_ref; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | long ret; |
| 452 | |
David Howells | 5593122 | 2009-09-02 09:13:45 +0100 | [diff] [blame] | 453 | keyring_ref = lookup_user_key(ringid, 0, KEY_WRITE); |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 454 | if (IS_ERR(keyring_ref)) { |
| 455 | ret = PTR_ERR(keyring_ref); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | goto error; |
| 457 | } |
| 458 | |
David Howells | 5593122 | 2009-09-02 09:13:45 +0100 | [diff] [blame] | 459 | key_ref = lookup_user_key(id, KEY_LOOKUP_FOR_UNLINK, 0); |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 460 | if (IS_ERR(key_ref)) { |
| 461 | ret = PTR_ERR(key_ref); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | goto error2; |
| 463 | } |
| 464 | |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 465 | ret = key_unlink(key_ref_to_ptr(keyring_ref), key_ref_to_ptr(key_ref)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 467 | key_ref_put(key_ref); |
Justin P. Mattock | c5b60b5 | 2010-04-21 00:02:11 -0700 | [diff] [blame] | 468 | error2: |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 469 | key_ref_put(keyring_ref); |
Justin P. Mattock | c5b60b5 | 2010-04-21 00:02:11 -0700 | [diff] [blame] | 470 | error: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | return ret; |
David Howells | a8b17ed | 2011-01-20 16:38:27 +0000 | [diff] [blame] | 472 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | /* |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 475 | * Return a description of a key to userspace. |
| 476 | * |
| 477 | * The key must grant the caller View permission for this to work. |
| 478 | * |
| 479 | * If there's a buffer, we place up to buflen bytes of data into it formatted |
| 480 | * in the following way: |
| 481 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | * type;uid;gid;perm;description<NUL> |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 483 | * |
| 484 | * If successful, we return the amount of description available, irrespective |
| 485 | * of how much we may have copied into the buffer. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | */ |
| 487 | long keyctl_describe_key(key_serial_t keyid, |
| 488 | char __user *buffer, |
| 489 | size_t buflen) |
| 490 | { |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 491 | struct key *key, *instkey; |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 492 | key_ref_t key_ref; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | char *tmpbuf; |
| 494 | long ret; |
| 495 | |
David Howells | 5593122 | 2009-09-02 09:13:45 +0100 | [diff] [blame] | 496 | key_ref = lookup_user_key(keyid, KEY_LOOKUP_PARTIAL, KEY_VIEW); |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 497 | if (IS_ERR(key_ref)) { |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 498 | /* viewing a key under construction is permitted if we have the |
| 499 | * authorisation token handy */ |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 500 | if (PTR_ERR(key_ref) == -EACCES) { |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 501 | instkey = key_get_instantiation_authkey(keyid); |
| 502 | if (!IS_ERR(instkey)) { |
| 503 | key_put(instkey); |
David Howells | 8bbf4976 | 2008-11-14 10:39:14 +1100 | [diff] [blame] | 504 | key_ref = lookup_user_key(keyid, |
David Howells | 5593122 | 2009-09-02 09:13:45 +0100 | [diff] [blame] | 505 | KEY_LOOKUP_PARTIAL, |
| 506 | 0); |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 507 | if (!IS_ERR(key_ref)) |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 508 | goto okay; |
| 509 | } |
| 510 | } |
| 511 | |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 512 | ret = PTR_ERR(key_ref); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | goto error; |
| 514 | } |
| 515 | |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 516 | okay: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | /* calculate how much description we're going to return */ |
| 518 | ret = -ENOMEM; |
| 519 | tmpbuf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
| 520 | if (!tmpbuf) |
| 521 | goto error2; |
| 522 | |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 523 | key = key_ref_to_ptr(key_ref); |
| 524 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | ret = snprintf(tmpbuf, PAGE_SIZE - 1, |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 526 | "%s;%d;%d;%08x;%s", |
David Howells | 94fd840 | 2010-06-28 14:05:04 +0100 | [diff] [blame] | 527 | key->type->name, |
| 528 | key->uid, |
| 529 | key->gid, |
| 530 | key->perm, |
| 531 | key->description ?: ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | |
| 533 | /* include a NUL char at the end of the data */ |
| 534 | if (ret > PAGE_SIZE - 1) |
| 535 | ret = PAGE_SIZE - 1; |
| 536 | tmpbuf[ret] = 0; |
| 537 | ret++; |
| 538 | |
| 539 | /* consider returning the data */ |
| 540 | if (buffer && buflen > 0) { |
| 541 | if (buflen > ret) |
| 542 | buflen = ret; |
| 543 | |
| 544 | if (copy_to_user(buffer, tmpbuf, buflen) != 0) |
| 545 | ret = -EFAULT; |
| 546 | } |
| 547 | |
| 548 | kfree(tmpbuf); |
Justin P. Mattock | c5b60b5 | 2010-04-21 00:02:11 -0700 | [diff] [blame] | 549 | error2: |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 550 | key_ref_put(key_ref); |
Justin P. Mattock | c5b60b5 | 2010-04-21 00:02:11 -0700 | [diff] [blame] | 551 | error: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | return ret; |
David Howells | a8b17ed | 2011-01-20 16:38:27 +0000 | [diff] [blame] | 553 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | /* |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 556 | * Search the specified keyring and any keyrings it links to for a matching |
| 557 | * key. Only keyrings that grant the caller Search permission will be searched |
| 558 | * (this includes the starting keyring). Only keys with Search permission can |
| 559 | * be found. |
| 560 | * |
| 561 | * If successful, the found key will be linked to the destination keyring if |
| 562 | * supplied and the key has Link permission, and the found key ID will be |
| 563 | * returned. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | */ |
| 565 | long keyctl_keyring_search(key_serial_t ringid, |
| 566 | const char __user *_type, |
| 567 | const char __user *_description, |
| 568 | key_serial_t destringid) |
| 569 | { |
| 570 | struct key_type *ktype; |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 571 | key_ref_t keyring_ref, key_ref, dest_ref; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | char type[32], *description; |
Davi Arnaut | 0cb409d | 2006-03-24 03:18:43 -0800 | [diff] [blame] | 573 | long ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | |
| 575 | /* pull the type and description into kernel space */ |
Davi Arnaut | 0cb409d | 2006-03-24 03:18:43 -0800 | [diff] [blame] | 576 | ret = key_get_type_from_user(type, _type, sizeof(type)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | if (ret < 0) |
| 578 | goto error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | |
Davi Arnaut | 0cb409d | 2006-03-24 03:18:43 -0800 | [diff] [blame] | 580 | description = strndup_user(_description, PAGE_SIZE); |
| 581 | if (IS_ERR(description)) { |
| 582 | ret = PTR_ERR(description); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | goto error; |
Davi Arnaut | 0cb409d | 2006-03-24 03:18:43 -0800 | [diff] [blame] | 584 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | |
| 586 | /* get the keyring at which to begin the search */ |
David Howells | 5593122 | 2009-09-02 09:13:45 +0100 | [diff] [blame] | 587 | keyring_ref = lookup_user_key(ringid, 0, KEY_SEARCH); |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 588 | if (IS_ERR(keyring_ref)) { |
| 589 | ret = PTR_ERR(keyring_ref); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | goto error2; |
| 591 | } |
| 592 | |
| 593 | /* get the destination keyring if specified */ |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 594 | dest_ref = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | if (destringid) { |
David Howells | 5593122 | 2009-09-02 09:13:45 +0100 | [diff] [blame] | 596 | dest_ref = lookup_user_key(destringid, KEY_LOOKUP_CREATE, |
| 597 | KEY_WRITE); |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 598 | if (IS_ERR(dest_ref)) { |
| 599 | ret = PTR_ERR(dest_ref); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | goto error3; |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | /* find the key type */ |
| 605 | ktype = key_type_lookup(type); |
| 606 | if (IS_ERR(ktype)) { |
| 607 | ret = PTR_ERR(ktype); |
| 608 | goto error4; |
| 609 | } |
| 610 | |
| 611 | /* do the search */ |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 612 | key_ref = keyring_search(keyring_ref, ktype, description); |
| 613 | if (IS_ERR(key_ref)) { |
| 614 | ret = PTR_ERR(key_ref); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | |
| 616 | /* treat lack or presence of a negative key the same */ |
| 617 | if (ret == -EAGAIN) |
| 618 | ret = -ENOKEY; |
| 619 | goto error5; |
| 620 | } |
| 621 | |
| 622 | /* link the resulting key to the destination keyring if we can */ |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 623 | if (dest_ref) { |
David Howells | 29db919 | 2005-10-30 15:02:44 -0800 | [diff] [blame] | 624 | ret = key_permission(key_ref, KEY_LINK); |
| 625 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | goto error6; |
| 627 | |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 628 | ret = key_link(key_ref_to_ptr(dest_ref), key_ref_to_ptr(key_ref)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | if (ret < 0) |
| 630 | goto error6; |
| 631 | } |
| 632 | |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 633 | ret = key_ref_to_ptr(key_ref)->serial; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | |
Justin P. Mattock | c5b60b5 | 2010-04-21 00:02:11 -0700 | [diff] [blame] | 635 | error6: |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 636 | key_ref_put(key_ref); |
Justin P. Mattock | c5b60b5 | 2010-04-21 00:02:11 -0700 | [diff] [blame] | 637 | error5: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | key_type_put(ktype); |
Justin P. Mattock | c5b60b5 | 2010-04-21 00:02:11 -0700 | [diff] [blame] | 639 | error4: |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 640 | key_ref_put(dest_ref); |
Justin P. Mattock | c5b60b5 | 2010-04-21 00:02:11 -0700 | [diff] [blame] | 641 | error3: |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 642 | key_ref_put(keyring_ref); |
Justin P. Mattock | c5b60b5 | 2010-04-21 00:02:11 -0700 | [diff] [blame] | 643 | error2: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | kfree(description); |
Justin P. Mattock | c5b60b5 | 2010-04-21 00:02:11 -0700 | [diff] [blame] | 645 | error: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | return ret; |
David Howells | a8b17ed | 2011-01-20 16:38:27 +0000 | [diff] [blame] | 647 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | /* |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 650 | * Read a key's payload. |
| 651 | * |
| 652 | * The key must either grant the caller Read permission, or it must grant the |
| 653 | * caller Search permission when searched for from the process keyrings. |
| 654 | * |
| 655 | * If successful, we place up to buflen bytes of data into the buffer, if one |
| 656 | * is provided, and return the amount of data that is available in the key, |
| 657 | * irrespective of how much we copied into the buffer. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | */ |
| 659 | long keyctl_read_key(key_serial_t keyid, char __user *buffer, size_t buflen) |
| 660 | { |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 661 | struct key *key; |
| 662 | key_ref_t key_ref; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | long ret; |
| 664 | |
| 665 | /* find the key first */ |
David Howells | 5593122 | 2009-09-02 09:13:45 +0100 | [diff] [blame] | 666 | key_ref = lookup_user_key(keyid, 0, 0); |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 667 | if (IS_ERR(key_ref)) { |
| 668 | ret = -ENOKEY; |
| 669 | goto error; |
| 670 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 672 | key = key_ref_to_ptr(key_ref); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 674 | /* see if we can read it directly */ |
David Howells | 29db919 | 2005-10-30 15:02:44 -0800 | [diff] [blame] | 675 | ret = key_permission(key_ref, KEY_READ); |
| 676 | if (ret == 0) |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 677 | goto can_read_key; |
David Howells | 29db919 | 2005-10-30 15:02:44 -0800 | [diff] [blame] | 678 | if (ret != -EACCES) |
| 679 | goto error; |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 680 | |
| 681 | /* we can't; see if it's searchable from this process's keyrings |
| 682 | * - we automatically take account of the fact that it may be |
| 683 | * dangling off an instantiation key |
| 684 | */ |
| 685 | if (!is_key_possessed(key_ref)) { |
| 686 | ret = -EACCES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | goto error2; |
| 688 | } |
| 689 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | /* the key is probably readable - now try to read it */ |
Justin P. Mattock | c5b60b5 | 2010-04-21 00:02:11 -0700 | [diff] [blame] | 691 | can_read_key: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | ret = key_validate(key); |
| 693 | if (ret == 0) { |
| 694 | ret = -EOPNOTSUPP; |
| 695 | if (key->type->read) { |
| 696 | /* read the data with the semaphore held (since we |
| 697 | * might sleep) */ |
| 698 | down_read(&key->sem); |
| 699 | ret = key->type->read(key, buffer, buflen); |
| 700 | up_read(&key->sem); |
| 701 | } |
| 702 | } |
| 703 | |
Justin P. Mattock | c5b60b5 | 2010-04-21 00:02:11 -0700 | [diff] [blame] | 704 | error2: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | key_put(key); |
Justin P. Mattock | c5b60b5 | 2010-04-21 00:02:11 -0700 | [diff] [blame] | 706 | error: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | return ret; |
David Howells | a8b17ed | 2011-01-20 16:38:27 +0000 | [diff] [blame] | 708 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | /* |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 711 | * Change the ownership of a key |
| 712 | * |
| 713 | * The key must grant the caller Setattr permission for this to work, though |
| 714 | * the key need not be fully instantiated yet. For the UID to be changed, or |
| 715 | * for the GID to be changed to a group the caller is not a member of, the |
| 716 | * caller must have sysadmin capability. If either uid or gid is -1 then that |
| 717 | * attribute is not changed. |
| 718 | * |
| 719 | * If the UID is to be changed, the new user must have sufficient quota to |
| 720 | * accept the key. The quota deduction will be removed from the old user to |
| 721 | * the new user should the attribute be changed. |
| 722 | * |
| 723 | * If successful, 0 will be returned. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | */ |
| 725 | long keyctl_chown_key(key_serial_t id, uid_t uid, gid_t gid) |
| 726 | { |
Fredrik Tolf | 5801649 | 2006-06-26 00:24:51 -0700 | [diff] [blame] | 727 | struct key_user *newowner, *zapowner = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | struct key *key; |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 729 | key_ref_t key_ref; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | long ret; |
| 731 | |
| 732 | ret = 0; |
| 733 | if (uid == (uid_t) -1 && gid == (gid_t) -1) |
| 734 | goto error; |
| 735 | |
David Howells | 5593122 | 2009-09-02 09:13:45 +0100 | [diff] [blame] | 736 | key_ref = lookup_user_key(id, KEY_LOOKUP_CREATE | KEY_LOOKUP_PARTIAL, |
| 737 | KEY_SETATTR); |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 738 | if (IS_ERR(key_ref)) { |
| 739 | ret = PTR_ERR(key_ref); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | goto error; |
| 741 | } |
| 742 | |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 743 | key = key_ref_to_ptr(key_ref); |
| 744 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | /* make the changes with the locks held to prevent chown/chown races */ |
| 746 | ret = -EACCES; |
| 747 | down_write(&key->sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | |
| 749 | if (!capable(CAP_SYS_ADMIN)) { |
| 750 | /* only the sysadmin can chown a key to some other UID */ |
| 751 | if (uid != (uid_t) -1 && key->uid != uid) |
Fredrik Tolf | 5801649 | 2006-06-26 00:24:51 -0700 | [diff] [blame] | 752 | goto error_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | |
| 754 | /* only the sysadmin can set the key's GID to a group other |
| 755 | * than one of those that the current process subscribes to */ |
| 756 | if (gid != (gid_t) -1 && gid != key->gid && !in_group_p(gid)) |
Fredrik Tolf | 5801649 | 2006-06-26 00:24:51 -0700 | [diff] [blame] | 757 | goto error_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | } |
| 759 | |
Fredrik Tolf | 5801649 | 2006-06-26 00:24:51 -0700 | [diff] [blame] | 760 | /* change the UID */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | if (uid != (uid_t) -1 && uid != key->uid) { |
Fredrik Tolf | 5801649 | 2006-06-26 00:24:51 -0700 | [diff] [blame] | 762 | ret = -ENOMEM; |
Serge E. Hallyn | 1d1e975 | 2009-02-26 18:27:38 -0600 | [diff] [blame] | 763 | newowner = key_user_lookup(uid, current_user_ns()); |
Fredrik Tolf | 5801649 | 2006-06-26 00:24:51 -0700 | [diff] [blame] | 764 | if (!newowner) |
| 765 | goto error_put; |
| 766 | |
| 767 | /* transfer the quota burden to the new user */ |
| 768 | if (test_bit(KEY_FLAG_IN_QUOTA, &key->flags)) { |
David Howells | 0b77f5b | 2008-04-29 01:01:32 -0700 | [diff] [blame] | 769 | unsigned maxkeys = (uid == 0) ? |
| 770 | key_quota_root_maxkeys : key_quota_maxkeys; |
| 771 | unsigned maxbytes = (uid == 0) ? |
| 772 | key_quota_root_maxbytes : key_quota_maxbytes; |
| 773 | |
Fredrik Tolf | 5801649 | 2006-06-26 00:24:51 -0700 | [diff] [blame] | 774 | spin_lock(&newowner->lock); |
David Howells | 0b77f5b | 2008-04-29 01:01:32 -0700 | [diff] [blame] | 775 | if (newowner->qnkeys + 1 >= maxkeys || |
| 776 | newowner->qnbytes + key->quotalen >= maxbytes || |
| 777 | newowner->qnbytes + key->quotalen < |
| 778 | newowner->qnbytes) |
Fredrik Tolf | 5801649 | 2006-06-26 00:24:51 -0700 | [diff] [blame] | 779 | goto quota_overrun; |
| 780 | |
| 781 | newowner->qnkeys++; |
| 782 | newowner->qnbytes += key->quotalen; |
| 783 | spin_unlock(&newowner->lock); |
| 784 | |
| 785 | spin_lock(&key->user->lock); |
| 786 | key->user->qnkeys--; |
| 787 | key->user->qnbytes -= key->quotalen; |
| 788 | spin_unlock(&key->user->lock); |
| 789 | } |
| 790 | |
| 791 | atomic_dec(&key->user->nkeys); |
| 792 | atomic_inc(&newowner->nkeys); |
| 793 | |
| 794 | if (test_bit(KEY_FLAG_INSTANTIATED, &key->flags)) { |
| 795 | atomic_dec(&key->user->nikeys); |
| 796 | atomic_inc(&newowner->nikeys); |
| 797 | } |
| 798 | |
| 799 | zapowner = key->user; |
| 800 | key->user = newowner; |
| 801 | key->uid = uid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | /* change the GID */ |
| 805 | if (gid != (gid_t) -1) |
| 806 | key->gid = gid; |
| 807 | |
| 808 | ret = 0; |
| 809 | |
Fredrik Tolf | 5801649 | 2006-06-26 00:24:51 -0700 | [diff] [blame] | 810 | error_put: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | up_write(&key->sem); |
| 812 | key_put(key); |
Fredrik Tolf | 5801649 | 2006-06-26 00:24:51 -0700 | [diff] [blame] | 813 | if (zapowner) |
| 814 | key_user_put(zapowner); |
| 815 | error: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | return ret; |
| 817 | |
Fredrik Tolf | 5801649 | 2006-06-26 00:24:51 -0700 | [diff] [blame] | 818 | quota_overrun: |
| 819 | spin_unlock(&newowner->lock); |
| 820 | zapowner = newowner; |
| 821 | ret = -EDQUOT; |
| 822 | goto error_put; |
David Howells | a8b17ed | 2011-01-20 16:38:27 +0000 | [diff] [blame] | 823 | } |
Fredrik Tolf | 5801649 | 2006-06-26 00:24:51 -0700 | [diff] [blame] | 824 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | /* |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 826 | * Change the permission mask on a key. |
| 827 | * |
| 828 | * The key must grant the caller Setattr permission for this to work, though |
| 829 | * the key need not be fully instantiated yet. If the caller does not have |
| 830 | * sysadmin capability, it may only change the permission on keys that it owns. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | */ |
| 832 | long keyctl_setperm_key(key_serial_t id, key_perm_t perm) |
| 833 | { |
| 834 | struct key *key; |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 835 | key_ref_t key_ref; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | long ret; |
| 837 | |
| 838 | ret = -EINVAL; |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 839 | if (perm & ~(KEY_POS_ALL | KEY_USR_ALL | KEY_GRP_ALL | KEY_OTH_ALL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | goto error; |
| 841 | |
David Howells | 5593122 | 2009-09-02 09:13:45 +0100 | [diff] [blame] | 842 | key_ref = lookup_user_key(id, KEY_LOOKUP_CREATE | KEY_LOOKUP_PARTIAL, |
| 843 | KEY_SETATTR); |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 844 | if (IS_ERR(key_ref)) { |
| 845 | ret = PTR_ERR(key_ref); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | goto error; |
| 847 | } |
| 848 | |
David Howells | 664cceb | 2005-09-28 17:03:15 +0100 | [diff] [blame] | 849 | key = key_ref_to_ptr(key_ref); |
| 850 | |
David Howells | 76d8aea | 2005-06-23 22:00:49 -0700 | [diff] [blame] | 851 | /* make the changes with the locks held to prevent chown/chmod races */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | ret = -EACCES; |
| 853 | down_write(&key->sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | |
David Howells | 76d8aea | 2005-06-23 22:00:49 -0700 | [diff] [blame] | 855 | /* if we're not the sysadmin, we can only change a key that we own */ |
David Howells | 47d804b | 2008-11-14 10:39:11 +1100 | [diff] [blame] | 856 | if (capable(CAP_SYS_ADMIN) || key->uid == current_fsuid()) { |
David Howells | 76d8aea | 2005-06-23 22:00:49 -0700 | [diff] [blame] | 857 | key->perm = perm; |
| 858 | ret = 0; |
| 859 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | up_write(&key->sem); |
| 862 | key_put(key); |
David Howells | 76d8aea | 2005-06-23 22:00:49 -0700 | [diff] [blame] | 863 | error: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | return ret; |
David Howells | a8b17ed | 2011-01-20 16:38:27 +0000 | [diff] [blame] | 865 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | |
David Howells | 8bbf4976 | 2008-11-14 10:39:14 +1100 | [diff] [blame] | 867 | /* |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 868 | * Get the destination keyring for instantiation and check that the caller has |
| 869 | * Write permission on it. |
David Howells | 8bbf4976 | 2008-11-14 10:39:14 +1100 | [diff] [blame] | 870 | */ |
| 871 | static long get_instantiation_keyring(key_serial_t ringid, |
| 872 | struct request_key_auth *rka, |
| 873 | struct key **_dest_keyring) |
| 874 | { |
| 875 | key_ref_t dkref; |
| 876 | |
David Howells | eca1bf5 | 2008-12-29 00:41:51 +0000 | [diff] [blame] | 877 | *_dest_keyring = NULL; |
| 878 | |
David Howells | 8bbf4976 | 2008-11-14 10:39:14 +1100 | [diff] [blame] | 879 | /* just return a NULL pointer if we weren't asked to make a link */ |
David Howells | eca1bf5 | 2008-12-29 00:41:51 +0000 | [diff] [blame] | 880 | if (ringid == 0) |
David Howells | 8bbf4976 | 2008-11-14 10:39:14 +1100 | [diff] [blame] | 881 | return 0; |
David Howells | 8bbf4976 | 2008-11-14 10:39:14 +1100 | [diff] [blame] | 882 | |
| 883 | /* if a specific keyring is nominated by ID, then use that */ |
| 884 | if (ringid > 0) { |
David Howells | 5593122 | 2009-09-02 09:13:45 +0100 | [diff] [blame] | 885 | dkref = lookup_user_key(ringid, KEY_LOOKUP_CREATE, KEY_WRITE); |
David Howells | 8bbf4976 | 2008-11-14 10:39:14 +1100 | [diff] [blame] | 886 | if (IS_ERR(dkref)) |
| 887 | return PTR_ERR(dkref); |
| 888 | *_dest_keyring = key_ref_to_ptr(dkref); |
| 889 | return 0; |
| 890 | } |
| 891 | |
| 892 | if (ringid == KEY_SPEC_REQKEY_AUTH_KEY) |
| 893 | return -EINVAL; |
| 894 | |
| 895 | /* otherwise specify the destination keyring recorded in the |
| 896 | * authorisation key (any KEY_SPEC_*_KEYRING) */ |
| 897 | if (ringid >= KEY_SPEC_REQUESTOR_KEYRING) { |
David Howells | 21279cf | 2009-10-15 10:14:35 +0100 | [diff] [blame] | 898 | *_dest_keyring = key_get(rka->dest_keyring); |
David Howells | 8bbf4976 | 2008-11-14 10:39:14 +1100 | [diff] [blame] | 899 | return 0; |
| 900 | } |
| 901 | |
| 902 | return -ENOKEY; |
| 903 | } |
| 904 | |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 905 | /* |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 906 | * Change the request_key authorisation key on the current process. |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 907 | */ |
| 908 | static int keyctl_change_reqkey_auth(struct key *key) |
| 909 | { |
| 910 | struct cred *new; |
| 911 | |
| 912 | new = prepare_creds(); |
| 913 | if (!new) |
| 914 | return -ENOMEM; |
| 915 | |
| 916 | key_put(new->request_key_auth); |
| 917 | new->request_key_auth = key_get(key); |
| 918 | |
| 919 | return commit_creds(new); |
| 920 | } |
| 921 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | /* |
David Howells | ee009e4a0 | 2011-03-07 15:06:20 +0000 | [diff] [blame] | 923 | * Copy the iovec data from userspace |
| 924 | */ |
| 925 | static long copy_from_user_iovec(void *buffer, const struct iovec *iov, |
| 926 | unsigned ioc) |
| 927 | { |
| 928 | for (; ioc > 0; ioc--) { |
| 929 | if (copy_from_user(buffer, iov->iov_base, iov->iov_len) != 0) |
| 930 | return -EFAULT; |
| 931 | buffer += iov->iov_len; |
| 932 | iov++; |
| 933 | } |
| 934 | return 0; |
| 935 | } |
| 936 | |
| 937 | /* |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 938 | * Instantiate a key with the specified payload and link the key into the |
| 939 | * destination keyring if one is given. |
| 940 | * |
| 941 | * The caller must have the appropriate instantiation permit set for this to |
| 942 | * work (see keyctl_assume_authority). No other permissions are required. |
| 943 | * |
| 944 | * If successful, 0 will be returned. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | */ |
David Howells | ee009e4a0 | 2011-03-07 15:06:20 +0000 | [diff] [blame] | 946 | long keyctl_instantiate_key_common(key_serial_t id, |
| 947 | const struct iovec *payload_iov, |
| 948 | unsigned ioc, |
| 949 | size_t plen, |
| 950 | key_serial_t ringid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | { |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 952 | const struct cred *cred = current_cred(); |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 953 | struct request_key_auth *rka; |
David Howells | 8bbf4976 | 2008-11-14 10:39:14 +1100 | [diff] [blame] | 954 | struct key *instkey, *dest_keyring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | void *payload; |
| 956 | long ret; |
David Howells | 38bbca6 | 2008-04-29 01:01:19 -0700 | [diff] [blame] | 957 | bool vm = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 959 | kenter("%d,,%zu,%d", id, plen, ringid); |
| 960 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | ret = -EINVAL; |
David Howells | 38bbca6 | 2008-04-29 01:01:19 -0700 | [diff] [blame] | 962 | if (plen > 1024 * 1024 - 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | goto error; |
| 964 | |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 965 | /* the appropriate instantiation authorisation key must have been |
| 966 | * assumed before calling this */ |
| 967 | ret = -EPERM; |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 968 | instkey = cred->request_key_auth; |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 969 | if (!instkey) |
| 970 | goto error; |
| 971 | |
| 972 | rka = instkey->payload.data; |
| 973 | if (rka->target_key->serial != id) |
| 974 | goto error; |
| 975 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | /* pull the payload in if one was supplied */ |
| 977 | payload = NULL; |
| 978 | |
David Howells | ee009e4a0 | 2011-03-07 15:06:20 +0000 | [diff] [blame] | 979 | if (payload_iov) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | ret = -ENOMEM; |
| 981 | payload = kmalloc(plen, GFP_KERNEL); |
David Howells | 38bbca6 | 2008-04-29 01:01:19 -0700 | [diff] [blame] | 982 | if (!payload) { |
| 983 | if (plen <= PAGE_SIZE) |
| 984 | goto error; |
| 985 | vm = true; |
| 986 | payload = vmalloc(plen); |
| 987 | if (!payload) |
| 988 | goto error; |
| 989 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | |
David Howells | ee009e4a0 | 2011-03-07 15:06:20 +0000 | [diff] [blame] | 991 | ret = copy_from_user_iovec(payload, payload_iov, ioc); |
| 992 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | goto error2; |
| 994 | } |
| 995 | |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 996 | /* find the destination keyring amongst those belonging to the |
| 997 | * requesting task */ |
David Howells | 8bbf4976 | 2008-11-14 10:39:14 +1100 | [diff] [blame] | 998 | ret = get_instantiation_keyring(ringid, rka, &dest_keyring); |
| 999 | if (ret < 0) |
| 1000 | goto error2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | |
| 1002 | /* instantiate the key and link it into a keyring */ |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 1003 | ret = key_instantiate_and_link(rka->target_key, payload, plen, |
David Howells | 8bbf4976 | 2008-11-14 10:39:14 +1100 | [diff] [blame] | 1004 | dest_keyring, instkey); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | |
David Howells | 8bbf4976 | 2008-11-14 10:39:14 +1100 | [diff] [blame] | 1006 | key_put(dest_keyring); |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 1007 | |
| 1008 | /* discard the assumed authority if it's just been disabled by |
| 1009 | * instantiation of the key */ |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 1010 | if (ret == 0) |
| 1011 | keyctl_change_reqkey_auth(NULL); |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 1012 | |
| 1013 | error2: |
David Howells | 38bbca6 | 2008-04-29 01:01:19 -0700 | [diff] [blame] | 1014 | if (!vm) |
| 1015 | kfree(payload); |
| 1016 | else |
| 1017 | vfree(payload); |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 1018 | error: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | return ret; |
David Howells | a8b17ed | 2011-01-20 16:38:27 +0000 | [diff] [blame] | 1020 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | /* |
David Howells | ee009e4a0 | 2011-03-07 15:06:20 +0000 | [diff] [blame] | 1023 | * Instantiate a key with the specified payload and link the key into the |
| 1024 | * destination keyring if one is given. |
| 1025 | * |
| 1026 | * The caller must have the appropriate instantiation permit set for this to |
| 1027 | * work (see keyctl_assume_authority). No other permissions are required. |
| 1028 | * |
| 1029 | * If successful, 0 will be returned. |
| 1030 | */ |
| 1031 | long keyctl_instantiate_key(key_serial_t id, |
| 1032 | const void __user *_payload, |
| 1033 | size_t plen, |
| 1034 | key_serial_t ringid) |
| 1035 | { |
| 1036 | if (_payload && plen) { |
| 1037 | struct iovec iov[1] = { |
| 1038 | [0].iov_base = (void __user *)_payload, |
| 1039 | [0].iov_len = plen |
| 1040 | }; |
| 1041 | |
| 1042 | return keyctl_instantiate_key_common(id, iov, 1, plen, ringid); |
| 1043 | } |
| 1044 | |
| 1045 | return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid); |
| 1046 | } |
| 1047 | |
| 1048 | /* |
| 1049 | * Instantiate a key with the specified multipart payload and link the key into |
| 1050 | * the destination keyring if one is given. |
| 1051 | * |
| 1052 | * The caller must have the appropriate instantiation permit set for this to |
| 1053 | * work (see keyctl_assume_authority). No other permissions are required. |
| 1054 | * |
| 1055 | * If successful, 0 will be returned. |
| 1056 | */ |
| 1057 | long keyctl_instantiate_key_iov(key_serial_t id, |
| 1058 | const struct iovec __user *_payload_iov, |
| 1059 | unsigned ioc, |
| 1060 | key_serial_t ringid) |
| 1061 | { |
| 1062 | struct iovec iovstack[UIO_FASTIOV], *iov = iovstack; |
| 1063 | long ret; |
| 1064 | |
| 1065 | if (_payload_iov == 0 || ioc == 0) |
| 1066 | goto no_payload; |
| 1067 | |
| 1068 | ret = rw_copy_check_uvector(WRITE, _payload_iov, ioc, |
Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 1069 | ARRAY_SIZE(iovstack), iovstack, &iov, 1); |
David Howells | ee009e4a0 | 2011-03-07 15:06:20 +0000 | [diff] [blame] | 1070 | if (ret < 0) |
| 1071 | return ret; |
| 1072 | if (ret == 0) |
| 1073 | goto no_payload_free; |
| 1074 | |
| 1075 | ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid); |
| 1076 | |
| 1077 | if (iov != iovstack) |
| 1078 | kfree(iov); |
| 1079 | return ret; |
| 1080 | |
| 1081 | no_payload_free: |
| 1082 | if (iov != iovstack) |
| 1083 | kfree(iov); |
| 1084 | no_payload: |
| 1085 | return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid); |
| 1086 | } |
| 1087 | |
| 1088 | /* |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 1089 | * Negatively instantiate the key with the given timeout (in seconds) and link |
| 1090 | * the key into the destination keyring if one is given. |
| 1091 | * |
| 1092 | * The caller must have the appropriate instantiation permit set for this to |
| 1093 | * work (see keyctl_assume_authority). No other permissions are required. |
| 1094 | * |
| 1095 | * The key and any links to the key will be automatically garbage collected |
| 1096 | * after the timeout expires. |
| 1097 | * |
| 1098 | * Negative keys are used to rate limit repeated request_key() calls by causing |
| 1099 | * them to return -ENOKEY until the negative key expires. |
| 1100 | * |
| 1101 | * If successful, 0 will be returned. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | */ |
| 1103 | long keyctl_negate_key(key_serial_t id, unsigned timeout, key_serial_t ringid) |
| 1104 | { |
David Howells | fdd1b94 | 2011-03-07 15:06:09 +0000 | [diff] [blame] | 1105 | return keyctl_reject_key(id, timeout, ENOKEY, ringid); |
| 1106 | } |
| 1107 | |
| 1108 | /* |
| 1109 | * Negatively instantiate the key with the given timeout (in seconds) and error |
| 1110 | * code and link the key into the destination keyring if one is given. |
| 1111 | * |
| 1112 | * The caller must have the appropriate instantiation permit set for this to |
| 1113 | * work (see keyctl_assume_authority). No other permissions are required. |
| 1114 | * |
| 1115 | * The key and any links to the key will be automatically garbage collected |
| 1116 | * after the timeout expires. |
| 1117 | * |
| 1118 | * Negative keys are used to rate limit repeated request_key() calls by causing |
| 1119 | * them to return the specified error code until the negative key expires. |
| 1120 | * |
| 1121 | * If successful, 0 will be returned. |
| 1122 | */ |
| 1123 | long keyctl_reject_key(key_serial_t id, unsigned timeout, unsigned error, |
| 1124 | key_serial_t ringid) |
| 1125 | { |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 1126 | const struct cred *cred = current_cred(); |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 1127 | struct request_key_auth *rka; |
David Howells | 8bbf4976 | 2008-11-14 10:39:14 +1100 | [diff] [blame] | 1128 | struct key *instkey, *dest_keyring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | long ret; |
| 1130 | |
David Howells | fdd1b94 | 2011-03-07 15:06:09 +0000 | [diff] [blame] | 1131 | kenter("%d,%u,%u,%d", id, timeout, error, ringid); |
| 1132 | |
| 1133 | /* must be a valid error code and mustn't be a kernel special */ |
| 1134 | if (error <= 0 || |
| 1135 | error >= MAX_ERRNO || |
| 1136 | error == ERESTARTSYS || |
| 1137 | error == ERESTARTNOINTR || |
| 1138 | error == ERESTARTNOHAND || |
| 1139 | error == ERESTART_RESTARTBLOCK) |
| 1140 | return -EINVAL; |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 1141 | |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 1142 | /* the appropriate instantiation authorisation key must have been |
| 1143 | * assumed before calling this */ |
| 1144 | ret = -EPERM; |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 1145 | instkey = cred->request_key_auth; |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 1146 | if (!instkey) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | goto error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 1149 | rka = instkey->payload.data; |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 1150 | if (rka->target_key->serial != id) |
| 1151 | goto error; |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 1152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | /* find the destination keyring if present (which must also be |
| 1154 | * writable) */ |
David Howells | 8bbf4976 | 2008-11-14 10:39:14 +1100 | [diff] [blame] | 1155 | ret = get_instantiation_keyring(ringid, rka, &dest_keyring); |
| 1156 | if (ret < 0) |
| 1157 | goto error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | |
| 1159 | /* instantiate the key and link it into a keyring */ |
David Howells | fdd1b94 | 2011-03-07 15:06:09 +0000 | [diff] [blame] | 1160 | ret = key_reject_and_link(rka->target_key, timeout, error, |
David Howells | 8bbf4976 | 2008-11-14 10:39:14 +1100 | [diff] [blame] | 1161 | dest_keyring, instkey); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | |
David Howells | 8bbf4976 | 2008-11-14 10:39:14 +1100 | [diff] [blame] | 1163 | key_put(dest_keyring); |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 1164 | |
| 1165 | /* discard the assumed authority if it's just been disabled by |
| 1166 | * instantiation of the key */ |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 1167 | if (ret == 0) |
| 1168 | keyctl_change_reqkey_auth(NULL); |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 1169 | |
| 1170 | error: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | return ret; |
David Howells | a8b17ed | 2011-01-20 16:38:27 +0000 | [diff] [blame] | 1172 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | /* |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 1175 | * Read or set the default keyring in which request_key() will cache keys and |
| 1176 | * return the old setting. |
| 1177 | * |
| 1178 | * If a process keyring is specified then this will be created if it doesn't |
| 1179 | * yet exist. The old setting will be returned if successful. |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 1180 | */ |
| 1181 | long keyctl_set_reqkey_keyring(int reqkey_defl) |
| 1182 | { |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 1183 | struct cred *new; |
| 1184 | int ret, old_setting; |
| 1185 | |
| 1186 | old_setting = current_cred_xxx(jit_keyring); |
| 1187 | |
| 1188 | if (reqkey_defl == KEY_REQKEY_DEFL_NO_CHANGE) |
| 1189 | return old_setting; |
| 1190 | |
| 1191 | new = prepare_creds(); |
| 1192 | if (!new) |
| 1193 | return -ENOMEM; |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 1194 | |
| 1195 | switch (reqkey_defl) { |
| 1196 | case KEY_REQKEY_DEFL_THREAD_KEYRING: |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 1197 | ret = install_thread_keyring_to_cred(new); |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 1198 | if (ret < 0) |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 1199 | goto error; |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 1200 | goto set; |
| 1201 | |
| 1202 | case KEY_REQKEY_DEFL_PROCESS_KEYRING: |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 1203 | ret = install_process_keyring_to_cred(new); |
| 1204 | if (ret < 0) { |
| 1205 | if (ret != -EEXIST) |
| 1206 | goto error; |
| 1207 | ret = 0; |
| 1208 | } |
| 1209 | goto set; |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 1210 | |
| 1211 | case KEY_REQKEY_DEFL_DEFAULT: |
| 1212 | case KEY_REQKEY_DEFL_SESSION_KEYRING: |
| 1213 | case KEY_REQKEY_DEFL_USER_KEYRING: |
| 1214 | case KEY_REQKEY_DEFL_USER_SESSION_KEYRING: |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 1215 | case KEY_REQKEY_DEFL_REQUESTOR_KEYRING: |
| 1216 | goto set; |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 1217 | |
| 1218 | case KEY_REQKEY_DEFL_NO_CHANGE: |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 1219 | case KEY_REQKEY_DEFL_GROUP_KEYRING: |
| 1220 | default: |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 1221 | ret = -EINVAL; |
| 1222 | goto error; |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 1223 | } |
| 1224 | |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 1225 | set: |
| 1226 | new->jit_keyring = reqkey_defl; |
| 1227 | commit_creds(new); |
| 1228 | return old_setting; |
| 1229 | error: |
| 1230 | abort_creds(new); |
Dan Carpenter | 4303ef1 | 2010-06-11 17:30:05 +0100 | [diff] [blame] | 1231 | return ret; |
David Howells | a8b17ed | 2011-01-20 16:38:27 +0000 | [diff] [blame] | 1232 | } |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 1233 | |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 1234 | /* |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 1235 | * Set or clear the timeout on a key. |
| 1236 | * |
| 1237 | * Either the key must grant the caller Setattr permission or else the caller |
| 1238 | * must hold an instantiation authorisation token for the key. |
| 1239 | * |
| 1240 | * The timeout is either 0 to clear the timeout, or a number of seconds from |
| 1241 | * the current time. The key and any links to the key will be automatically |
| 1242 | * garbage collected after the timeout expires. |
| 1243 | * |
| 1244 | * If successful, 0 is returned. |
David Howells | 017679c | 2006-01-08 01:02:43 -0800 | [diff] [blame] | 1245 | */ |
| 1246 | long keyctl_set_timeout(key_serial_t id, unsigned timeout) |
| 1247 | { |
David Howells | 9156235 | 2010-06-11 17:31:05 +0100 | [diff] [blame] | 1248 | struct key *key, *instkey; |
David Howells | 017679c | 2006-01-08 01:02:43 -0800 | [diff] [blame] | 1249 | key_ref_t key_ref; |
David Howells | 017679c | 2006-01-08 01:02:43 -0800 | [diff] [blame] | 1250 | long ret; |
| 1251 | |
David Howells | 5593122 | 2009-09-02 09:13:45 +0100 | [diff] [blame] | 1252 | key_ref = lookup_user_key(id, KEY_LOOKUP_CREATE | KEY_LOOKUP_PARTIAL, |
| 1253 | KEY_SETATTR); |
David Howells | 017679c | 2006-01-08 01:02:43 -0800 | [diff] [blame] | 1254 | if (IS_ERR(key_ref)) { |
David Howells | 9156235 | 2010-06-11 17:31:05 +0100 | [diff] [blame] | 1255 | /* setting the timeout on a key under construction is permitted |
| 1256 | * if we have the authorisation token handy */ |
| 1257 | if (PTR_ERR(key_ref) == -EACCES) { |
| 1258 | instkey = key_get_instantiation_authkey(id); |
| 1259 | if (!IS_ERR(instkey)) { |
| 1260 | key_put(instkey); |
| 1261 | key_ref = lookup_user_key(id, |
| 1262 | KEY_LOOKUP_PARTIAL, |
| 1263 | 0); |
| 1264 | if (!IS_ERR(key_ref)) |
| 1265 | goto okay; |
| 1266 | } |
| 1267 | } |
| 1268 | |
David Howells | 017679c | 2006-01-08 01:02:43 -0800 | [diff] [blame] | 1269 | ret = PTR_ERR(key_ref); |
| 1270 | goto error; |
| 1271 | } |
| 1272 | |
David Howells | 9156235 | 2010-06-11 17:31:05 +0100 | [diff] [blame] | 1273 | okay: |
David Howells | 017679c | 2006-01-08 01:02:43 -0800 | [diff] [blame] | 1274 | key = key_ref_to_ptr(key_ref); |
Bryan Schumaker | 59e6b9c | 2012-02-24 14:14:50 -0500 | [diff] [blame^] | 1275 | key_set_timeout(key, timeout); |
David Howells | 017679c | 2006-01-08 01:02:43 -0800 | [diff] [blame] | 1276 | key_put(key); |
| 1277 | |
| 1278 | ret = 0; |
| 1279 | error: |
| 1280 | return ret; |
David Howells | a8b17ed | 2011-01-20 16:38:27 +0000 | [diff] [blame] | 1281 | } |
David Howells | 017679c | 2006-01-08 01:02:43 -0800 | [diff] [blame] | 1282 | |
David Howells | 017679c | 2006-01-08 01:02:43 -0800 | [diff] [blame] | 1283 | /* |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 1284 | * Assume (or clear) the authority to instantiate the specified key. |
| 1285 | * |
| 1286 | * This sets the authoritative token currently in force for key instantiation. |
| 1287 | * This must be done for a key to be instantiated. It has the effect of making |
| 1288 | * available all the keys from the caller of the request_key() that created a |
| 1289 | * key to request_key() calls made by the caller of this function. |
| 1290 | * |
| 1291 | * The caller must have the instantiation key in their process keyrings with a |
| 1292 | * Search permission grant available to the caller. |
| 1293 | * |
| 1294 | * If the ID given is 0, then the setting will be cleared and 0 returned. |
| 1295 | * |
| 1296 | * If the ID given has a matching an authorisation key, then that key will be |
| 1297 | * set and its ID will be returned. The authorisation key can be read to get |
| 1298 | * the callout information passed to request_key(). |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 1299 | */ |
| 1300 | long keyctl_assume_authority(key_serial_t id) |
| 1301 | { |
| 1302 | struct key *authkey; |
| 1303 | long ret; |
| 1304 | |
| 1305 | /* special key IDs aren't permitted */ |
| 1306 | ret = -EINVAL; |
| 1307 | if (id < 0) |
| 1308 | goto error; |
| 1309 | |
| 1310 | /* we divest ourselves of authority if given an ID of 0 */ |
| 1311 | if (id == 0) { |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 1312 | ret = keyctl_change_reqkey_auth(NULL); |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 1313 | goto error; |
| 1314 | } |
| 1315 | |
| 1316 | /* attempt to assume the authority temporarily granted to us whilst we |
| 1317 | * instantiate the specified key |
| 1318 | * - the authorisation key must be in the current task's keyrings |
| 1319 | * somewhere |
| 1320 | */ |
| 1321 | authkey = key_get_instantiation_authkey(id); |
| 1322 | if (IS_ERR(authkey)) { |
| 1323 | ret = PTR_ERR(authkey); |
| 1324 | goto error; |
| 1325 | } |
| 1326 | |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 1327 | ret = keyctl_change_reqkey_auth(authkey); |
| 1328 | if (ret < 0) |
| 1329 | goto error; |
| 1330 | key_put(authkey); |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 1331 | |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 1332 | ret = authkey->serial; |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 1333 | error: |
| 1334 | return ret; |
David Howells | a8b17ed | 2011-01-20 16:38:27 +0000 | [diff] [blame] | 1335 | } |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 1336 | |
David Howells | 70a5bb7 | 2008-04-29 01:01:26 -0700 | [diff] [blame] | 1337 | /* |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 1338 | * Get a key's the LSM security label. |
| 1339 | * |
| 1340 | * The key must grant the caller View permission for this to work. |
| 1341 | * |
| 1342 | * If there's a buffer, then up to buflen bytes of data will be placed into it. |
| 1343 | * |
| 1344 | * If successful, the amount of information available will be returned, |
| 1345 | * irrespective of how much was copied (including the terminal NUL). |
David Howells | 70a5bb7 | 2008-04-29 01:01:26 -0700 | [diff] [blame] | 1346 | */ |
| 1347 | long keyctl_get_security(key_serial_t keyid, |
| 1348 | char __user *buffer, |
| 1349 | size_t buflen) |
| 1350 | { |
| 1351 | struct key *key, *instkey; |
| 1352 | key_ref_t key_ref; |
| 1353 | char *context; |
| 1354 | long ret; |
| 1355 | |
David Howells | 5593122 | 2009-09-02 09:13:45 +0100 | [diff] [blame] | 1356 | key_ref = lookup_user_key(keyid, KEY_LOOKUP_PARTIAL, KEY_VIEW); |
David Howells | 70a5bb7 | 2008-04-29 01:01:26 -0700 | [diff] [blame] | 1357 | if (IS_ERR(key_ref)) { |
| 1358 | if (PTR_ERR(key_ref) != -EACCES) |
| 1359 | return PTR_ERR(key_ref); |
| 1360 | |
| 1361 | /* viewing a key under construction is also permitted if we |
| 1362 | * have the authorisation token handy */ |
| 1363 | instkey = key_get_instantiation_authkey(keyid); |
| 1364 | if (IS_ERR(instkey)) |
Roel Kluin | fa1cc7b | 2009-12-15 15:05:12 -0800 | [diff] [blame] | 1365 | return PTR_ERR(instkey); |
David Howells | 70a5bb7 | 2008-04-29 01:01:26 -0700 | [diff] [blame] | 1366 | key_put(instkey); |
| 1367 | |
David Howells | 5593122 | 2009-09-02 09:13:45 +0100 | [diff] [blame] | 1368 | key_ref = lookup_user_key(keyid, KEY_LOOKUP_PARTIAL, 0); |
David Howells | 70a5bb7 | 2008-04-29 01:01:26 -0700 | [diff] [blame] | 1369 | if (IS_ERR(key_ref)) |
| 1370 | return PTR_ERR(key_ref); |
| 1371 | } |
| 1372 | |
| 1373 | key = key_ref_to_ptr(key_ref); |
| 1374 | ret = security_key_getsecurity(key, &context); |
| 1375 | if (ret == 0) { |
| 1376 | /* if no information was returned, give userspace an empty |
| 1377 | * string */ |
| 1378 | ret = 1; |
| 1379 | if (buffer && buflen > 0 && |
| 1380 | copy_to_user(buffer, "", 1) != 0) |
| 1381 | ret = -EFAULT; |
| 1382 | } else if (ret > 0) { |
| 1383 | /* return as much data as there's room for */ |
| 1384 | if (buffer && buflen > 0) { |
| 1385 | if (buflen > ret) |
| 1386 | buflen = ret; |
| 1387 | |
| 1388 | if (copy_to_user(buffer, context, buflen) != 0) |
| 1389 | ret = -EFAULT; |
| 1390 | } |
| 1391 | |
| 1392 | kfree(context); |
| 1393 | } |
| 1394 | |
| 1395 | key_ref_put(key_ref); |
| 1396 | return ret; |
| 1397 | } |
| 1398 | |
David Howells | ee18d64 | 2009-09-02 09:14:21 +0100 | [diff] [blame] | 1399 | /* |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 1400 | * Attempt to install the calling process's session keyring on the process's |
| 1401 | * parent process. |
| 1402 | * |
| 1403 | * The keyring must exist and must grant the caller LINK permission, and the |
| 1404 | * parent process must be single-threaded and must have the same effective |
| 1405 | * ownership as this process and mustn't be SUID/SGID. |
| 1406 | * |
| 1407 | * The keyring will be emplaced on the parent when it next resumes userspace. |
| 1408 | * |
| 1409 | * If successful, 0 will be returned. |
David Howells | ee18d64 | 2009-09-02 09:14:21 +0100 | [diff] [blame] | 1410 | */ |
| 1411 | long keyctl_session_to_parent(void) |
| 1412 | { |
Geert Uytterhoeven | a00ae4d | 2009-12-13 20:21:34 +0100 | [diff] [blame] | 1413 | #ifdef TIF_NOTIFY_RESUME |
David Howells | ee18d64 | 2009-09-02 09:14:21 +0100 | [diff] [blame] | 1414 | struct task_struct *me, *parent; |
| 1415 | const struct cred *mycred, *pcred; |
| 1416 | struct cred *cred, *oldcred; |
| 1417 | key_ref_t keyring_r; |
| 1418 | int ret; |
| 1419 | |
| 1420 | keyring_r = lookup_user_key(KEY_SPEC_SESSION_KEYRING, 0, KEY_LINK); |
| 1421 | if (IS_ERR(keyring_r)) |
| 1422 | return PTR_ERR(keyring_r); |
| 1423 | |
| 1424 | /* our parent is going to need a new cred struct, a new tgcred struct |
| 1425 | * and new security data, so we allocate them here to prevent ENOMEM in |
| 1426 | * our parent */ |
| 1427 | ret = -ENOMEM; |
| 1428 | cred = cred_alloc_blank(); |
| 1429 | if (!cred) |
| 1430 | goto error_keyring; |
| 1431 | |
| 1432 | cred->tgcred->session_keyring = key_ref_to_ptr(keyring_r); |
| 1433 | keyring_r = NULL; |
| 1434 | |
| 1435 | me = current; |
David Howells | 9d1ac65 | 2010-09-10 09:59:46 +0100 | [diff] [blame] | 1436 | rcu_read_lock(); |
David Howells | ee18d64 | 2009-09-02 09:14:21 +0100 | [diff] [blame] | 1437 | write_lock_irq(&tasklist_lock); |
| 1438 | |
| 1439 | parent = me->real_parent; |
| 1440 | ret = -EPERM; |
| 1441 | |
| 1442 | /* the parent mustn't be init and mustn't be a kernel thread */ |
| 1443 | if (parent->pid <= 1 || !parent->mm) |
| 1444 | goto not_permitted; |
| 1445 | |
| 1446 | /* the parent must be single threaded */ |
Oleg Nesterov | dd98acf | 2010-05-26 14:43:23 -0700 | [diff] [blame] | 1447 | if (!thread_group_empty(parent)) |
David Howells | ee18d64 | 2009-09-02 09:14:21 +0100 | [diff] [blame] | 1448 | goto not_permitted; |
| 1449 | |
| 1450 | /* the parent and the child must have different session keyrings or |
| 1451 | * there's no point */ |
| 1452 | mycred = current_cred(); |
| 1453 | pcred = __task_cred(parent); |
| 1454 | if (mycred == pcred || |
| 1455 | mycred->tgcred->session_keyring == pcred->tgcred->session_keyring) |
| 1456 | goto already_same; |
| 1457 | |
| 1458 | /* the parent must have the same effective ownership and mustn't be |
| 1459 | * SUID/SGID */ |
Justin P. Mattock | c5b60b5 | 2010-04-21 00:02:11 -0700 | [diff] [blame] | 1460 | if (pcred->uid != mycred->euid || |
David Howells | ee18d64 | 2009-09-02 09:14:21 +0100 | [diff] [blame] | 1461 | pcred->euid != mycred->euid || |
| 1462 | pcred->suid != mycred->euid || |
Justin P. Mattock | c5b60b5 | 2010-04-21 00:02:11 -0700 | [diff] [blame] | 1463 | pcred->gid != mycred->egid || |
David Howells | ee18d64 | 2009-09-02 09:14:21 +0100 | [diff] [blame] | 1464 | pcred->egid != mycred->egid || |
| 1465 | pcred->sgid != mycred->egid) |
| 1466 | goto not_permitted; |
| 1467 | |
| 1468 | /* the keyrings must have the same UID */ |
David Howells | 3d96406 | 2010-09-10 09:59:51 +0100 | [diff] [blame] | 1469 | if ((pcred->tgcred->session_keyring && |
| 1470 | pcred->tgcred->session_keyring->uid != mycred->euid) || |
David Howells | ee18d64 | 2009-09-02 09:14:21 +0100 | [diff] [blame] | 1471 | mycred->tgcred->session_keyring->uid != mycred->euid) |
| 1472 | goto not_permitted; |
| 1473 | |
David Howells | ee18d64 | 2009-09-02 09:14:21 +0100 | [diff] [blame] | 1474 | /* if there's an already pending keyring replacement, then we replace |
| 1475 | * that */ |
| 1476 | oldcred = parent->replacement_session_keyring; |
| 1477 | |
| 1478 | /* the replacement session keyring is applied just prior to userspace |
| 1479 | * restarting */ |
| 1480 | parent->replacement_session_keyring = cred; |
| 1481 | cred = NULL; |
| 1482 | set_ti_thread_flag(task_thread_info(parent), TIF_NOTIFY_RESUME); |
| 1483 | |
| 1484 | write_unlock_irq(&tasklist_lock); |
David Howells | 9d1ac65 | 2010-09-10 09:59:46 +0100 | [diff] [blame] | 1485 | rcu_read_unlock(); |
David Howells | ee18d64 | 2009-09-02 09:14:21 +0100 | [diff] [blame] | 1486 | if (oldcred) |
| 1487 | put_cred(oldcred); |
| 1488 | return 0; |
| 1489 | |
| 1490 | already_same: |
| 1491 | ret = 0; |
| 1492 | not_permitted: |
Marc Dionne | 5c84342 | 2009-09-14 12:46:23 +0100 | [diff] [blame] | 1493 | write_unlock_irq(&tasklist_lock); |
David Howells | 9d1ac65 | 2010-09-10 09:59:46 +0100 | [diff] [blame] | 1494 | rcu_read_unlock(); |
David Howells | ee18d64 | 2009-09-02 09:14:21 +0100 | [diff] [blame] | 1495 | put_cred(cred); |
| 1496 | return ret; |
| 1497 | |
| 1498 | error_keyring: |
| 1499 | key_ref_put(keyring_r); |
| 1500 | return ret; |
Geert Uytterhoeven | a00ae4d | 2009-12-13 20:21:34 +0100 | [diff] [blame] | 1501 | |
| 1502 | #else /* !TIF_NOTIFY_RESUME */ |
| 1503 | /* |
| 1504 | * To be removed when TIF_NOTIFY_RESUME has been implemented on |
| 1505 | * m68k/xtensa |
| 1506 | */ |
| 1507 | #warning TIF_NOTIFY_RESUME not implemented |
| 1508 | return -EOPNOTSUPP; |
| 1509 | #endif /* !TIF_NOTIFY_RESUME */ |
David Howells | ee18d64 | 2009-09-02 09:14:21 +0100 | [diff] [blame] | 1510 | } |
| 1511 | |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 1512 | /* |
David Howells | 973c9f4 | 2011-01-20 16:38:33 +0000 | [diff] [blame] | 1513 | * The key control system call |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1514 | */ |
Heiko Carstens | 938bb9f | 2009-01-14 14:14:30 +0100 | [diff] [blame] | 1515 | SYSCALL_DEFINE5(keyctl, int, option, unsigned long, arg2, unsigned long, arg3, |
| 1516 | unsigned long, arg4, unsigned long, arg5) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1517 | { |
| 1518 | switch (option) { |
| 1519 | case KEYCTL_GET_KEYRING_ID: |
| 1520 | return keyctl_get_keyring_ID((key_serial_t) arg2, |
| 1521 | (int) arg3); |
| 1522 | |
| 1523 | case KEYCTL_JOIN_SESSION_KEYRING: |
| 1524 | return keyctl_join_session_keyring((const char __user *) arg2); |
| 1525 | |
| 1526 | case KEYCTL_UPDATE: |
| 1527 | return keyctl_update_key((key_serial_t) arg2, |
| 1528 | (const void __user *) arg3, |
| 1529 | (size_t) arg4); |
| 1530 | |
| 1531 | case KEYCTL_REVOKE: |
| 1532 | return keyctl_revoke_key((key_serial_t) arg2); |
| 1533 | |
| 1534 | case KEYCTL_DESCRIBE: |
| 1535 | return keyctl_describe_key((key_serial_t) arg2, |
| 1536 | (char __user *) arg3, |
| 1537 | (unsigned) arg4); |
| 1538 | |
| 1539 | case KEYCTL_CLEAR: |
| 1540 | return keyctl_keyring_clear((key_serial_t) arg2); |
| 1541 | |
| 1542 | case KEYCTL_LINK: |
| 1543 | return keyctl_keyring_link((key_serial_t) arg2, |
| 1544 | (key_serial_t) arg3); |
| 1545 | |
| 1546 | case KEYCTL_UNLINK: |
| 1547 | return keyctl_keyring_unlink((key_serial_t) arg2, |
| 1548 | (key_serial_t) arg3); |
| 1549 | |
| 1550 | case KEYCTL_SEARCH: |
| 1551 | return keyctl_keyring_search((key_serial_t) arg2, |
| 1552 | (const char __user *) arg3, |
| 1553 | (const char __user *) arg4, |
| 1554 | (key_serial_t) arg5); |
| 1555 | |
| 1556 | case KEYCTL_READ: |
| 1557 | return keyctl_read_key((key_serial_t) arg2, |
| 1558 | (char __user *) arg3, |
| 1559 | (size_t) arg4); |
| 1560 | |
| 1561 | case KEYCTL_CHOWN: |
| 1562 | return keyctl_chown_key((key_serial_t) arg2, |
| 1563 | (uid_t) arg3, |
| 1564 | (gid_t) arg4); |
| 1565 | |
| 1566 | case KEYCTL_SETPERM: |
| 1567 | return keyctl_setperm_key((key_serial_t) arg2, |
| 1568 | (key_perm_t) arg3); |
| 1569 | |
| 1570 | case KEYCTL_INSTANTIATE: |
| 1571 | return keyctl_instantiate_key((key_serial_t) arg2, |
| 1572 | (const void __user *) arg3, |
| 1573 | (size_t) arg4, |
| 1574 | (key_serial_t) arg5); |
| 1575 | |
| 1576 | case KEYCTL_NEGATE: |
| 1577 | return keyctl_negate_key((key_serial_t) arg2, |
| 1578 | (unsigned) arg3, |
| 1579 | (key_serial_t) arg4); |
| 1580 | |
David Howells | 3e30148 | 2005-06-23 22:00:56 -0700 | [diff] [blame] | 1581 | case KEYCTL_SET_REQKEY_KEYRING: |
| 1582 | return keyctl_set_reqkey_keyring(arg2); |
| 1583 | |
David Howells | 017679c | 2006-01-08 01:02:43 -0800 | [diff] [blame] | 1584 | case KEYCTL_SET_TIMEOUT: |
| 1585 | return keyctl_set_timeout((key_serial_t) arg2, |
| 1586 | (unsigned) arg3); |
| 1587 | |
David Howells | b5f545c | 2006-01-08 01:02:47 -0800 | [diff] [blame] | 1588 | case KEYCTL_ASSUME_AUTHORITY: |
| 1589 | return keyctl_assume_authority((key_serial_t) arg2); |
| 1590 | |
David Howells | 70a5bb7 | 2008-04-29 01:01:26 -0700 | [diff] [blame] | 1591 | case KEYCTL_GET_SECURITY: |
| 1592 | return keyctl_get_security((key_serial_t) arg2, |
James Morris | 90bd49a | 2008-12-29 14:35:35 +1100 | [diff] [blame] | 1593 | (char __user *) arg3, |
David Howells | 70a5bb7 | 2008-04-29 01:01:26 -0700 | [diff] [blame] | 1594 | (size_t) arg4); |
| 1595 | |
David Howells | ee18d64 | 2009-09-02 09:14:21 +0100 | [diff] [blame] | 1596 | case KEYCTL_SESSION_TO_PARENT: |
| 1597 | return keyctl_session_to_parent(); |
| 1598 | |
David Howells | fdd1b94 | 2011-03-07 15:06:09 +0000 | [diff] [blame] | 1599 | case KEYCTL_REJECT: |
| 1600 | return keyctl_reject_key((key_serial_t) arg2, |
| 1601 | (unsigned) arg3, |
| 1602 | (unsigned) arg4, |
| 1603 | (key_serial_t) arg5); |
| 1604 | |
David Howells | ee009e4a0 | 2011-03-07 15:06:20 +0000 | [diff] [blame] | 1605 | case KEYCTL_INSTANTIATE_IOV: |
| 1606 | return keyctl_instantiate_key_iov( |
| 1607 | (key_serial_t) arg2, |
| 1608 | (const struct iovec __user *) arg3, |
| 1609 | (unsigned) arg4, |
| 1610 | (key_serial_t) arg5); |
| 1611 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1612 | default: |
| 1613 | return -EOPNOTSUPP; |
| 1614 | } |
David Howells | a8b17ed | 2011-01-20 16:38:27 +0000 | [diff] [blame] | 1615 | } |