summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2015-10-21 09:04:48 -0400
committerDavid Howells <dhowells@redhat.com>2015-10-21 10:18:36 -0400
commit146aa8b1453bd8f1ff2304ffb71b4ee0eb9acdcc (patch)
treea89ef2cd2e8029b0c09a58739cca0e7e2e68f4db
parent4adc605edc5f744dcf432241b5996ff6a13d868c (diff)
KEYS: Merge the type-specific data with the payload data
Merge the type-specific data with the payload data into one four-word chunk as it seems pointless to keep them separate. Use user_key_payload() for accessing the payloads of overloaded user-defined keys. Signed-off-by: David Howells <dhowells@redhat.com> cc: linux-cifs@vger.kernel.org cc: ecryptfs@vger.kernel.org cc: linux-ext4@vger.kernel.org cc: linux-f2fs-devel@lists.sourceforge.net cc: linux-nfs@vger.kernel.org cc: ceph-devel@vger.kernel.org cc: linux-ima-devel@lists.sourceforge.net
-rw-r--r--Documentation/crypto/asymmetric-keys.txt27
-rw-r--r--Documentation/security/keys.txt41
-rw-r--r--crypto/asymmetric_keys/asymmetric_keys.h5
-rw-r--r--crypto/asymmetric_keys/asymmetric_type.c44
-rw-r--r--crypto/asymmetric_keys/public_key.c4
-rw-r--r--crypto/asymmetric_keys/signature.c2
-rw-r--r--crypto/asymmetric_keys/x509_parser.h1
-rw-r--r--crypto/asymmetric_keys/x509_public_key.c9
-rw-r--r--fs/cifs/cifs_spnego.c6
-rw-r--r--fs/cifs/cifsacl.c25
-rw-r--r--fs/cifs/connect.c9
-rw-r--r--fs/cifs/sess.c2
-rw-r--r--fs/cifs/smb2pdu.c2
-rw-r--r--fs/ecryptfs/ecryptfs_kernel.h5
-rw-r--r--fs/ext4/crypto_key.c4
-rw-r--r--fs/f2fs/crypto_key.c4
-rw-r--r--fs/fscache/object-list.c4
-rw-r--r--fs/nfs/nfs4idmap.c4
-rw-r--r--include/crypto/public_key.h1
-rw-r--r--include/keys/asymmetric-subtype.h2
-rw-r--r--include/keys/asymmetric-type.h15
-rw-r--r--include/keys/user-type.h8
-rw-r--r--include/linux/key-type.h3
-rw-r--r--include/linux/key.h33
-rw-r--r--kernel/module_signing.c1
-rw-r--r--lib/digsig.c7
-rw-r--r--net/ceph/ceph_common.c2
-rw-r--r--net/ceph/crypto.c6
-rw-r--r--net/dns_resolver/dns_key.c20
-rw-r--r--net/dns_resolver/dns_query.c7
-rw-r--r--net/dns_resolver/internal.h8
-rw-r--r--net/rxrpc/af_rxrpc.c2
-rw-r--r--net/rxrpc/ar-key.c32
-rw-r--r--net/rxrpc/ar-output.c2
-rw-r--r--net/rxrpc/ar-security.c4
-rw-r--r--net/rxrpc/rxkad.c16
-rw-r--r--security/integrity/evm/evm_crypto.c2
-rw-r--r--security/keys/big_key.c47
-rw-r--r--security/keys/encrypted-keys/encrypted.c18
-rw-r--r--security/keys/encrypted-keys/encrypted.h4
-rw-r--r--security/keys/encrypted-keys/masterkey_trusted.c4
-rw-r--r--security/keys/key.c18
-rw-r--r--security/keys/keyctl.c4
-rw-r--r--security/keys/keyring.c12
-rw-r--r--security/keys/process_keys.c4
-rw-r--r--security/keys/request_key.c4
-rw-r--r--security/keys/request_key_auth.c12
-rw-r--r--security/keys/trusted.c6
-rw-r--r--security/keys/user_defined.c14
49 files changed, 286 insertions, 230 deletions
diff --git a/Documentation/crypto/asymmetric-keys.txt b/Documentation/crypto/asymmetric-keys.txt
index b7675904a747..8c07e0ea6bc0 100644
--- a/Documentation/crypto/asymmetric-keys.txt
+++ b/Documentation/crypto/asymmetric-keys.txt
@@ -186,7 +186,7 @@ and looks like the following:
186 const struct public_key_signature *sig); 186 const struct public_key_signature *sig);
187 }; 187 };
188 188
189Asymmetric keys point to this with their type_data[0] member. 189Asymmetric keys point to this with their payload[asym_subtype] member.
190 190
191The owner and name fields should be set to the owning module and the name of 191The owner and name fields should be set to the owning module and the name of
192the subtype. Currently, the name is only used for print statements. 192the subtype. Currently, the name is only used for print statements.
@@ -269,8 +269,7 @@ mandatory:
269 269
270 struct key_preparsed_payload { 270 struct key_preparsed_payload {
271 char *description; 271 char *description;
272 void *type_data[2]; 272 void *payload[4];
273 void *payload;
274 const void *data; 273 const void *data;
275 size_t datalen; 274 size_t datalen;
276 size_t quotalen; 275 size_t quotalen;
@@ -283,16 +282,18 @@ mandatory:
283 not theirs. 282 not theirs.
284 283
285 If the parser is happy with the blob, it should propose a description for 284 If the parser is happy with the blob, it should propose a description for
286 the key and attach it to ->description, ->type_data[0] should be set to 285 the key and attach it to ->description, ->payload[asym_subtype] should be
287 point to the subtype to be used, ->payload should be set to point to the 286 set to point to the subtype to be used, ->payload[asym_crypto] should be
288 initialised data for that subtype, ->type_data[1] should point to a hex 287 set to point to the initialised data for that subtype,
289 fingerprint and quotalen should be updated to indicate how much quota this 288 ->payload[asym_key_ids] should point to one or more hex fingerprints and
290 key should account for. 289 quotalen should be updated to indicate how much quota this key should
291 290 account for.
292 When clearing up, the data attached to ->type_data[1] and ->description 291
293 will be kfree()'d and the data attached to ->payload will be passed to the 292 When clearing up, the data attached to ->payload[asym_key_ids] and
294 subtype's ->destroy() method to be disposed of. A module reference for 293 ->description will be kfree()'d and the data attached to
295 the subtype pointed to by ->type_data[0] will be put. 294 ->payload[asm_crypto] will be passed to the subtype's ->destroy() method
295 to be disposed of. A module reference for the subtype pointed to by
296 ->payload[asym_subtype] will be put.
296 297
297 298
298 If the data format is not recognised, -EBADMSG should be returned. If it 299 If the data format is not recognised, -EBADMSG should be returned. If it
diff --git a/Documentation/security/keys.txt b/Documentation/security/keys.txt
index c9e7f4f223a5..8c183873b2b7 100644
--- a/Documentation/security/keys.txt
+++ b/Documentation/security/keys.txt
@@ -1049,12 +1049,12 @@ search a specific keyring, so using keyrings in this way is of limited utility.
1049NOTES ON ACCESSING PAYLOAD CONTENTS 1049NOTES ON ACCESSING PAYLOAD CONTENTS
1050=================================== 1050===================================
1051 1051
1052The simplest payload is just a number in key->payload.value. In this case, 1052The simplest payload is just data stored in key->payload directly. In this
1053there's no need to indulge in RCU or locking when accessing the payload. 1053case, there's no need to indulge in RCU or locking when accessing the payload.
1054 1054
1055More complex payload contents must be allocated and a pointer to them set in 1055More complex payload contents must be allocated and pointers to them set in the
1056key->payload.data. One of the following ways must be selected to access the 1056key->payload.data[] array. One of the following ways must be selected to
1057data: 1057access the data:
1058 1058
1059 (1) Unmodifiable key type. 1059 (1) Unmodifiable key type.
1060 1060
@@ -1092,6 +1092,13 @@ data:
1092 the payload. key->datalen cannot be relied upon to be consistent with the 1092 the payload. key->datalen cannot be relied upon to be consistent with the
1093 payload just dereferenced if the key's semaphore is not held. 1093 payload just dereferenced if the key's semaphore is not held.
1094 1094
1095 Note that key->payload.data[0] has a shadow that is marked for __rcu
1096 usage. This is called key->payload.rcu_data0. The following accessors
1097 wrap the RCU calls to this element:
1098
1099 rcu_assign_keypointer(struct key *key, void *data);
1100 void *rcu_dereference_key(struct key *key);
1101
1095 1102
1096=================== 1103===================
1097DEFINING A KEY TYPE 1104DEFINING A KEY TYPE
@@ -1143,8 +1150,7 @@ The structure has a number of fields, some of which are mandatory:
1143 1150
1144 struct key_preparsed_payload { 1151 struct key_preparsed_payload {
1145 char *description; 1152 char *description;
1146 void *type_data[2]; 1153 union key_payload payload;
1147 void *payload;
1148 const void *data; 1154 const void *data;
1149 size_t datalen; 1155 size_t datalen;
1150 size_t quotalen; 1156 size_t quotalen;
@@ -1160,10 +1166,9 @@ The structure has a number of fields, some of which are mandatory:
1160 attached as a string to the description field. This will be used for the 1166 attached as a string to the description field. This will be used for the
1161 key description if the caller of add_key() passes NULL or "". 1167 key description if the caller of add_key() passes NULL or "".
1162 1168
1163 The method can attach anything it likes to type_data[] and payload. These 1169 The method can attach anything it likes to payload. This is merely passed
1164 are merely passed along to the instantiate() or update() operations. If 1170 along to the instantiate() or update() operations. If set, the expiry
1165 set, the expiry time will be applied to the key if it is instantiated from 1171 time will be applied to the key if it is instantiated from this data.
1166 this data.
1167 1172
1168 The method should return 0 if successful or a negative error code 1173 The method should return 0 if successful or a negative error code
1169 otherwise. 1174 otherwise.
@@ -1172,11 +1177,10 @@ The structure has a number of fields, some of which are mandatory:
1172 (*) void (*free_preparse)(struct key_preparsed_payload *prep); 1177 (*) void (*free_preparse)(struct key_preparsed_payload *prep);
1173 1178
1174 This method is only required if the preparse() method is provided, 1179 This method is only required if the preparse() method is provided,
1175 otherwise it is unused. It cleans up anything attached to the 1180 otherwise it is unused. It cleans up anything attached to the description
1176 description, type_data and payload fields of the key_preparsed_payload 1181 and payload fields of the key_preparsed_payload struct as filled in by the
1177 struct as filled in by the preparse() method. It will always be called 1182 preparse() method. It will always be called after preparse() returns
1178 after preparse() returns successfully, even if instantiate() or update() 1183 successfully, even if instantiate() or update() succeed.
1179 succeed.
1180 1184
1181 1185
1182 (*) int (*instantiate)(struct key *key, struct key_preparsed_payload *prep); 1186 (*) int (*instantiate)(struct key *key, struct key_preparsed_payload *prep);
@@ -1197,6 +1201,11 @@ The structure has a number of fields, some of which are mandatory:
1197 1201
1198 It is safe to sleep in this method. 1202 It is safe to sleep in this method.
1199 1203
1204 generic_key_instantiate() is provided to simply copy the data from
1205 prep->payload.data[] to key->payload.data[], with RCU-safe assignment on
1206 the first element. It will then clear prep->payload.data[] so that the
1207 free_preparse method doesn't release the data.
1208
1200 1209
1201 (*) int (*update)(struct key *key, const void *data, size_t datalen); 1210 (*) int (*update)(struct key *key, const void *data, size_t datalen);
1202 1211
diff --git a/crypto/asymmetric_keys/asymmetric_keys.h b/crypto/asymmetric_keys/asymmetric_keys.h
index 3f5b537ab33e..1d450b580245 100644
--- a/crypto/asymmetric_keys/asymmetric_keys.h
+++ b/crypto/asymmetric_keys/asymmetric_keys.h
@@ -14,8 +14,3 @@ extern struct asymmetric_key_id *asymmetric_key_hex_to_key_id(const char *id);
14extern int __asymmetric_key_hex_to_key_id(const char *id, 14extern int __asymmetric_key_hex_to_key_id(const char *id,
15 struct asymmetric_key_id *match_id, 15 struct asymmetric_key_id *match_id,
16 size_t hexlen); 16 size_t hexlen);
17static inline
18const struct asymmetric_key_ids *asymmetric_key_ids(const struct key *key)
19{
20 return key->type_data.p[1];
21}
diff --git a/crypto/asymmetric_keys/asymmetric_type.c b/crypto/asymmetric_keys/asymmetric_type.c
index 1916680ad81b..9f2165b27d52 100644
--- a/crypto/asymmetric_keys/asymmetric_type.c
+++ b/crypto/asymmetric_keys/asymmetric_type.c
@@ -307,25 +307,34 @@ static int asymmetric_key_preparse(struct key_preparsed_payload *prep)
307} 307}
308 308
309/* 309/*
310 * Clean up the key ID list
311 */
312static void asymmetric_key_free_kids(struct asymmetric_key_ids *kids)
313{
314 int i;
315
316 if (kids) {
317 for (i = 0; i < ARRAY_SIZE(kids->id); i++)
318 kfree(kids->id[i]);
319 kfree(kids);
320 }
321}
322
323/*
310 * Clean up the preparse data 324 * Clean up the preparse data
311 */ 325 */
312static void asymmetric_key_free_preparse(struct key_preparsed_payload *prep) 326static void asymmetric_key_free_preparse(struct key_preparsed_payload *prep)
313{ 327{
314 struct asymmetric_key_subtype *subtype = prep->type_data[0]; 328 struct asymmetric_key_subtype *subtype = prep->payload.data[asym_subtype];
315 struct asymmetric_key_ids *kids = prep->type_data[1]; 329 struct asymmetric_key_ids *kids = prep->payload.data[asym_key_ids];
316 int i;
317 330
318 pr_devel("==>%s()\n", __func__); 331 pr_devel("==>%s()\n", __func__);
319 332
320 if (subtype) { 333 if (subtype) {
321 subtype->destroy(prep->payload[0]); 334 subtype->destroy(prep->payload.data[asym_crypto]);
322 module_put(subtype->owner); 335 module_put(subtype->owner);
323 } 336 }
324 if (kids) { 337 asymmetric_key_free_kids(kids);
325 for (i = 0; i < ARRAY_SIZE(kids->id); i++)
326 kfree(kids->id[i]);
327 kfree(kids);
328 }
329 kfree(prep->description); 338 kfree(prep->description);
330} 339}
331 340
@@ -335,20 +344,19 @@ static void asymmetric_key_free_preparse(struct key_preparsed_payload *prep)
335static void asymmetric_key_destroy(struct key *key) 344static void asymmetric_key_destroy(struct key *key)
336{ 345{
337 struct asymmetric_key_subtype *subtype = asymmetric_key_subtype(key); 346 struct asymmetric_key_subtype *subtype = asymmetric_key_subtype(key);
338 struct asymmetric_key_ids *kids = key->type_data.p[1]; 347 struct asymmetric_key_ids *kids = key->payload.data[asym_key_ids];
348 void *data = key->payload.data[asym_crypto];
349
350 key->payload.data[asym_crypto] = NULL;
351 key->payload.data[asym_subtype] = NULL;
352 key->payload.data[asym_key_ids] = NULL;
339 353
340 if (subtype) { 354 if (subtype) {
341 subtype->destroy(key->payload.data); 355 subtype->destroy(data);
342 module_put(subtype->owner); 356 module_put(subtype->owner);
343 key->type_data.p[0] = NULL;
344 } 357 }
345 358
346 if (kids) { 359 asymmetric_key_free_kids(kids);
347 kfree(kids->id[0]);
348 kfree(kids->id[1]);
349 kfree(kids);
350 key->type_data.p[1] = NULL;
351 }
352} 360}
353 361
354struct key_type key_type_asymmetric = { 362struct key_type key_type_asymmetric = {
diff --git a/crypto/asymmetric_keys/public_key.c b/crypto/asymmetric_keys/public_key.c
index 81efccbe22d5..6db4c01c6503 100644
--- a/crypto/asymmetric_keys/public_key.c
+++ b/crypto/asymmetric_keys/public_key.c
@@ -49,7 +49,7 @@ EXPORT_SYMBOL_GPL(pkey_id_type_name);
49static void public_key_describe(const struct key *asymmetric_key, 49static void public_key_describe(const struct key *asymmetric_key,
50 struct seq_file *m) 50 struct seq_file *m)
51{ 51{
52 struct public_key *key = asymmetric_key->payload.data; 52 struct public_key *key = asymmetric_key->payload.data[asym_crypto];
53 53
54 if (key) 54 if (key)
55 seq_printf(m, "%s.%s", 55 seq_printf(m, "%s.%s",
@@ -112,7 +112,7 @@ EXPORT_SYMBOL_GPL(public_key_verify_signature);
112static int public_key_verify_signature_2(const struct key *key, 112static int public_key_verify_signature_2(const struct key *key,
113 const struct public_key_signature *sig) 113 const struct public_key_signature *sig)
114{ 114{
115 const struct public_key *pk = key->payload.data; 115 const struct public_key *pk = key->payload.data[asym_crypto];
116 return public_key_verify_signature(pk, sig); 116 return public_key_verify_signature(pk, sig);
117} 117}
118 118
diff --git a/crypto/asymmetric_keys/signature.c b/crypto/asymmetric_keys/signature.c
index 7525fd183574..9441240f7d2a 100644
--- a/crypto/asymmetric_keys/signature.c
+++ b/crypto/asymmetric_keys/signature.c
@@ -37,7 +37,7 @@ int verify_signature(const struct key *key,
37 return -EINVAL; 37 return -EINVAL;
38 subtype = asymmetric_key_subtype(key); 38 subtype = asymmetric_key_subtype(key);
39 if (!subtype || 39 if (!subtype ||
40 !key->payload.data) 40 !key->payload.data[0])
41 return -EINVAL; 41 return -EINVAL;
42 if (!subtype->verify_signature) 42 if (!subtype->verify_signature)
43 return -ENOTSUPP; 43 return -ENOTSUPP;
diff --git a/crypto/asymmetric_keys/x509_parser.h b/crypto/asymmetric_keys/x509_parser.h
index 1de01eaec884..dbeed6018e63 100644
--- a/crypto/asymmetric_keys/x509_parser.h
+++ b/crypto/asymmetric_keys/x509_parser.h
@@ -11,6 +11,7 @@
11 11
12#include <linux/time.h> 12#include <linux/time.h>
13#include <crypto/public_key.h> 13#include <crypto/public_key.h>
14#include <keys/asymmetric-type.h>
14 15
15struct x509_certificate { 16struct x509_certificate {
16 struct x509_certificate *next; 17 struct x509_certificate *next;
diff --git a/crypto/asymmetric_keys/x509_public_key.c b/crypto/asymmetric_keys/x509_public_key.c
index 197096632412..64d42981a8d7 100644
--- a/crypto/asymmetric_keys/x509_public_key.c
+++ b/crypto/asymmetric_keys/x509_public_key.c
@@ -266,7 +266,8 @@ static int x509_validate_trust(struct x509_certificate *cert,
266 if (!IS_ERR(key)) { 266 if (!IS_ERR(key)) {
267 if (!use_builtin_keys 267 if (!use_builtin_keys
268 || test_bit(KEY_FLAG_BUILTIN, &key->flags)) 268 || test_bit(KEY_FLAG_BUILTIN, &key->flags))
269 ret = x509_check_signature(key->payload.data, cert); 269 ret = x509_check_signature(key->payload.data[asym_crypto],
270 cert);
270 key_put(key); 271 key_put(key);
271 } 272 }
272 return ret; 273 return ret;
@@ -352,9 +353,9 @@ static int x509_key_preparse(struct key_preparsed_payload *prep)
352 353
353 /* We're pinning the module by being linked against it */ 354 /* We're pinning the module by being linked against it */
354 __module_get(public_key_subtype.owner); 355 __module_get(public_key_subtype.owner);
355 prep->type_data[0] = &public_key_subtype; 356 prep->payload.data[asym_subtype] = &public_key_subtype;
356 prep->type_data[1] = kids; 357 prep->payload.data[asym_key_ids] = kids;
357 prep->payload[0] = cert->pub; 358 prep->payload.data[asym_crypto] = cert->pub;
358 prep->description = desc; 359 prep->description = desc;
359 prep->quotalen = 100; 360 prep->quotalen = 100;
360 361
diff --git a/fs/cifs/cifs_spnego.c b/fs/cifs/cifs_spnego.c
index f4cf200b3c76..6908080e9b6d 100644
--- a/fs/cifs/cifs_spnego.c
+++ b/fs/cifs/cifs_spnego.c
@@ -42,7 +42,7 @@ cifs_spnego_key_instantiate(struct key *key, struct key_preparsed_payload *prep)
42 goto error; 42 goto error;
43 43
44 /* attach the data */ 44 /* attach the data */
45 key->payload.data = payload; 45 key->payload.data[0] = payload;
46 ret = 0; 46 ret = 0;
47 47
48error: 48error:
@@ -52,7 +52,7 @@ error:
52static void 52static void
53cifs_spnego_key_destroy(struct key *key) 53cifs_spnego_key_destroy(struct key *key)
54{ 54{
55 kfree(key->payload.data); 55 kfree(key->payload.data[0]);
56} 56}
57 57
58 58
@@ -167,7 +167,7 @@ cifs_get_spnego_key(struct cifs_ses *sesInfo)
167 167
168#ifdef CONFIG_CIFS_DEBUG2 168#ifdef CONFIG_CIFS_DEBUG2
169 if (cifsFYI && !IS_ERR(spnego_key)) { 169 if (cifsFYI && !IS_ERR(spnego_key)) {
170 struct cifs_spnego_msg *msg = spnego_key->payload.data; 170 struct cifs_spnego_msg *msg = spnego_key->payload.data[0];
171 cifs_dump_mem("SPNEGO reply blob:", msg->data, min(1024U, 171 cifs_dump_mem("SPNEGO reply blob:", msg->data, min(1024U,
172 msg->secblob_len + msg->sesskey_len)); 172 msg->secblob_len + msg->sesskey_len));
173 } 173 }
diff --git a/fs/cifs/cifsacl.c b/fs/cifs/cifsacl.c
index 1ea780bc6376..3f93125916bf 100644
--- a/fs/cifs/cifsacl.c
+++ b/fs/cifs/cifsacl.c
@@ -58,16 +58,15 @@ cifs_idmap_key_instantiate(struct key *key, struct key_preparsed_payload *prep)
58 * dereference payload.data! 58 * dereference payload.data!
59 */ 59 */
60 if (prep->datalen <= sizeof(key->payload)) { 60 if (prep->datalen <= sizeof(key->payload)) {
61 key->payload.value = 0; 61 key->payload.data[0] = NULL;
62 memcpy(&key->payload.value, prep->data, prep->datalen); 62 memcpy(&key->payload, prep->data, prep->datalen);
63 key->datalen = prep->datalen; 63 } else {
64 return 0; 64 payload = kmemdup(prep->data, prep->datalen, GFP_KERNEL);
65 if (!payload)
66 return -ENOMEM;
67 key->payload.data[0] = payload;
65 } 68 }
66 payload = kmemdup(prep->data, prep->datalen, GFP_KERNEL);
67 if (!payload)
68 return -ENOMEM;
69 69
70 key->payload.data = payload;
71 key->datalen = prep->datalen; 70 key->datalen = prep->datalen;
72 return 0; 71 return 0;
73} 72}
@@ -76,7 +75,7 @@ static inline void
76cifs_idmap_key_destroy(struct key *key) 75cifs_idmap_key_destroy(struct key *key)
77{ 76{
78 if (key->datalen > sizeof(key->payload)) 77 if (key->datalen > sizeof(key->payload))
79 kfree(key->payload.data); 78 kfree(key->payload.data[0]);
80} 79}
81 80
82static struct key_type cifs_idmap_key_type = { 81static struct key_type cifs_idmap_key_type = {
@@ -233,8 +232,8 @@ id_to_sid(unsigned int cid, uint sidtype, struct cifs_sid *ssid)
233 * it could be. 232 * it could be.
234 */ 233 */
235 ksid = sidkey->datalen <= sizeof(sidkey->payload) ? 234 ksid = sidkey->datalen <= sizeof(sidkey->payload) ?
236 (struct cifs_sid *)&sidkey->payload.value : 235 (struct cifs_sid *)&sidkey->payload :
237 (struct cifs_sid *)sidkey->payload.data; 236 (struct cifs_sid *)sidkey->payload.data[0];
238 237
239 ksid_size = CIFS_SID_BASE_SIZE + (ksid->num_subauth * sizeof(__le32)); 238 ksid_size = CIFS_SID_BASE_SIZE + (ksid->num_subauth * sizeof(__le32));
240 if (ksid_size > sidkey->datalen) { 239 if (ksid_size > sidkey->datalen) {
@@ -307,14 +306,14 @@ sid_to_id(struct cifs_sb_info *cifs_sb, struct cifs_sid *psid,
307 if (sidtype == SIDOWNER) { 306 if (sidtype == SIDOWNER) {
308 kuid_t uid; 307 kuid_t uid;
309 uid_t id; 308 uid_t id;
310 memcpy(&id, &sidkey->payload.value, sizeof(uid_t)); 309 memcpy(&id, &sidkey->payload.data[0], sizeof(uid_t));
311 uid = make_kuid(&init_user_ns, id); 310 uid = make_kuid(&init_user_ns, id);
312 if (uid_valid(uid)) 311 if (uid_valid(uid))
313 fuid = uid; 312 fuid = uid;
314 } else { 313 } else {
315 kgid_t gid; 314 kgid_t gid;
316 gid_t id; 315 gid_t id;
317 memcpy(&id, &sidkey->payload.value, sizeof(gid_t)); 316 memcpy(&id, &sidkey->payload.data[0], sizeof(gid_t));
318 gid = make_kgid(&init_user_ns, id); 317 gid = make_kgid(&init_user_ns, id);
319 if (gid_valid(gid)) 318 if (gid_valid(gid))
320 fgid = gid; 319 fgid = gid;
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index 773f4dc77630..3f2228570d44 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -2325,13 +2325,14 @@ static int
2325cifs_set_cifscreds(struct smb_vol *vol, struct cifs_ses *ses) 2325cifs_set_cifscreds(struct smb_vol *vol, struct cifs_ses *ses)
2326{ 2326{
2327 int rc = 0; 2327 int rc = 0;
2328 char *desc, *delim, *payload; 2328 const char *delim, *payload;
2329 char *desc;
2329 ssize_t len; 2330 ssize_t len;
2330 struct key *key; 2331 struct key *key;
2331 struct TCP_Server_Info *server = ses->server; 2332 struct TCP_Server_Info *server = ses->server;
2332 struct sockaddr_in *sa; 2333 struct sockaddr_in *sa;
2333 struct sockaddr_in6 *sa6; 2334 struct sockaddr_in6 *sa6;
2334 struct user_key_payload *upayload; 2335 const struct user_key_payload *upayload;
2335 2336
2336 desc = kmalloc(CIFSCREDS_DESC_SIZE, GFP_KERNEL); 2337 desc = kmalloc(CIFSCREDS_DESC_SIZE, GFP_KERNEL);
2337 if (!desc) 2338 if (!desc)
@@ -2374,14 +2375,14 @@ cifs_set_cifscreds(struct smb_vol *vol, struct cifs_ses *ses)
2374 } 2375 }
2375 2376
2376 down_read(&key->sem); 2377 down_read(&key->sem);
2377 upayload = key->payload.data; 2378 upayload = user_key_payload(key);
2378 if (IS_ERR_OR_NULL(upayload)) { 2379 if (IS_ERR_OR_NULL(upayload)) {
2379 rc = upayload ? PTR_ERR(upayload) : -EINVAL; 2380 rc = upayload ? PTR_ERR(upayload) : -EINVAL;
2380 goto out_key_put; 2381 goto out_key_put;
2381 } 2382 }
2382 2383
2383 /* find first : in payload */ 2384 /* find first : in payload */
2384 payload = (char *)upayload->data; 2385 payload = upayload->data;
2385 delim = strnchr(payload, upayload->datalen, ':'); 2386 delim = strnchr(payload, upayload->datalen, ':');
2386 cifs_dbg(FYI, "payload=%s\n", payload); 2387 cifs_dbg(FYI, "payload=%s\n", payload);
2387 if (!delim) { 2388 if (!delim) {
diff --git a/fs/cifs/sess.c b/fs/cifs/sess.c
index bce6fdcd5d48..59727e32ed0f 100644
--- a/fs/cifs/sess.c
+++ b/fs/cifs/sess.c
@@ -988,7 +988,7 @@ sess_auth_kerberos(struct sess_data *sess_data)
988 goto out; 988 goto out;
989 } 989 }
990 990
991 msg = spnego_key->payload.data; 991 msg = spnego_key->payload.data[0];
992 /* 992 /*
993 * check version field to make sure that cifs.upcall is 993 * check version field to make sure that cifs.upcall is
994 * sending us a response in an expected form 994 * sending us a response in an expected form
diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
index ce83e2edbe0a..52d14c9cf052 100644
--- a/fs/cifs/smb2pdu.c
+++ b/fs/cifs/smb2pdu.c
@@ -660,7 +660,7 @@ ssetup_ntlmssp_authenticate:
660 goto ssetup_exit; 660 goto ssetup_exit;
661 } 661 }
662 662
663 msg = spnego_key->payload.data; 663 msg = spnego_key->payload.data[0];
664 /* 664 /*
665 * check version field to make sure that cifs.upcall is 665 * check version field to make sure that cifs.upcall is
666 * sending us a response in an expected form 666 * sending us a response in an expected form
diff --git a/fs/ecryptfs/ecryptfs_kernel.h b/fs/ecryptfs/ecryptfs_kernel.h
index 5ba029e627cc..7b39260c7bba 100644
--- a/fs/ecryptfs/ecryptfs_kernel.h
+++ b/fs/ecryptfs/ecryptfs_kernel.h
@@ -86,7 +86,7 @@ ecryptfs_get_encrypted_key_payload_data(struct key *key)
86{ 86{
87 if (key->type == &key_type_encrypted) 87 if (key->type == &key_type_encrypted)
88 return (struct ecryptfs_auth_tok *) 88 return (struct ecryptfs_auth_tok *)
89 (&((struct encrypted_key_payload *)key->payload.data)->payload_data); 89 (&((struct encrypted_key_payload *)key->payload.data[0])->payload_data);
90 else 90 else
91 return NULL; 91 return NULL;
92} 92}
@@ -117,8 +117,7 @@ ecryptfs_get_key_payload_data(struct key *key)
117 117
118 auth_tok = ecryptfs_get_encrypted_key_payload_data(key); 118 auth_tok = ecryptfs_get_encrypted_key_payload_data(key);
119 if (!auth_tok) 119 if (!auth_tok)
120 return (struct ecryptfs_auth_tok *) 120 return (struct ecryptfs_auth_tok *)user_key_payload(key)->data;
121 (((struct user_key_payload *)key->payload.data)->data);
122 else 121 else
123 return auth_tok; 122 return auth_tok;
124} 123}
diff --git a/fs/ext4/crypto_key.c b/fs/ext4/crypto_key.c
index 1d510c11b100..5c52c79dea46 100644
--- a/fs/ext4/crypto_key.c
+++ b/fs/ext4/crypto_key.c
@@ -121,7 +121,7 @@ int _ext4_get_encryption_info(struct inode *inode)
121 struct key *keyring_key = NULL; 121 struct key *keyring_key = NULL;
122 struct ext4_encryption_key *master_key; 122 struct ext4_encryption_key *master_key;
123 struct ext4_encryption_context ctx; 123 struct ext4_encryption_context ctx;
124 struct user_key_payload *ukp; 124 const struct user_key_payload *ukp;
125 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); 125 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
126 struct crypto_ablkcipher *ctfm; 126 struct crypto_ablkcipher *ctfm;
127 const char *cipher_str; 127 const char *cipher_str;
@@ -209,7 +209,7 @@ retry:
209 } 209 }
210 crypt_info->ci_keyring_key = keyring_key; 210 crypt_info->ci_keyring_key = keyring_key;
211 BUG_ON(keyring_key->type != &key_type_logon); 211 BUG_ON(keyring_key->type != &key_type_logon);
212 ukp = ((struct user_key_payload *)keyring_key->payload.data); 212 ukp = user_key_payload(keyring_key);
213 if (ukp->datalen != sizeof(struct ext4_encryption_key)) { 213 if (ukp->datalen != sizeof(struct ext4_encryption_key)) {
214 res = -EINVAL; 214 res = -EINVAL;
215 goto out; 215 goto out;
diff --git a/fs/f2fs/crypto_key.c b/fs/f2fs/crypto_key.c
index 9f77de2ef317..5de2d866a25c 100644
--- a/fs/f2fs/crypto_key.c
+++ b/fs/f2fs/crypto_key.c
@@ -122,7 +122,7 @@ int _f2fs_get_encryption_info(struct inode *inode)
122 struct key *keyring_key = NULL; 122 struct key *keyring_key = NULL;
123 struct f2fs_encryption_key *master_key; 123 struct f2fs_encryption_key *master_key;
124 struct f2fs_encryption_context ctx; 124 struct f2fs_encryption_context ctx;
125 struct user_key_payload *ukp; 125 const struct user_key_payload *ukp;
126 struct crypto_ablkcipher *ctfm; 126 struct crypto_ablkcipher *ctfm;
127 const char *cipher_str; 127 const char *cipher_str;
128 char raw_key[F2FS_MAX_KEY_SIZE]; 128 char raw_key[F2FS_MAX_KEY_SIZE];
@@ -199,7 +199,7 @@ retry:
199 } 199 }
200 crypt_info->ci_keyring_key = keyring_key; 200 crypt_info->ci_keyring_key = keyring_key;
201 BUG_ON(keyring_key->type != &key_type_logon); 201 BUG_ON(keyring_key->type != &key_type_logon);
202 ukp = ((struct user_key_payload *)keyring_key->payload.data); 202 ukp = user_key_payload(keyring_key);
203 if (ukp->datalen != sizeof(struct f2fs_encryption_key)) { 203 if (ukp->datalen != sizeof(struct f2fs_encryption_key)) {
204 res = -EINVAL; 204 res = -EINVAL;
205 goto out; 205 goto out;
diff --git a/fs/fscache/object-list.c b/fs/fscache/object-list.c
index 51dde817e1f2..6b028b7c4250 100644
--- a/fs/fscache/object-list.c
+++ b/fs/fscache/object-list.c
@@ -316,7 +316,7 @@ static const struct seq_operations fscache_objlist_ops = {
316static void fscache_objlist_config(struct fscache_objlist_data *data) 316static void fscache_objlist_config(struct fscache_objlist_data *data)
317{ 317{
318#ifdef CONFIG_KEYS 318#ifdef CONFIG_KEYS
319 struct user_key_payload *confkey; 319 const struct user_key_payload *confkey;
320 unsigned long config; 320 unsigned long config;
321 struct key *key; 321 struct key *key;
322 const char *buf; 322 const char *buf;
@@ -329,7 +329,7 @@ static void fscache_objlist_config(struct fscache_objlist_data *data)
329 config = 0; 329 config = 0;
330 rcu_read_lock(); 330 rcu_read_lock();
331 331
332 confkey = key->payload.data; 332 confkey = user_key_payload(key);
333 buf = confkey->data; 333 buf = confkey->data;
334 334
335 for (len = confkey->datalen - 1; len >= 0; len--) { 335 for (len = confkey->datalen - 1; len >= 0; len--) {
diff --git a/fs/nfs/nfs4idmap.c b/fs/nfs/nfs4idmap.c
index 2e4902203c35..5ba22c6b0ffa 100644
--- a/fs/nfs/nfs4idmap.c
+++ b/fs/nfs/nfs4idmap.c
@@ -297,7 +297,7 @@ static ssize_t nfs_idmap_get_key(const char *name, size_t namelen,
297{ 297{
298 const struct cred *saved_cred; 298 const struct cred *saved_cred;
299 struct key *rkey; 299 struct key *rkey;
300 struct user_key_payload *payload; 300 const struct user_key_payload *payload;
301 ssize_t ret; 301 ssize_t ret;
302 302
303 saved_cred = override_creds(id_resolver_cache); 303 saved_cred = override_creds(id_resolver_cache);
@@ -316,7 +316,7 @@ static ssize_t nfs_idmap_get_key(const char *name, size_t namelen,
316 if (ret < 0) 316 if (ret < 0)
317 goto out_up; 317 goto out_up;
318 318
319 payload = rcu_dereference(rkey->payload.rcudata); 319 payload = user_key_payload(rkey);
320 if (IS_ERR_OR_NULL(payload)) { 320 if (IS_ERR_OR_NULL(payload)) {
321 ret = PTR_ERR(payload); 321 ret = PTR_ERR(payload);
322 goto out_up; 322 goto out_up;
diff --git a/include/crypto/public_key.h b/include/crypto/public_key.h
index 067c242b1e15..cc2516df0efa 100644
--- a/include/crypto/public_key.h
+++ b/include/crypto/public_key.h
@@ -15,7 +15,6 @@
15#define _LINUX_PUBLIC_KEY_H 15#define _LINUX_PUBLIC_KEY_H
16 16
17#include <linux/mpi.h> 17#include <linux/mpi.h>
18#include <keys/asymmetric-type.h>
19#include <crypto/hash_info.h> 18#include <crypto/hash_info.h>
20 19
21enum pkey_algo { 20enum pkey_algo {
diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
index 4b840e822209..4915d40d3c3c 100644
--- a/include/keys/asymmetric-subtype.h
+++ b/include/keys/asymmetric-subtype.h
@@ -49,7 +49,7 @@ struct asymmetric_key_subtype {
49static inline 49static inline
50struct asymmetric_key_subtype *asymmetric_key_subtype(const struct key *key) 50struct asymmetric_key_subtype *asymmetric_key_subtype(const struct key *key)
51{ 51{
52 return key->type_data.p[0]; 52 return key->payload.data[asym_subtype];
53} 53}
54 54
55#endif /* _KEYS_ASYMMETRIC_SUBTYPE_H */ 55#endif /* _KEYS_ASYMMETRIC_SUBTYPE_H */
diff --git a/include/keys/asymmetric-type.h b/include/keys/asymmetric-type.h
index c0754abb2f56..59c1df9cf922 100644
--- a/include/keys/asymmetric-type.h
+++ b/include/keys/asymmetric-type.h
@@ -19,6 +19,16 @@
19extern struct key_type key_type_asymmetric; 19extern struct key_type key_type_asymmetric;
20 20
21/* 21/*
22 * The key payload is four words. The asymmetric-type key uses them as
23 * follows:
24 */
25enum asymmetric_payload_bits {
26 asym_crypto,
27 asym_subtype,
28 asym_key_ids,
29};
30
31/*
22 * Identifiers for an asymmetric key ID. We have three ways of looking up a 32 * Identifiers for an asymmetric key ID. We have three ways of looking up a
23 * key derived from an X.509 certificate: 33 * key derived from an X.509 certificate:
24 * 34 *
@@ -58,6 +68,11 @@ extern struct asymmetric_key_id *asymmetric_key_generate_id(const void *val_1,
58 size_t len_1, 68 size_t len_1,
59 const void *val_2, 69 const void *val_2,
60 size_t len_2); 70 size_t len_2);
71static inline
72const struct asymmetric_key_ids *asymmetric_key_ids(const struct key *key)
73{
74 return key->payload.data[asym_key_ids];
75}
61 76
62/* 77/*
63 * The payload is at the discretion of the subtype. 78 * The payload is at the discretion of the subtype.
diff --git a/include/keys/user-type.h b/include/keys/user-type.h
index cebefb069c44..c56fef40f53e 100644
--- a/include/keys/user-type.h
+++ b/include/keys/user-type.h
@@ -15,6 +15,8 @@
15#include <linux/key.h> 15#include <linux/key.h>
16#include <linux/rcupdate.h> 16#include <linux/rcupdate.h>
17 17
18#ifdef CONFIG_KEYS
19
18/*****************************************************************************/ 20/*****************************************************************************/
19/* 21/*
20 * the payload for a key of type "user" or "logon" 22 * the payload for a key of type "user" or "logon"
@@ -46,5 +48,11 @@ extern void user_describe(const struct key *user, struct seq_file *m);
46extern long user_read(const struct key *key, 48extern long user_read(const struct key *key,
47 char __user *buffer, size_t buflen); 49 char __user *buffer, size_t buflen);
48 50
51static inline const struct user_key_payload *user_key_payload(const struct key *key)
52{
53 return (struct user_key_payload *)rcu_dereference_key(key);
54}
55
56#endif /* CONFIG_KEYS */
49 57
50#endif /* _KEYS_USER_TYPE_H */ 58#endif /* _KEYS_USER_TYPE_H */
diff --git a/include/linux/key-type.h b/include/linux/key-type.h
index ff9f1d394235..7463355a198b 100644
--- a/include/linux/key-type.h
+++ b/include/linux/key-type.h
@@ -40,8 +40,7 @@ struct key_construction {
40 */ 40 */
41struct key_preparsed_payload { 41struct key_preparsed_payload {
42 char *description; /* Proposed key description (or NULL) */ 42 char *description; /* Proposed key description (or NULL) */
43 void *type_data[2]; /* Private key-type data */ 43 union key_payload payload; /* Proposed payload */
44 void *payload[2]; /* Proposed payload */
45 const void *data; /* Raw data */ 44 const void *data; /* Raw data */
46 size_t datalen; /* Raw datalen */ 45 size_t datalen; /* Raw datalen */
47 size_t quotalen; /* Quota length for proposed payload */ 46 size_t quotalen; /* Quota length for proposed payload */
diff --git a/include/linux/key.h b/include/linux/key.h
index e1d4715f3222..66f705243985 100644
--- a/include/linux/key.h
+++ b/include/linux/key.h
@@ -89,6 +89,11 @@ struct keyring_index_key {
89 size_t desc_len; 89 size_t desc_len;
90}; 90};
91 91
92union key_payload {
93 void __rcu *rcu_data0;
94 void *data[4];
95};
96
92/*****************************************************************************/ 97/*****************************************************************************/
93/* 98/*
94 * key reference with possession attribute handling 99 * key reference with possession attribute handling
@@ -186,28 +191,18 @@ struct key {
186 }; 191 };
187 }; 192 };
188 193
189 /* type specific data
190 * - this is used by the keyring type to index the name
191 */
192 union {
193 struct list_head link;
194 unsigned long x[2];
195 void *p[2];
196 int reject_error;
197 } type_data;
198
199 /* key data 194 /* key data
200 * - this is used to hold the data actually used in cryptography or 195 * - this is used to hold the data actually used in cryptography or
201 * whatever 196 * whatever
202 */ 197 */
203 union { 198 union {
204 union { 199 union key_payload payload;
205 unsigned long value; 200 struct {
206 void __rcu *rcudata; 201 /* Keyring bits */
207 void *data; 202 struct list_head name_link;
208 void *data2[2]; 203 struct assoc_array keys;
209 } payload; 204 };
210 struct assoc_array keys; 205 int reject_error;
211 }; 206 };
212}; 207};
213 208
@@ -336,12 +331,12 @@ static inline bool key_is_instantiated(const struct key *key)
336} 331}
337 332
338#define rcu_dereference_key(KEY) \ 333#define rcu_dereference_key(KEY) \
339 (rcu_dereference_protected((KEY)->payload.rcudata, \ 334 (rcu_dereference_protected((KEY)->payload.rcu_data0, \
340 rwsem_is_locked(&((struct key *)(KEY))->sem))) 335 rwsem_is_locked(&((struct key *)(KEY))->sem)))
341 336
342#define rcu_assign_keypointer(KEY, PAYLOAD) \ 337#define rcu_assign_keypointer(KEY, PAYLOAD) \
343do { \ 338do { \
344 rcu_assign_pointer((KEY)->payload.rcudata, (PAYLOAD)); \ 339 rcu_assign_pointer((KEY)->payload.rcu_data0, (PAYLOAD)); \
345} while (0) 340} while (0)
346 341
347#ifdef CONFIG_SYSCTL 342#ifdef CONFIG_SYSCTL
diff --git a/kernel/module_signing.c b/kernel/module_signing.c
index bd62f5cda746..6528a79d998d 100644
--- a/kernel/module_signing.c
+++ b/kernel/module_signing.c
@@ -10,6 +10,7 @@
10 */ 10 */
11 11
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/errno.h>
13#include <keys/system_keyring.h> 14#include <keys/system_keyring.h>
14#include <crypto/public_key.h> 15#include <crypto/public_key.h>
15#include "module-internal.h" 16#include "module-internal.h"
diff --git a/lib/digsig.c b/lib/digsig.c
index ae05ea393fc8..07be6c1ef4e2 100644
--- a/lib/digsig.c
+++ b/lib/digsig.c
@@ -79,12 +79,13 @@ static int digsig_verify_rsa(struct key *key,
79 unsigned char *out1 = NULL; 79 unsigned char *out1 = NULL;
80 const char *m; 80 const char *m;
81 MPI in = NULL, res = NULL, pkey[2]; 81 MPI in = NULL, res = NULL, pkey[2];
82 uint8_t *p, *datap, *endp; 82 uint8_t *p, *datap;
83 struct user_key_payload *ukp; 83 const uint8_t *endp;
84 const struct user_key_payload *ukp;
84 struct pubkey_hdr *pkh; 85 struct pubkey_hdr *pkh;
85 86
86 down_read(&key->sem); 87 down_read(&key->sem);
87 ukp = key->payload.data; 88 ukp = user_key_payload(key);
88 89
89 if (ukp->datalen < sizeof(*pkh)) 90 if (ukp->datalen < sizeof(*pkh))
90 goto err1; 91 goto err1;
diff --git a/net/ceph/ceph_common.c b/net/ceph/ceph_common.c
index 54a00d66509e..78f098a20796 100644
--- a/net/ceph/ceph_common.c
+++ b/net/ceph/ceph_common.c
@@ -318,7 +318,7 @@ static int get_secret(struct ceph_crypto_key *dst, const char *name) {
318 goto out; 318 goto out;
319 } 319 }
320 320
321 ckey = ukey->payload.data; 321 ckey = ukey->payload.data[0];
322 err = ceph_crypto_key_clone(dst, ckey); 322 err = ceph_crypto_key_clone(dst, ckey);
323 if (err) 323 if (err)
324 goto out_key; 324 goto out_key;
diff --git a/net/ceph/crypto.c b/net/ceph/crypto.c
index 4440edcce0d6..42e8649c6e79 100644
--- a/net/ceph/crypto.c
+++ b/net/ceph/crypto.c
@@ -537,7 +537,7 @@ static int ceph_key_preparse(struct key_preparsed_payload *prep)
537 if (ret < 0) 537 if (ret < 0)
538 goto err_ckey; 538 goto err_ckey;
539 539
540 prep->payload[0] = ckey; 540 prep->payload.data[0] = ckey;
541 prep->quotalen = datalen; 541 prep->quotalen = datalen;
542 return 0; 542 return 0;
543 543
@@ -549,14 +549,14 @@ err:
549 549
550static void ceph_key_free_preparse(struct key_preparsed_payload *prep) 550static void ceph_key_free_preparse(struct key_preparsed_payload *prep)
551{ 551{
552 struct ceph_crypto_key *ckey = prep->payload[0]; 552 struct ceph_crypto_key *ckey = prep->payload.data[0];
553 ceph_crypto_key_destroy(ckey); 553 ceph_crypto_key_destroy(ckey);
554 kfree(ckey); 554 kfree(ckey);
555} 555}
556 556
557static void ceph_key_destroy(struct key *key) 557static void ceph_key_destroy(struct key *key)
558{ 558{
559 struct ceph_crypto_key *ckey = key->payload.data; 559 struct ceph_crypto_key *ckey = key->payload.data[0];
560 560
561 ceph_crypto_key_destroy(ckey); 561 ceph_crypto_key_destroy(ckey);
562 kfree(ckey); 562 kfree(ckey);
diff --git a/net/dns_resolver/dns_key.c b/net/dns_resolver/dns_key.c
index 31cd4fd75486..c79b85eb4d4c 100644
--- a/net/dns_resolver/dns_key.c
+++ b/net/dns_resolver/dns_key.c
@@ -122,7 +122,7 @@ dns_resolver_preparse(struct key_preparsed_payload *prep)
122 goto bad_option_value; 122 goto bad_option_value;
123 123
124 kdebug("dns error no. = %lu", derrno); 124 kdebug("dns error no. = %lu", derrno);
125 prep->type_data[0] = ERR_PTR(-derrno); 125 prep->payload.data[dns_key_error] = ERR_PTR(-derrno);
126 continue; 126 continue;
127 } 127 }
128 128
@@ -137,8 +137,8 @@ dns_resolver_preparse(struct key_preparsed_payload *prep)
137 137
138 /* don't cache the result if we're caching an error saying there's no 138 /* don't cache the result if we're caching an error saying there's no
139 * result */ 139 * result */
140 if (prep->type_data[0]) { 140 if (prep->payload.data[dns_key_error]) {
141 kleave(" = 0 [h_error %ld]", PTR_ERR(prep->type_data[0])); 141 kleave(" = 0 [h_error %ld]", PTR_ERR(prep->payload.data[dns_key_error]));
142 return 0; 142 return 0;
143 } 143 }
144 144
@@ -155,7 +155,7 @@ dns_resolver_preparse(struct key_preparsed_payload *prep)
155 memcpy(upayload->data, data, result_len); 155 memcpy(upayload->data, data, result_len);
156 upayload->data[result_len] = '\0'; 156 upayload->data[result_len] = '\0';
157 157
158 prep->payload[0] = upayload; 158 prep->payload.data[dns_key_data] = upayload;
159 kleave(" = 0"); 159 kleave(" = 0");
160 return 0; 160 return 0;
161} 161}
@@ -167,7 +167,7 @@ static void dns_resolver_free_preparse(struct key_preparsed_payload *prep)
167{ 167{
168 pr_devel("==>%s()\n", __func__); 168 pr_devel("==>%s()\n", __func__);
169 169
170 kfree(prep->payload[0]); 170 kfree(prep->payload.data[dns_key_data]);
171} 171}
172 172
173/* 173/*
@@ -223,10 +223,10 @@ static int dns_resolver_match_preparse(struct key_match_data *match_data)
223 */ 223 */
224static void dns_resolver_describe(const struct key *key, struct seq_file *m) 224static void dns_resolver_describe(const struct key *key, struct seq_file *m)
225{ 225{
226 int err = key->type_data.x[0];
227
228 seq_puts(m, key->description); 226 seq_puts(m, key->description);
229 if (key_is_instantiated(key)) { 227 if (key_is_instantiated(key)) {
228 int err = PTR_ERR(key->payload.data[dns_key_error]);
229
230 if (err) 230 if (err)
231 seq_printf(m, ": %d", err); 231 seq_printf(m, ": %d", err);
232 else 232 else
@@ -241,8 +241,10 @@ static void dns_resolver_describe(const struct key *key, struct seq_file *m)
241static long dns_resolver_read(const struct key *key, 241static long dns_resolver_read(const struct key *key,
242 char __user *buffer, size_t buflen) 242 char __user *buffer, size_t buflen)
243{ 243{
244 if (key->type_data.x[0]) 244 int err = PTR_ERR(key->payload.data[dns_key_error]);
245 return key->type_data.x[0]; 245
246 if (err)
247 return err;
246 248
247 return user_read(key, buffer, buflen); 249 return user_read(key, buffer, buflen);
248} 250}
diff --git a/net/dns_resolver/dns_query.c b/net/dns_resolver/dns_query.c
index 39d2c39bdf87..4677b6fa6dda 100644
--- a/net/dns_resolver/dns_query.c
+++ b/net/dns_resolver/dns_query.c
@@ -70,7 +70,7 @@ int dns_query(const char *type, const char *name, size_t namelen,
70 const char *options, char **_result, time_t *_expiry) 70 const char *options, char **_result, time_t *_expiry)
71{ 71{
72 struct key *rkey; 72 struct key *rkey;
73 struct user_key_payload *upayload; 73 const struct user_key_payload *upayload;
74 const struct cred *saved_cred; 74 const struct cred *saved_cred;
75 size_t typelen, desclen; 75 size_t typelen, desclen;
76 char *desc, *cp; 76 char *desc, *cp;
@@ -137,12 +137,11 @@ int dns_query(const char *type, const char *name, size_t namelen,
137 goto put; 137 goto put;
138 138
139 /* If the DNS server gave an error, return that to the caller */ 139 /* If the DNS server gave an error, return that to the caller */
140 ret = rkey->type_data.x[0]; 140 ret = PTR_ERR(rkey->payload.data[dns_key_error]);
141 if (ret) 141 if (ret)
142 goto put; 142 goto put;
143 143
144 upayload = rcu_dereference_protected(rkey->payload.data, 144 upayload = user_key_payload(rkey);
145 lockdep_is_held(&rkey->sem));
146 len = upayload->datalen; 145 len = upayload->datalen;
147 146
148 ret = -ENOMEM; 147 ret = -ENOMEM;
diff --git a/net/dns_resolver/internal.h b/net/dns_resolver/internal.h
index 7af1ed39c009..0c570d40e4d6 100644
--- a/net/dns_resolver/internal.h
+++ b/net/dns_resolver/internal.h
@@ -23,6 +23,14 @@
23#include <linux/sched.h> 23#include <linux/sched.h>
24 24
25/* 25/*
26 * Layout of key payload words.
27 */
28enum {
29 dns_key_data,
30 dns_key_error,
31};
32
33/*
26 * dns_key.c 34 * dns_key.c
27 */ 35 */
28extern const struct cred *dns_resolver_cache; 36extern const struct cred *dns_resolver_cache;
diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
index 25d60ed15284..1f8a144a5dc2 100644
--- a/net/rxrpc/af_rxrpc.c
+++ b/net/rxrpc/af_rxrpc.c
@@ -305,7 +305,7 @@ struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock,
305 305
306 if (!key) 306 if (!key)
307 key = rx->key; 307 key = rx->key;
308 if (key && !key->payload.data) 308 if (key && !key->payload.data[0])
309 key = NULL; /* a no-security key */ 309 key = NULL; /* a no-security key */
310 310
311 bundle = rxrpc_get_bundle(rx, trans, key, service_id, gfp); 311 bundle = rxrpc_get_bundle(rx, trans, key, service_id, gfp);
diff --git a/net/rxrpc/ar-key.c b/net/rxrpc/ar-key.c
index db0f39f5ef96..da3cc09f683e 100644
--- a/net/rxrpc/ar-key.c
+++ b/net/rxrpc/ar-key.c
@@ -148,10 +148,10 @@ static int rxrpc_preparse_xdr_rxkad(struct key_preparsed_payload *prep,
148 token->kad->ticket[6], token->kad->ticket[7]); 148 token->kad->ticket[6], token->kad->ticket[7]);
149 149
150 /* count the number of tokens attached */ 150 /* count the number of tokens attached */
151 prep->type_data[0] = (void *)((unsigned long)prep->type_data[0] + 1); 151 prep->payload.data[1] = (void *)((unsigned long)prep->payload.data[1] + 1);
152 152
153 /* attach the data */ 153 /* attach the data */
154 for (pptoken = (struct rxrpc_key_token **)&prep->payload[0]; 154 for (pptoken = (struct rxrpc_key_token **)&prep->payload.data[0];
155 *pptoken; 155 *pptoken;
156 pptoken = &(*pptoken)->next) 156 pptoken = &(*pptoken)->next)
157 continue; 157 continue;
@@ -522,7 +522,7 @@ static int rxrpc_preparse_xdr_rxk5(struct key_preparsed_payload *prep,
522 goto inval; 522 goto inval;
523 523
524 /* attach the payload */ 524 /* attach the payload */
525 for (pptoken = (struct rxrpc_key_token **)&prep->payload[0]; 525 for (pptoken = (struct rxrpc_key_token **)&prep->payload.data[0];
526 *pptoken; 526 *pptoken;
527 pptoken = &(*pptoken)->next) 527 pptoken = &(*pptoken)->next)
528 continue; 528 continue;
@@ -764,10 +764,10 @@ static int rxrpc_preparse(struct key_preparsed_payload *prep)
764 memcpy(&token->kad->ticket, v1->ticket, v1->ticket_length); 764 memcpy(&token->kad->ticket, v1->ticket, v1->ticket_length);
765 765
766 /* count the number of tokens attached */ 766 /* count the number of tokens attached */
767 prep->type_data[0] = (void *)((unsigned long)prep->type_data[0] + 1); 767 prep->payload.data[1] = (void *)((unsigned long)prep->payload.data[1] + 1);
768 768
769 /* attach the data */ 769 /* attach the data */
770 pp = (struct rxrpc_key_token **)&prep->payload[0]; 770 pp = (struct rxrpc_key_token **)&prep->payload.data[0];
771 while (*pp) 771 while (*pp)
772 pp = &(*pp)->next; 772 pp = &(*pp)->next;
773 *pp = token; 773 *pp = token;
@@ -814,7 +814,7 @@ static void rxrpc_free_token_list(struct rxrpc_key_token *token)
814 */ 814 */
815static void rxrpc_free_preparse(struct key_preparsed_payload *prep) 815static void rxrpc_free_preparse(struct key_preparsed_payload *prep)
816{ 816{
817 rxrpc_free_token_list(prep->payload[0]); 817 rxrpc_free_token_list(prep->payload.data[0]);
818} 818}
819 819
820/* 820/*
@@ -831,7 +831,7 @@ static int rxrpc_preparse_s(struct key_preparsed_payload *prep)
831 if (prep->datalen != 8) 831 if (prep->datalen != 8)
832 return -EINVAL; 832 return -EINVAL;
833 833
834 memcpy(&prep->type_data, prep->data, 8); 834 memcpy(&prep->payload.data[2], prep->data, 8);
835 835
836 ci = crypto_alloc_blkcipher("pcbc(des)", 0, CRYPTO_ALG_ASYNC); 836 ci = crypto_alloc_blkcipher("pcbc(des)", 0, CRYPTO_ALG_ASYNC);
837 if (IS_ERR(ci)) { 837 if (IS_ERR(ci)) {
@@ -842,7 +842,7 @@ static int rxrpc_preparse_s(struct key_preparsed_payload *prep)
842 if (crypto_blkcipher_setkey(ci, prep->data, 8) < 0) 842 if (crypto_blkcipher_setkey(ci, prep->data, 8) < 0)
843 BUG(); 843 BUG();
844 844
845 prep->payload[0] = ci; 845 prep->payload.data[0] = ci;
846 _leave(" = 0"); 846 _leave(" = 0");
847 return 0; 847 return 0;
848} 848}
@@ -852,8 +852,8 @@ static int rxrpc_preparse_s(struct key_preparsed_payload *prep)
852 */ 852 */
853static void rxrpc_free_preparse_s(struct key_preparsed_payload *prep) 853static void rxrpc_free_preparse_s(struct key_preparsed_payload *prep)
854{ 854{
855 if (prep->payload[0]) 855 if (prep->payload.data[0])
856 crypto_free_blkcipher(prep->payload[0]); 856 crypto_free_blkcipher(prep->payload.data[0]);
857} 857}
858 858
859/* 859/*
@@ -861,7 +861,7 @@ static void rxrpc_free_preparse_s(struct key_preparsed_payload *prep)
861 */ 861 */
862static void rxrpc_destroy(struct key *key) 862static void rxrpc_destroy(struct key *key)
863{ 863{
864 rxrpc_free_token_list(key->payload.data); 864 rxrpc_free_token_list(key->payload.data[0]);
865} 865}
866 866
867/* 867/*
@@ -869,9 +869,9 @@ static void rxrpc_destroy(struct key *key)
869 */ 869 */
870static void rxrpc_destroy_s(struct key *key) 870static void rxrpc_destroy_s(struct key *key)
871{ 871{
872 if (key->payload.data) { 872 if (key->payload.data[0]) {
873 crypto_free_blkcipher(key->payload.data); 873 crypto_free_blkcipher(key->payload.data[0]);
874 key->payload.data = NULL; 874 key->payload.data[0] = NULL;
875 } 875 }
876} 876}
877 877
@@ -1070,7 +1070,7 @@ static long rxrpc_read(const struct key *key,
1070 size += 1 * 4; /* token count */ 1070 size += 1 * 4; /* token count */
1071 1071
1072 ntoks = 0; 1072 ntoks = 0;
1073 for (token = key->payload.data; token; token = token->next) { 1073 for (token = key->payload.data[0]; token; token = token->next) {
1074 toksize = 4; /* sec index */ 1074 toksize = 4; /* sec index */
1075 1075
1076 switch (token->security_index) { 1076 switch (token->security_index) {
@@ -1163,7 +1163,7 @@ static long rxrpc_read(const struct key *key,
1163 ENCODE(ntoks); 1163 ENCODE(ntoks);
1164 1164
1165 tok = 0; 1165 tok = 0;
1166 for (token = key->payload.data; token; token = token->next) { 1166 for (token = key->payload.data[0]; token; token = token->next) {
1167 toksize = toksizes[tok++]; 1167 toksize = toksizes[tok++];
1168 ENCODE(toksize); 1168 ENCODE(toksize);
1169 oldxdr = xdr; 1169 oldxdr = xdr;
diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
index c0042807bfc6..a40d3afe93b7 100644
--- a/net/rxrpc/ar-output.c
+++ b/net/rxrpc/ar-output.c
@@ -158,7 +158,7 @@ int rxrpc_client_sendmsg(struct rxrpc_sock *rx, struct rxrpc_transport *trans,
158 service_id = htons(srx->srx_service); 158 service_id = htons(srx->srx_service);
159 } 159 }
160 key = rx->key; 160 key = rx->key;
161 if (key && !rx->key->payload.data) 161 if (key && !rx->key->payload.data[0])
162 key = NULL; 162 key = NULL;
163 bundle = rxrpc_get_bundle(rx, trans, key, service_id, 163 bundle = rxrpc_get_bundle(rx, trans, key, service_id,
164 GFP_KERNEL); 164 GFP_KERNEL);
diff --git a/net/rxrpc/ar-security.c b/net/rxrpc/ar-security.c
index 49b3cc31ee1f..8334474eb26c 100644
--- a/net/rxrpc/ar-security.c
+++ b/net/rxrpc/ar-security.c
@@ -137,9 +137,9 @@ int rxrpc_init_client_conn_security(struct rxrpc_connection *conn)
137 if (ret < 0) 137 if (ret < 0)
138 return ret; 138 return ret;
139 139
140 if (!key->payload.data) 140 token = key->payload.data[0];
141 if (!token)
141 return -EKEYREJECTED; 142 return -EKEYREJECTED;
142 token = key->payload.data;
143 143
144 sec = rxrpc_security_lookup(token->security_index); 144 sec = rxrpc_security_lookup(token->security_index);
145 if (!sec) 145 if (!sec)
diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
index f226709ebd8f..d7a9ab5a9d9c 100644
--- a/net/rxrpc/rxkad.c
+++ b/net/rxrpc/rxkad.c
@@ -67,7 +67,7 @@ static int rxkad_init_connection_security(struct rxrpc_connection *conn)
67 67
68 _enter("{%d},{%x}", conn->debug_id, key_serial(conn->key)); 68 _enter("{%d},{%x}", conn->debug_id, key_serial(conn->key));
69 69
70 token = conn->key->payload.data; 70 token = conn->key->payload.data[0];
71 conn->security_ix = token->security_index; 71 conn->security_ix = token->security_index;
72 72
73 ci = crypto_alloc_blkcipher("pcbc(fcrypt)", 0, CRYPTO_ALG_ASYNC); 73 ci = crypto_alloc_blkcipher("pcbc(fcrypt)", 0, CRYPTO_ALG_ASYNC);
@@ -125,7 +125,7 @@ static void rxkad_prime_packet_security(struct rxrpc_connection *conn)
125 if (!conn->key) 125 if (!conn->key)
126 return; 126 return;
127 127
128 token = conn->key->payload.data; 128 token = conn->key->payload.data[0];
129 memcpy(&iv, token->kad->session_key, sizeof(iv)); 129 memcpy(&iv, token->kad->session_key, sizeof(iv));
130 130
131 desc.tfm = conn->cipher; 131 desc.tfm = conn->cipher;
@@ -221,7 +221,7 @@ static int rxkad_secure_packet_encrypt(const struct rxrpc_call *call,
221 rxkhdr.checksum = 0; 221 rxkhdr.checksum = 0;
222 222
223 /* encrypt from the session key */ 223 /* encrypt from the session key */
224 token = call->conn->key->payload.data; 224 token = call->conn->key->payload.data[0];
225 memcpy(&iv, token->kad->session_key, sizeof(iv)); 225 memcpy(&iv, token->kad->session_key, sizeof(iv));
226 desc.tfm = call->conn->cipher; 226 desc.tfm = call->conn->cipher;
227 desc.info = iv.x; 227 desc.info = iv.x;
@@ -433,7 +433,7 @@ static int rxkad_verify_packet_encrypt(const struct rxrpc_call *call,
433 skb_to_sgvec(skb, sg, 0, skb->len); 433 skb_to_sgvec(skb, sg, 0, skb->len);
434 434
435 /* decrypt from the session key */ 435 /* decrypt from the session key */
436 token = call->conn->key->payload.data; 436 token = call->conn->key->payload.data[0];
437 memcpy(&iv, token->kad->session_key, sizeof(iv)); 437 memcpy(&iv, token->kad->session_key, sizeof(iv));
438 desc.tfm = call->conn->cipher; 438 desc.tfm = call->conn->cipher;
439 desc.info = iv.x; 439 desc.info = iv.x;
@@ -780,7 +780,7 @@ static int rxkad_respond_to_challenge(struct rxrpc_connection *conn,
780 if (conn->security_level < min_level) 780 if (conn->security_level < min_level)
781 goto protocol_error; 781 goto protocol_error;
782 782
783 token = conn->key->payload.data; 783 token = conn->key->payload.data[0];
784 784
785 /* build the response packet */ 785 /* build the response packet */
786 memset(&resp, 0, sizeof(resp)); 786 memset(&resp, 0, sizeof(resp));
@@ -848,12 +848,12 @@ static int rxkad_decrypt_ticket(struct rxrpc_connection *conn,
848 } 848 }
849 } 849 }
850 850
851 ASSERT(conn->server_key->payload.data != NULL); 851 ASSERT(conn->server_key->payload.data[0] != NULL);
852 ASSERTCMP((unsigned long) ticket & 7UL, ==, 0); 852 ASSERTCMP((unsigned long) ticket & 7UL, ==, 0);
853 853
854 memcpy(&iv, &conn->server_key->type_data, sizeof(iv)); 854 memcpy(&iv, &conn->server_key->payload.data[2], sizeof(iv));
855 855
856 desc.tfm = conn->server_key->payload.data; 856 desc.tfm = conn->server_key->payload.data[0];
857 desc.info = iv.x; 857 desc.info = iv.x;
858 desc.flags = 0; 858 desc.flags = 0;
859 859
diff --git a/security/integrity/evm/evm_crypto.c b/security/integrity/evm/evm_crypto.c
index 159ef3ea4130..461f8d891579 100644
--- a/security/integrity/evm/evm_crypto.c
+++ b/security/integrity/evm/evm_crypto.c
@@ -247,7 +247,7 @@ int evm_init_key(void)
247 return -ENOENT; 247 return -ENOENT;
248 248
249 down_read(&evm_key->sem); 249 down_read(&evm_key->sem);
250 ekp = evm_key->payload.data; 250 ekp = evm_key->payload.data[0];
251 if (ekp->decrypted_datalen > MAX_KEY_SIZE) { 251 if (ekp->decrypted_datalen > MAX_KEY_SIZE) {
252 rc = -EINVAL; 252 rc = -EINVAL;
253 goto out; 253 goto out;
diff --git a/security/keys/big_key.c b/security/keys/big_key.c
index b6adb94f6d52..907c1522ee46 100644
--- a/security/keys/big_key.c
+++ b/security/keys/big_key.c
@@ -21,6 +21,16 @@
21MODULE_LICENSE("GPL"); 21MODULE_LICENSE("GPL");
22 22
23/* 23/*
24 * Layout of key payload words.
25 */
26enum {
27 big_key_data,
28 big_key_path,
29 big_key_path_2nd_part,
30 big_key_len,
31};
32
33/*
24 * If the data is under this limit, there's no point creating a shm file to 34 * If the data is under this limit, there's no point creating a shm file to
25 * hold it as the permanently resident metadata for the shmem fs will be at 35 * hold it as the permanently resident metadata for the shmem fs will be at
26 * least as large as the data. 36 * least as large as the data.
@@ -47,7 +57,7 @@ struct key_type key_type_big_key = {
47 */ 57 */
48int big_key_preparse(struct key_preparsed_payload *prep) 58int big_key_preparse(struct key_preparsed_payload *prep)
49{ 59{
50 struct path *path = (struct path *)&prep->payload; 60 struct path *path = (struct path *)&prep->payload.data[big_key_path];
51 struct file *file; 61 struct file *file;
52 ssize_t written; 62 ssize_t written;
53 size_t datalen = prep->datalen; 63 size_t datalen = prep->datalen;
@@ -60,7 +70,7 @@ int big_key_preparse(struct key_preparsed_payload *prep)
60 /* Set an arbitrary quota */ 70 /* Set an arbitrary quota */
61 prep->quotalen = 16; 71 prep->quotalen = 16;
62 72
63 prep->type_data[1] = (void *)(unsigned long)datalen; 73 prep->payload.data[big_key_len] = (void *)(unsigned long)datalen;
64 74
65 if (datalen > BIG_KEY_FILE_THRESHOLD) { 75 if (datalen > BIG_KEY_FILE_THRESHOLD) {
66 /* Create a shmem file to store the data in. This will permit the data 76 /* Create a shmem file to store the data in. This will permit the data
@@ -94,7 +104,8 @@ int big_key_preparse(struct key_preparsed_payload *prep)
94 if (!data) 104 if (!data)
95 return -ENOMEM; 105 return -ENOMEM;
96 106
97 prep->payload[0] = memcpy(data, prep->data, prep->datalen); 107 prep->payload.data[big_key_data] = data;
108 memcpy(data, prep->data, prep->datalen);
98 } 109 }
99 return 0; 110 return 0;
100 111
@@ -110,10 +121,10 @@ error:
110void big_key_free_preparse(struct key_preparsed_payload *prep) 121void big_key_free_preparse(struct key_preparsed_payload *prep)
111{ 122{
112 if (prep->datalen > BIG_KEY_FILE_THRESHOLD) { 123 if (prep->datalen > BIG_KEY_FILE_THRESHOLD) {
113 struct path *path = (struct path *)&prep->payload; 124 struct path *path = (struct path *)&prep->payload.data[big_key_path];
114 path_put(path); 125 path_put(path);
115 } else { 126 } else {
116 kfree(prep->payload[0]); 127 kfree(prep->payload.data[big_key_data]);
117 } 128 }
118} 129}
119 130
@@ -123,11 +134,12 @@ void big_key_free_preparse(struct key_preparsed_payload *prep)
123 */ 134 */
124void big_key_revoke(struct key *key) 135void big_key_revoke(struct key *key)
125{ 136{
126 struct path *path = (struct path *)&key->payload.data2; 137 struct path *path = (struct path *)&key->payload.data[big_key_path];
127 138
128 /* clear the quota */ 139 /* clear the quota */
129 key_payload_reserve(key, 0); 140 key_payload_reserve(key, 0);
130 if (key_is_instantiated(key) && key->type_data.x[1] > BIG_KEY_FILE_THRESHOLD) 141 if (key_is_instantiated(key) &&
142 (size_t)key->payload.data[big_key_len] > BIG_KEY_FILE_THRESHOLD)
131 vfs_truncate(path, 0); 143 vfs_truncate(path, 0);
132} 144}
133 145
@@ -136,14 +148,16 @@ void big_key_revoke(struct key *key)
136 */ 148 */
137void big_key_destroy(struct key *key) 149void big_key_destroy(struct key *key)
138{ 150{
139 if (key->type_data.x[1] > BIG_KEY_FILE_THRESHOLD) { 151 size_t datalen = (size_t)key->payload.data[big_key_len];
140 struct path *path = (struct path *)&key->payload.data2; 152
153 if (datalen) {
154 struct path *path = (struct path *)&key->payload.data[big_key_path];
141 path_put(path); 155 path_put(path);
142 path->mnt = NULL; 156 path->mnt = NULL;
143 path->dentry = NULL; 157 path->dentry = NULL;
144 } else { 158 } else {
145 kfree(key->payload.data); 159 kfree(key->payload.data[big_key_data]);
146 key->payload.data = NULL; 160 key->payload.data[big_key_data] = NULL;
147 } 161 }
148} 162}
149 163
@@ -152,12 +166,12 @@ void big_key_destroy(struct key *key)
152 */ 166 */
153void big_key_describe(const struct key *key, struct seq_file *m) 167void big_key_describe(const struct key *key, struct seq_file *m)
154{ 168{
155 unsigned long datalen = key->type_data.x[1]; 169 size_t datalen = (size_t)key->payload.data[big_key_len];
156 170
157 seq_puts(m, key->description); 171 seq_puts(m, key->description);
158 172
159 if (key_is_instantiated(key)) 173 if (key_is_instantiated(key))
160 seq_printf(m, ": %lu [%s]", 174 seq_printf(m, ": %zu [%s]",
161 datalen, 175 datalen,
162 datalen > BIG_KEY_FILE_THRESHOLD ? "file" : "buff"); 176 datalen > BIG_KEY_FILE_THRESHOLD ? "file" : "buff");
163} 177}
@@ -168,14 +182,14 @@ void big_key_describe(const struct key *key, struct seq_file *m)
168 */ 182 */
169long big_key_read(const struct key *key, char __user *buffer, size_t buflen) 183long big_key_read(const struct key *key, char __user *buffer, size_t buflen)
170{ 184{
171 unsigned long datalen = key->type_data.x[1]; 185 size_t datalen = (size_t)key->payload.data[big_key_len];
172 long ret; 186 long ret;
173 187
174 if (!buffer || buflen < datalen) 188 if (!buffer || buflen < datalen)
175 return datalen; 189 return datalen;
176 190
177 if (datalen > BIG_KEY_FILE_THRESHOLD) { 191 if (datalen > BIG_KEY_FILE_THRESHOLD) {
178 struct path *path = (struct path *)&key->payload.data2; 192 struct path *path = (struct path *)&key->payload.data[big_key_path];
179 struct file *file; 193 struct file *file;
180 loff_t pos; 194 loff_t pos;
181 195
@@ -190,7 +204,8 @@ long big_key_read(const struct key *key, char __user *buffer, size_t buflen)
190 ret = -EIO; 204 ret = -EIO;
191 } else { 205 } else {
192 ret = datalen; 206 ret = datalen;
193 if (copy_to_user(buffer, key->payload.data, datalen) != 0) 207 if (copy_to_user(buffer, key->payload.data[big_key_data],
208 datalen) != 0)
194 ret = -EFAULT; 209 ret = -EFAULT;
195 } 210 }
196 211
diff --git a/security/keys/encrypted-keys/encrypted.c b/security/keys/encrypted-keys/encrypted.c
index 7bed4ad7cd76..927db9f35ad6 100644
--- a/security/keys/encrypted-keys/encrypted.c
+++ b/security/keys/encrypted-keys/encrypted.c
@@ -303,10 +303,10 @@ out:
303 * 303 *
304 * Use a user provided key to encrypt/decrypt an encrypted-key. 304 * Use a user provided key to encrypt/decrypt an encrypted-key.
305 */ 305 */
306static struct key *request_user_key(const char *master_desc, u8 **master_key, 306static struct key *request_user_key(const char *master_desc, const u8 **master_key,
307 size_t *master_keylen) 307 size_t *master_keylen)
308{ 308{
309 struct user_key_payload *upayload; 309 const struct user_key_payload *upayload;
310 struct key *ukey; 310 struct key *ukey;
311 311
312 ukey = request_key(&key_type_user, master_desc, NULL); 312 ukey = request_key(&key_type_user, master_desc, NULL);
@@ -314,7 +314,7 @@ static struct key *request_user_key(const char *master_desc, u8 **master_key,
314 goto error; 314 goto error;
315 315
316 down_read(&ukey->sem); 316 down_read(&ukey->sem);
317 upayload = ukey->payload.data; 317 upayload = user_key_payload(ukey);
318 *master_key = upayload->data; 318 *master_key = upayload->data;
319 *master_keylen = upayload->datalen; 319 *master_keylen = upayload->datalen;
320error: 320error:
@@ -426,7 +426,7 @@ static int init_blkcipher_desc(struct blkcipher_desc *desc, const u8 *key,
426} 426}
427 427
428static struct key *request_master_key(struct encrypted_key_payload *epayload, 428static struct key *request_master_key(struct encrypted_key_payload *epayload,
429 u8 **master_key, size_t *master_keylen) 429 const u8 **master_key, size_t *master_keylen)
430{ 430{
431 struct key *mkey = NULL; 431 struct key *mkey = NULL;
432 432
@@ -653,7 +653,7 @@ static int encrypted_key_decrypt(struct encrypted_key_payload *epayload,
653{ 653{
654 struct key *mkey; 654 struct key *mkey;
655 u8 derived_key[HASH_SIZE]; 655 u8 derived_key[HASH_SIZE];
656 u8 *master_key; 656 const u8 *master_key;
657 u8 *hmac; 657 u8 *hmac;
658 const char *hex_encoded_data; 658 const char *hex_encoded_data;
659 unsigned int encrypted_datalen; 659 unsigned int encrypted_datalen;
@@ -837,7 +837,7 @@ static void encrypted_rcu_free(struct rcu_head *rcu)
837 */ 837 */
838static int encrypted_update(struct key *key, struct key_preparsed_payload *prep) 838static int encrypted_update(struct key *key, struct key_preparsed_payload *prep)
839{ 839{
840 struct encrypted_key_payload *epayload = key->payload.data; 840 struct encrypted_key_payload *epayload = key->payload.data[0];
841 struct encrypted_key_payload *new_epayload; 841 struct encrypted_key_payload *new_epayload;
842 char *buf; 842 char *buf;
843 char *new_master_desc = NULL; 843 char *new_master_desc = NULL;
@@ -896,7 +896,7 @@ static long encrypted_read(const struct key *key, char __user *buffer,
896{ 896{
897 struct encrypted_key_payload *epayload; 897 struct encrypted_key_payload *epayload;
898 struct key *mkey; 898 struct key *mkey;
899 u8 *master_key; 899 const u8 *master_key;
900 size_t master_keylen; 900 size_t master_keylen;
901 char derived_key[HASH_SIZE]; 901 char derived_key[HASH_SIZE];
902 char *ascii_buf; 902 char *ascii_buf;
@@ -957,13 +957,13 @@ out:
957 */ 957 */
958static void encrypted_destroy(struct key *key) 958static void encrypted_destroy(struct key *key)
959{ 959{
960 struct encrypted_key_payload *epayload = key->payload.data; 960 struct encrypted_key_payload *epayload = key->payload.data[0];
961 961
962 if (!epayload) 962 if (!epayload)
963 return; 963 return;
964 964
965 memset(epayload->decrypted_data, 0, epayload->decrypted_datalen); 965 memset(epayload->decrypted_data, 0, epayload->decrypted_datalen);
966 kfree(key->payload.data); 966 kfree(key->payload.data[0]);
967} 967}
968 968
969struct key_type key_type_encrypted = { 969struct key_type key_type_encrypted = {
diff --git a/security/keys/encrypted-keys/encrypted.h b/security/keys/encrypted-keys/encrypted.h
index 8136a2d44c63..47802c0de735 100644
--- a/security/keys/encrypted-keys/encrypted.h
+++ b/security/keys/encrypted-keys/encrypted.h
@@ -5,10 +5,10 @@
5#if defined(CONFIG_TRUSTED_KEYS) || \ 5#if defined(CONFIG_TRUSTED_KEYS) || \
6 (defined(CONFIG_TRUSTED_KEYS_MODULE) && defined(CONFIG_ENCRYPTED_KEYS_MODULE)) 6 (defined(CONFIG_TRUSTED_KEYS_MODULE) && defined(CONFIG_ENCRYPTED_KEYS_MODULE))
7extern struct key *request_trusted_key(const char *trusted_desc, 7extern struct key *request_trusted_key(const char *trusted_desc,
8 u8 **master_key, size_t *master_keylen); 8 const u8 **master_key, size_t *master_keylen);
9#else 9#else
10static inline struct key *request_trusted_key(const char *trusted_desc, 10static inline struct key *request_trusted_key(const char *trusted_desc,
11 u8 **master_key, 11 const u8 **master_key,
12 size_t *master_keylen) 12 size_t *master_keylen)
13{ 13{
14 return ERR_PTR(-EOPNOTSUPP); 14 return ERR_PTR(-EOPNOTSUPP);
diff --git a/security/keys/encrypted-keys/masterkey_trusted.c b/security/keys/encrypted-keys/masterkey_trusted.c
index 013f7e5d3a2f..b5b4812dbc87 100644
--- a/security/keys/encrypted-keys/masterkey_trusted.c
+++ b/security/keys/encrypted-keys/masterkey_trusted.c
@@ -29,7 +29,7 @@
29 * data, trusted key type data is not visible decrypted from userspace. 29 * data, trusted key type data is not visible decrypted from userspace.
30 */ 30 */
31struct key *request_trusted_key(const char *trusted_desc, 31struct key *request_trusted_key(const char *trusted_desc,
32 u8 **master_key, size_t *master_keylen) 32 const u8 **master_key, size_t *master_keylen)
33{ 33{
34 struct trusted_key_payload *tpayload; 34 struct trusted_key_payload *tpayload;
35 struct key *tkey; 35 struct key *tkey;
@@ -39,7 +39,7 @@ struct key *request_trusted_key(const char *trusted_desc,
39 goto error; 39 goto error;
40 40
41 down_read(&tkey->sem); 41 down_read(&tkey->sem);
42 tpayload = tkey->payload.data; 42 tpayload = tkey->payload.data[0];
43 *master_key = tpayload->key; 43 *master_key = tpayload->key;
44 *master_keylen = tpayload->key_len; 44 *master_keylen = tpayload->key_len;
45error: 45error:
diff --git a/security/keys/key.c b/security/keys/key.c
index c0478465d1ac..ab7997ded725 100644
--- a/security/keys/key.c
+++ b/security/keys/key.c
@@ -554,7 +554,7 @@ int key_reject_and_link(struct key *key,
554 if (!test_bit(KEY_FLAG_INSTANTIATED, &key->flags)) { 554 if (!test_bit(KEY_FLAG_INSTANTIATED, &key->flags)) {
555 /* mark the key as being negatively instantiated */ 555 /* mark the key as being negatively instantiated */
556 atomic_inc(&key->user->nikeys); 556 atomic_inc(&key->user->nikeys);
557 key->type_data.reject_error = -error; 557 key->reject_error = -error;
558 smp_wmb(); 558 smp_wmb();
559 set_bit(KEY_FLAG_NEGATIVE, &key->flags); 559 set_bit(KEY_FLAG_NEGATIVE, &key->flags);
560 set_bit(KEY_FLAG_INSTANTIATED, &key->flags); 560 set_bit(KEY_FLAG_INSTANTIATED, &key->flags);
@@ -1046,14 +1046,14 @@ int generic_key_instantiate(struct key *key, struct key_preparsed_payload *prep)
1046 1046
1047 ret = key_payload_reserve(key, prep->quotalen); 1047 ret = key_payload_reserve(key, prep->quotalen);
1048 if (ret == 0) { 1048 if (ret == 0) {
1049 key->type_data.p[0] = prep->type_data[0]; 1049 rcu_assign_keypointer(key, prep->payload.data[0]);
1050 key->type_data.p[1] = prep->type_data[1]; 1050 key->payload.data[1] = prep->payload.data[1];
1051 rcu_assign_keypointer(key, prep->payload[0]); 1051 key->payload.data[2] = prep->payload.data[2];
1052 key->payload.data2[1] = prep->payload[1]; 1052 key->payload.data[3] = prep->payload.data[3];
1053 prep->type_data[0] = NULL; 1053 prep->payload.data[0] = NULL;
1054 prep->type_data[1] = NULL; 1054 prep->payload.data[1] = NULL;
1055 prep->payload[0] = NULL; 1055 prep->payload.data[2] = NULL;
1056 prep->payload[1] = NULL; 1056 prep->payload.data[3] = NULL;
1057 } 1057 }
1058 pr_devel("<==%s() = %d\n", __func__, ret); 1058 pr_devel("<==%s() = %d\n", __func__, ret);
1059 return ret; 1059 return ret;
diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
index 6110fa498494..fb111eafcb89 100644
--- a/security/keys/keyctl.c
+++ b/security/keys/keyctl.c
@@ -1027,7 +1027,7 @@ long keyctl_instantiate_key_common(key_serial_t id,
1027 if (!instkey) 1027 if (!instkey)
1028 goto error; 1028 goto error;
1029 1029
1030 rka = instkey->payload.data; 1030 rka = instkey->payload.data[0];
1031 if (rka->target_key->serial != id) 1031 if (rka->target_key->serial != id)
1032 goto error; 1032 goto error;
1033 1033
@@ -1194,7 +1194,7 @@ long keyctl_reject_key(key_serial_t id, unsigned timeout, unsigned error,
1194 if (!instkey) 1194 if (!instkey)
1195 goto error; 1195 goto error;
1196 1196
1197 rka = instkey->payload.data; 1197 rka = instkey->payload.data[0];
1198 if (rka->target_key->serial != id) 1198 if (rka->target_key->serial != id)
1199 goto error; 1199 goto error;
1200 1200
diff --git a/security/keys/keyring.c b/security/keys/keyring.c
index d33437007ad2..f931ccfeefb0 100644
--- a/security/keys/keyring.c
+++ b/security/keys/keyring.c
@@ -118,7 +118,7 @@ static void keyring_publish_name(struct key *keyring)
118 if (!keyring_name_hash[bucket].next) 118 if (!keyring_name_hash[bucket].next)
119 INIT_LIST_HEAD(&keyring_name_hash[bucket]); 119 INIT_LIST_HEAD(&keyring_name_hash[bucket]);
120 120
121 list_add_tail(&keyring->type_data.link, 121 list_add_tail(&keyring->name_link,
122 &keyring_name_hash[bucket]); 122 &keyring_name_hash[bucket]);
123 123
124 write_unlock(&keyring_name_lock); 124 write_unlock(&keyring_name_lock);
@@ -387,9 +387,9 @@ static void keyring_destroy(struct key *keyring)
387 if (keyring->description) { 387 if (keyring->description) {
388 write_lock(&keyring_name_lock); 388 write_lock(&keyring_name_lock);
389 389
390 if (keyring->type_data.link.next != NULL && 390 if (keyring->name_link.next != NULL &&
391 !list_empty(&keyring->type_data.link)) 391 !list_empty(&keyring->name_link))
392 list_del(&keyring->type_data.link); 392 list_del(&keyring->name_link);
393 393
394 write_unlock(&keyring_name_lock); 394 write_unlock(&keyring_name_lock);
395 } 395 }
@@ -572,7 +572,7 @@ static int keyring_search_iterator(const void *object, void *iterator_data)
572 /* we set a different error code if we pass a negative key */ 572 /* we set a different error code if we pass a negative key */
573 if (kflags & (1 << KEY_FLAG_NEGATIVE)) { 573 if (kflags & (1 << KEY_FLAG_NEGATIVE)) {
574 smp_rmb(); 574 smp_rmb();
575 ctx->result = ERR_PTR(key->type_data.reject_error); 575 ctx->result = ERR_PTR(key->reject_error);
576 kleave(" = %d [neg]", ctx->skipped_ret); 576 kleave(" = %d [neg]", ctx->skipped_ret);
577 goto skipped; 577 goto skipped;
578 } 578 }
@@ -990,7 +990,7 @@ struct key *find_keyring_by_name(const char *name, bool skip_perm_check)
990 * that's readable and that hasn't been revoked */ 990 * that's readable and that hasn't been revoked */
991 list_for_each_entry(keyring, 991 list_for_each_entry(keyring,
992 &keyring_name_hash[bucket], 992 &keyring_name_hash[bucket],
993 type_data.link 993 name_link
994 ) { 994 ) {
995 if (!kuid_has_mapping(current_user_ns(), keyring->user->uid)) 995 if (!kuid_has_mapping(current_user_ns(), keyring->user->uid))
996 continue; 996 continue;
diff --git a/security/keys/process_keys.c b/security/keys/process_keys.c
index 43b4cddbf2b3..a3f85d2a00bb 100644
--- a/security/keys/process_keys.c
+++ b/security/keys/process_keys.c
@@ -457,7 +457,7 @@ key_ref_t search_process_keyrings(struct keyring_search_context *ctx)
457 down_read(&cred->request_key_auth->sem); 457 down_read(&cred->request_key_auth->sem);
458 458
459 if (key_validate(ctx->cred->request_key_auth) == 0) { 459 if (key_validate(ctx->cred->request_key_auth) == 0) {
460 rka = ctx->cred->request_key_auth->payload.data; 460 rka = ctx->cred->request_key_auth->payload.data[0];
461 461
462 ctx->cred = rka->cred; 462 ctx->cred = rka->cred;
463 key_ref = search_process_keyrings(ctx); 463 key_ref = search_process_keyrings(ctx);
@@ -647,7 +647,7 @@ try_again:
647 key_ref = ERR_PTR(-EKEYREVOKED); 647 key_ref = ERR_PTR(-EKEYREVOKED);
648 key = NULL; 648 key = NULL;
649 } else { 649 } else {
650 rka = ctx.cred->request_key_auth->payload.data; 650 rka = ctx.cred->request_key_auth->payload.data[0];
651 key = rka->dest_keyring; 651 key = rka->dest_keyring;
652 __key_get(key); 652 __key_get(key);
653 } 653 }
diff --git a/security/keys/request_key.c b/security/keys/request_key.c
index 486ef6fa393b..95d5cfc172c6 100644
--- a/security/keys/request_key.c
+++ b/security/keys/request_key.c
@@ -271,7 +271,7 @@ static void construct_get_dest_keyring(struct key **_dest_keyring)
271 if (cred->request_key_auth) { 271 if (cred->request_key_auth) {
272 authkey = cred->request_key_auth; 272 authkey = cred->request_key_auth;
273 down_read(&authkey->sem); 273 down_read(&authkey->sem);
274 rka = authkey->payload.data; 274 rka = authkey->payload.data[0];
275 if (!test_bit(KEY_FLAG_REVOKED, 275 if (!test_bit(KEY_FLAG_REVOKED,
276 &authkey->flags)) 276 &authkey->flags))
277 dest_keyring = 277 dest_keyring =
@@ -593,7 +593,7 @@ int wait_for_key_construction(struct key *key, bool intr)
593 return -ERESTARTSYS; 593 return -ERESTARTSYS;
594 if (test_bit(KEY_FLAG_NEGATIVE, &key->flags)) { 594 if (test_bit(KEY_FLAG_NEGATIVE, &key->flags)) {
595 smp_rmb(); 595 smp_rmb();
596 return key->type_data.reject_error; 596 return key->reject_error;
597 } 597 }
598 return key_validate(key); 598 return key_validate(key);
599} 599}
diff --git a/security/keys/request_key_auth.c b/security/keys/request_key_auth.c
index 5d672f7580dd..4f0f112fe276 100644
--- a/security/keys/request_key_auth.c
+++ b/security/keys/request_key_auth.c
@@ -59,7 +59,7 @@ static void request_key_auth_free_preparse(struct key_preparsed_payload *prep)
59static int request_key_auth_instantiate(struct key *key, 59static int request_key_auth_instantiate(struct key *key,
60 struct key_preparsed_payload *prep) 60 struct key_preparsed_payload *prep)
61{ 61{
62 key->payload.data = (struct request_key_auth *)prep->data; 62 key->payload.data[0] = (struct request_key_auth *)prep->data;
63 return 0; 63 return 0;
64} 64}
65 65
@@ -69,7 +69,7 @@ static int request_key_auth_instantiate(struct key *key,
69static void request_key_auth_describe(const struct key *key, 69static void request_key_auth_describe(const struct key *key,
70 struct seq_file *m) 70 struct seq_file *m)
71{ 71{
72 struct request_key_auth *rka = key->payload.data; 72 struct request_key_auth *rka = key->payload.data[0];
73 73
74 seq_puts(m, "key:"); 74 seq_puts(m, "key:");
75 seq_puts(m, key->description); 75 seq_puts(m, key->description);
@@ -84,7 +84,7 @@ static void request_key_auth_describe(const struct key *key,
84static long request_key_auth_read(const struct key *key, 84static long request_key_auth_read(const struct key *key,
85 char __user *buffer, size_t buflen) 85 char __user *buffer, size_t buflen)
86{ 86{
87 struct request_key_auth *rka = key->payload.data; 87 struct request_key_auth *rka = key->payload.data[0];
88 size_t datalen; 88 size_t datalen;
89 long ret; 89 long ret;
90 90
@@ -110,7 +110,7 @@ static long request_key_auth_read(const struct key *key,
110 */ 110 */
111static void request_key_auth_revoke(struct key *key) 111static void request_key_auth_revoke(struct key *key)
112{ 112{
113 struct request_key_auth *rka = key->payload.data; 113 struct request_key_auth *rka = key->payload.data[0];
114 114
115 kenter("{%d}", key->serial); 115 kenter("{%d}", key->serial);
116 116
@@ -125,7 +125,7 @@ static void request_key_auth_revoke(struct key *key)
125 */ 125 */
126static void request_key_auth_destroy(struct key *key) 126static void request_key_auth_destroy(struct key *key)
127{ 127{
128 struct request_key_auth *rka = key->payload.data; 128 struct request_key_auth *rka = key->payload.data[0];
129 129
130 kenter("{%d}", key->serial); 130 kenter("{%d}", key->serial);
131 131
@@ -179,7 +179,7 @@ struct key *request_key_auth_new(struct key *target, const void *callout_info,
179 if (test_bit(KEY_FLAG_REVOKED, &cred->request_key_auth->flags)) 179 if (test_bit(KEY_FLAG_REVOKED, &cred->request_key_auth->flags))
180 goto auth_key_revoked; 180 goto auth_key_revoked;
181 181
182 irka = cred->request_key_auth->payload.data; 182 irka = cred->request_key_auth->payload.data[0];
183 rka->cred = get_cred(irka->cred); 183 rka->cred = get_cred(irka->cred);
184 rka->pid = irka->pid; 184 rka->pid = irka->pid;
185 185
diff --git a/security/keys/trusted.c b/security/keys/trusted.c
index d3633cf17c7d..903dace648a1 100644
--- a/security/keys/trusted.c
+++ b/security/keys/trusted.c
@@ -1007,7 +1007,7 @@ static void trusted_rcu_free(struct rcu_head *rcu)
1007 */ 1007 */
1008static int trusted_update(struct key *key, struct key_preparsed_payload *prep) 1008static int trusted_update(struct key *key, struct key_preparsed_payload *prep)
1009{ 1009{
1010 struct trusted_key_payload *p = key->payload.data; 1010 struct trusted_key_payload *p = key->payload.data[0];
1011 struct trusted_key_payload *new_p; 1011 struct trusted_key_payload *new_p;
1012 struct trusted_key_options *new_o; 1012 struct trusted_key_options *new_o;
1013 size_t datalen = prep->datalen; 1013 size_t datalen = prep->datalen;
@@ -1114,12 +1114,12 @@ static long trusted_read(const struct key *key, char __user *buffer,
1114 */ 1114 */
1115static void trusted_destroy(struct key *key) 1115static void trusted_destroy(struct key *key)
1116{ 1116{
1117 struct trusted_key_payload *p = key->payload.data; 1117 struct trusted_key_payload *p = key->payload.data[0];
1118 1118
1119 if (!p) 1119 if (!p)
1120 return; 1120 return;
1121 memset(p->key, 0, p->key_len); 1121 memset(p->key, 0, p->key_len);
1122 kfree(key->payload.data); 1122 kfree(key->payload.data[0]);
1123} 1123}
1124 1124
1125struct key_type key_type_trusted = { 1125struct key_type key_type_trusted = {
diff --git a/security/keys/user_defined.c b/security/keys/user_defined.c
index 36b47bbd3d8c..28cb30f80256 100644
--- a/security/keys/user_defined.c
+++ b/security/keys/user_defined.c
@@ -74,7 +74,7 @@ int user_preparse(struct key_preparsed_payload *prep)
74 74
75 /* attach the data */ 75 /* attach the data */
76 prep->quotalen = datalen; 76 prep->quotalen = datalen;
77 prep->payload[0] = upayload; 77 prep->payload.data[0] = upayload;
78 upayload->datalen = datalen; 78 upayload->datalen = datalen;
79 memcpy(upayload->data, prep->data, datalen); 79 memcpy(upayload->data, prep->data, datalen);
80 return 0; 80 return 0;
@@ -86,7 +86,7 @@ EXPORT_SYMBOL_GPL(user_preparse);
86 */ 86 */
87void user_free_preparse(struct key_preparsed_payload *prep) 87void user_free_preparse(struct key_preparsed_payload *prep)
88{ 88{
89 kfree(prep->payload[0]); 89 kfree(prep->payload.data[0]);
90} 90}
91EXPORT_SYMBOL_GPL(user_free_preparse); 91EXPORT_SYMBOL_GPL(user_free_preparse);
92 92
@@ -120,7 +120,7 @@ int user_update(struct key *key, struct key_preparsed_payload *prep)
120 120
121 if (ret == 0) { 121 if (ret == 0) {
122 /* attach the new data, displacing the old */ 122 /* attach the new data, displacing the old */
123 zap = key->payload.data; 123 zap = key->payload.data[0];
124 rcu_assign_keypointer(key, upayload); 124 rcu_assign_keypointer(key, upayload);
125 key->expiry = 0; 125 key->expiry = 0;
126 } 126 }
@@ -140,7 +140,7 @@ EXPORT_SYMBOL_GPL(user_update);
140 */ 140 */
141void user_revoke(struct key *key) 141void user_revoke(struct key *key)
142{ 142{
143 struct user_key_payload *upayload = key->payload.data; 143 struct user_key_payload *upayload = key->payload.data[0];
144 144
145 /* clear the quota */ 145 /* clear the quota */
146 key_payload_reserve(key, 0); 146 key_payload_reserve(key, 0);
@@ -158,7 +158,7 @@ EXPORT_SYMBOL(user_revoke);
158 */ 158 */
159void user_destroy(struct key *key) 159void user_destroy(struct key *key)
160{ 160{
161 struct user_key_payload *upayload = key->payload.data; 161 struct user_key_payload *upayload = key->payload.data[0];
162 162
163 kfree(upayload); 163 kfree(upayload);
164} 164}
@@ -183,10 +183,10 @@ EXPORT_SYMBOL_GPL(user_describe);
183 */ 183 */
184long user_read(const struct key *key, char __user *buffer, size_t buflen) 184long user_read(const struct key *key, char __user *buffer, size_t buflen)
185{ 185{
186 struct user_key_payload *upayload; 186 const struct user_key_payload *upayload;
187 long ret; 187 long ret;
188 188
189 upayload = rcu_dereference_key(key); 189 upayload = user_key_payload(key);
190 ret = upayload->datalen; 190 ret = upayload->datalen;
191 191
192 /* we can return the data as is */ 192 /* we can return the data as is */