aboutsummaryrefslogtreecommitdiffstats
path: root/net/rxrpc/ar-key.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/rxrpc/ar-key.c')
-rw-r--r--net/rxrpc/ar-key.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/net/rxrpc/ar-key.c b/net/rxrpc/ar-key.c
index 5ee16f0353fe..43ea7de2fc8e 100644
--- a/net/rxrpc/ar-key.c
+++ b/net/rxrpc/ar-key.c
@@ -25,6 +25,7 @@
25#include <keys/user-type.h> 25#include <keys/user-type.h>
26#include "ar-internal.h" 26#include "ar-internal.h"
27 27
28static int rxrpc_vet_description_s(const char *);
28static int rxrpc_instantiate(struct key *, const void *, size_t); 29static int rxrpc_instantiate(struct key *, const void *, size_t);
29static int rxrpc_instantiate_s(struct key *, const void *, size_t); 30static int rxrpc_instantiate_s(struct key *, const void *, size_t);
30static void rxrpc_destroy(struct key *); 31static void rxrpc_destroy(struct key *);
@@ -52,6 +53,7 @@ EXPORT_SYMBOL(key_type_rxrpc);
52 */ 53 */
53struct key_type key_type_rxrpc_s = { 54struct key_type key_type_rxrpc_s = {
54 .name = "rxrpc_s", 55 .name = "rxrpc_s",
56 .vet_description = rxrpc_vet_description_s,
55 .instantiate = rxrpc_instantiate_s, 57 .instantiate = rxrpc_instantiate_s,
56 .match = user_match, 58 .match = user_match,
57 .destroy = rxrpc_destroy_s, 59 .destroy = rxrpc_destroy_s,
@@ -59,6 +61,23 @@ struct key_type key_type_rxrpc_s = {
59}; 61};
60 62
61/* 63/*
64 * Vet the description for an RxRPC server key
65 */
66static int rxrpc_vet_description_s(const char *desc)
67{
68 unsigned long num;
69 char *p;
70
71 num = simple_strtoul(desc, &p, 10);
72 if (*p != ':' || num > 65535)
73 return -EINVAL;
74 num = simple_strtoul(p + 1, &p, 10);
75 if (*p || num < 1 || num > 255)
76 return -EINVAL;
77 return 0;
78}
79
80/*
62 * parse an RxKAD type XDR format token 81 * parse an RxKAD type XDR format token
63 * - the caller guarantees we have at least 4 words 82 * - the caller guarantees we have at least 4 words
64 */ 83 */
@@ -89,11 +108,11 @@ static int rxrpc_instantiate_xdr_rxkad(struct key *key, const __be32 *xdr,
89 return ret; 108 return ret;
90 109
91 plen -= sizeof(*token); 110 plen -= sizeof(*token);
92 token = kmalloc(sizeof(*token), GFP_KERNEL); 111 token = kzalloc(sizeof(*token), GFP_KERNEL);
93 if (!token) 112 if (!token)
94 return -ENOMEM; 113 return -ENOMEM;
95 114
96 token->kad = kmalloc(plen, GFP_KERNEL); 115 token->kad = kzalloc(plen, GFP_KERNEL);
97 if (!token->kad) { 116 if (!token->kad) {
98 kfree(token); 117 kfree(token);
99 return -ENOMEM; 118 return -ENOMEM;
@@ -731,10 +750,10 @@ static int rxrpc_instantiate(struct key *key, const void *data, size_t datalen)
731 goto error; 750 goto error;
732 751
733 ret = -ENOMEM; 752 ret = -ENOMEM;
734 token = kmalloc(sizeof(*token), GFP_KERNEL); 753 token = kzalloc(sizeof(*token), GFP_KERNEL);
735 if (!token) 754 if (!token)
736 goto error; 755 goto error;
737 token->kad = kmalloc(plen, GFP_KERNEL); 756 token->kad = kzalloc(plen, GFP_KERNEL);
738 if (!token->kad) 757 if (!token->kad)
739 goto error_free; 758 goto error_free;
740 759