diff options
author | David Howells <dhowells@redhat.com> | 2014-09-16 12:32:16 -0400 |
---|---|---|
committer | David Howells <dhowells@redhat.com> | 2014-09-16 12:32:16 -0400 |
commit | 68c45c7feaf1a8adebc6d9d77aa0a2018d974085 (patch) | |
tree | 3723e1d847b0626e07837db7c648ba63ade7e1a5 /crypto/asymmetric_keys | |
parent | ac60ab4b4968b54fb5af20eac9dd78e36ad910c1 (diff) | |
parent | cecf5d2e1208da512a4c951c24acd66c54a4d06c (diff) |
Merge tag 'keys-fixes-20140916' into keys-next
Merge in keyrings fixes, at least some of which later patches depend on:
(1) Reinstate the production of EPERM for key types beginning with '.' in
requests from userspace.
(2) Tidy up the cleanup of PKCS#7 message signed information blocks and fix a
bug this made more obvious.
Signed-off-by: David Howells <dhowells@redhat.coM>
Diffstat (limited to 'crypto/asymmetric_keys')
-rw-r--r-- | crypto/asymmetric_keys/pkcs7_parser.c | 61 |
1 files changed, 33 insertions, 28 deletions
diff --git a/crypto/asymmetric_keys/pkcs7_parser.c b/crypto/asymmetric_keys/pkcs7_parser.c index 42e56aa7d277..1e9861da7ee4 100644 --- a/crypto/asymmetric_keys/pkcs7_parser.c +++ b/crypto/asymmetric_keys/pkcs7_parser.c | |||
@@ -31,6 +31,18 @@ struct pkcs7_parse_context { | |||
31 | unsigned sinfo_index; | 31 | unsigned sinfo_index; |
32 | }; | 32 | }; |
33 | 33 | ||
34 | /* | ||
35 | * Free a signed information block. | ||
36 | */ | ||
37 | static void pkcs7_free_signed_info(struct pkcs7_signed_info *sinfo) | ||
38 | { | ||
39 | if (sinfo) { | ||
40 | mpi_free(sinfo->sig.mpi[0]); | ||
41 | kfree(sinfo->sig.digest); | ||
42 | kfree(sinfo); | ||
43 | } | ||
44 | } | ||
45 | |||
34 | /** | 46 | /** |
35 | * pkcs7_free_message - Free a PKCS#7 message | 47 | * pkcs7_free_message - Free a PKCS#7 message |
36 | * @pkcs7: The PKCS#7 message to free | 48 | * @pkcs7: The PKCS#7 message to free |
@@ -54,9 +66,7 @@ void pkcs7_free_message(struct pkcs7_message *pkcs7) | |||
54 | while (pkcs7->signed_infos) { | 66 | while (pkcs7->signed_infos) { |
55 | sinfo = pkcs7->signed_infos; | 67 | sinfo = pkcs7->signed_infos; |
56 | pkcs7->signed_infos = sinfo->next; | 68 | pkcs7->signed_infos = sinfo->next; |
57 | mpi_free(sinfo->sig.mpi[0]); | 69 | pkcs7_free_signed_info(sinfo); |
58 | kfree(sinfo->sig.digest); | ||
59 | kfree(sinfo); | ||
60 | } | 70 | } |
61 | kfree(pkcs7); | 71 | kfree(pkcs7); |
62 | } | 72 | } |
@@ -71,51 +81,46 @@ EXPORT_SYMBOL_GPL(pkcs7_free_message); | |||
71 | struct pkcs7_message *pkcs7_parse_message(const void *data, size_t datalen) | 81 | struct pkcs7_message *pkcs7_parse_message(const void *data, size_t datalen) |
72 | { | 82 | { |
73 | struct pkcs7_parse_context *ctx; | 83 | struct pkcs7_parse_context *ctx; |
74 | struct pkcs7_message *msg; | 84 | struct pkcs7_message *msg = ERR_PTR(-ENOMEM); |
75 | long ret; | 85 | int ret; |
76 | 86 | ||
77 | ret = -ENOMEM; | ||
78 | msg = kzalloc(sizeof(struct pkcs7_message), GFP_KERNEL); | ||
79 | if (!msg) | ||
80 | goto error_no_sig; | ||
81 | ctx = kzalloc(sizeof(struct pkcs7_parse_context), GFP_KERNEL); | 87 | ctx = kzalloc(sizeof(struct pkcs7_parse_context), GFP_KERNEL); |
82 | if (!ctx) | 88 | if (!ctx) |
83 | goto error_no_ctx; | 89 | goto out_no_ctx; |
90 | ctx->msg = kzalloc(sizeof(struct pkcs7_message), GFP_KERNEL); | ||
91 | if (!ctx->msg) | ||
92 | goto out_no_msg; | ||
84 | ctx->sinfo = kzalloc(sizeof(struct pkcs7_signed_info), GFP_KERNEL); | 93 | ctx->sinfo = kzalloc(sizeof(struct pkcs7_signed_info), GFP_KERNEL); |
85 | if (!ctx->sinfo) | 94 | if (!ctx->sinfo) |
86 | goto error_no_sinfo; | 95 | goto out_no_sinfo; |
87 | 96 | ||
88 | ctx->msg = msg; | ||
89 | ctx->data = (unsigned long)data; | 97 | ctx->data = (unsigned long)data; |
90 | ctx->ppcerts = &ctx->certs; | 98 | ctx->ppcerts = &ctx->certs; |
91 | ctx->ppsinfo = &ctx->msg->signed_infos; | 99 | ctx->ppsinfo = &ctx->msg->signed_infos; |
92 | 100 | ||
93 | /* Attempt to decode the signature */ | 101 | /* Attempt to decode the signature */ |
94 | ret = asn1_ber_decoder(&pkcs7_decoder, ctx, data, datalen); | 102 | ret = asn1_ber_decoder(&pkcs7_decoder, ctx, data, datalen); |
95 | if (ret < 0) | 103 | if (ret < 0) { |
96 | goto error_decode; | 104 | msg = ERR_PTR(ret); |
105 | goto out; | ||
106 | } | ||
107 | |||
108 | msg = ctx->msg; | ||
109 | ctx->msg = NULL; | ||
97 | 110 | ||
111 | out: | ||
98 | while (ctx->certs) { | 112 | while (ctx->certs) { |
99 | struct x509_certificate *cert = ctx->certs; | 113 | struct x509_certificate *cert = ctx->certs; |
100 | ctx->certs = cert->next; | 114 | ctx->certs = cert->next; |
101 | x509_free_certificate(cert); | 115 | x509_free_certificate(cert); |
102 | } | 116 | } |
103 | mpi_free(ctx->sinfo->sig.mpi[0]); | 117 | pkcs7_free_signed_info(ctx->sinfo); |
104 | kfree(ctx->sinfo->sig.digest); | 118 | out_no_sinfo: |
105 | kfree(ctx->sinfo); | 119 | pkcs7_free_message(ctx->msg); |
120 | out_no_msg: | ||
106 | kfree(ctx); | 121 | kfree(ctx); |
122 | out_no_ctx: | ||
107 | return msg; | 123 | return msg; |
108 | |||
109 | error_decode: | ||
110 | mpi_free(ctx->sinfo->sig.mpi[0]); | ||
111 | kfree(ctx->sinfo->sig.digest); | ||
112 | kfree(ctx->sinfo); | ||
113 | error_no_sinfo: | ||
114 | kfree(ctx); | ||
115 | error_no_ctx: | ||
116 | pkcs7_free_message(msg); | ||
117 | error_no_sig: | ||
118 | return ERR_PTR(ret); | ||
119 | } | 124 | } |
120 | EXPORT_SYMBOL_GPL(pkcs7_parse_message); | 125 | EXPORT_SYMBOL_GPL(pkcs7_parse_message); |
121 | 126 | ||