diff options
-rw-r--r-- | net/tls/tls_sw.c | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c index 34895b7c132d..2945a3bd538c 100644 --- a/net/tls/tls_sw.c +++ b/net/tls/tls_sw.c | |||
@@ -191,18 +191,12 @@ static void tls_free_both_sg(struct sock *sk) | |||
191 | } | 191 | } |
192 | 192 | ||
193 | static int tls_do_encryption(struct tls_context *tls_ctx, | 193 | static int tls_do_encryption(struct tls_context *tls_ctx, |
194 | struct tls_sw_context_tx *ctx, size_t data_len, | 194 | struct tls_sw_context_tx *ctx, |
195 | gfp_t flags) | 195 | struct aead_request *aead_req, |
196 | size_t data_len) | ||
196 | { | 197 | { |
197 | unsigned int req_size = sizeof(struct aead_request) + | ||
198 | crypto_aead_reqsize(ctx->aead_send); | ||
199 | struct aead_request *aead_req; | ||
200 | int rc; | 198 | int rc; |
201 | 199 | ||
202 | aead_req = kzalloc(req_size, flags); | ||
203 | if (!aead_req) | ||
204 | return -ENOMEM; | ||
205 | |||
206 | ctx->sg_encrypted_data[0].offset += tls_ctx->tx.prepend_size; | 200 | ctx->sg_encrypted_data[0].offset += tls_ctx->tx.prepend_size; |
207 | ctx->sg_encrypted_data[0].length -= tls_ctx->tx.prepend_size; | 201 | ctx->sg_encrypted_data[0].length -= tls_ctx->tx.prepend_size; |
208 | 202 | ||
@@ -219,7 +213,6 @@ static int tls_do_encryption(struct tls_context *tls_ctx, | |||
219 | ctx->sg_encrypted_data[0].offset -= tls_ctx->tx.prepend_size; | 213 | ctx->sg_encrypted_data[0].offset -= tls_ctx->tx.prepend_size; |
220 | ctx->sg_encrypted_data[0].length += tls_ctx->tx.prepend_size; | 214 | ctx->sg_encrypted_data[0].length += tls_ctx->tx.prepend_size; |
221 | 215 | ||
222 | kfree(aead_req); | ||
223 | return rc; | 216 | return rc; |
224 | } | 217 | } |
225 | 218 | ||
@@ -228,8 +221,14 @@ static int tls_push_record(struct sock *sk, int flags, | |||
228 | { | 221 | { |
229 | struct tls_context *tls_ctx = tls_get_ctx(sk); | 222 | struct tls_context *tls_ctx = tls_get_ctx(sk); |
230 | struct tls_sw_context_tx *ctx = tls_sw_ctx_tx(tls_ctx); | 223 | struct tls_sw_context_tx *ctx = tls_sw_ctx_tx(tls_ctx); |
224 | struct aead_request *req; | ||
231 | int rc; | 225 | int rc; |
232 | 226 | ||
227 | req = kzalloc(sizeof(struct aead_request) + | ||
228 | crypto_aead_reqsize(ctx->aead_send), sk->sk_allocation); | ||
229 | if (!req) | ||
230 | return -ENOMEM; | ||
231 | |||
233 | sg_mark_end(ctx->sg_plaintext_data + ctx->sg_plaintext_num_elem - 1); | 232 | sg_mark_end(ctx->sg_plaintext_data + ctx->sg_plaintext_num_elem - 1); |
234 | sg_mark_end(ctx->sg_encrypted_data + ctx->sg_encrypted_num_elem - 1); | 233 | sg_mark_end(ctx->sg_encrypted_data + ctx->sg_encrypted_num_elem - 1); |
235 | 234 | ||
@@ -245,15 +244,14 @@ static int tls_push_record(struct sock *sk, int flags, | |||
245 | tls_ctx->pending_open_record_frags = 0; | 244 | tls_ctx->pending_open_record_frags = 0; |
246 | set_bit(TLS_PENDING_CLOSED_RECORD, &tls_ctx->flags); | 245 | set_bit(TLS_PENDING_CLOSED_RECORD, &tls_ctx->flags); |
247 | 246 | ||
248 | rc = tls_do_encryption(tls_ctx, ctx, ctx->sg_plaintext_size, | 247 | rc = tls_do_encryption(tls_ctx, ctx, req, ctx->sg_plaintext_size); |
249 | sk->sk_allocation); | ||
250 | if (rc < 0) { | 248 | if (rc < 0) { |
251 | /* If we are called from write_space and | 249 | /* If we are called from write_space and |
252 | * we fail, we need to set this SOCK_NOSPACE | 250 | * we fail, we need to set this SOCK_NOSPACE |
253 | * to trigger another write_space in the future. | 251 | * to trigger another write_space in the future. |
254 | */ | 252 | */ |
255 | set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); | 253 | set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); |
256 | return rc; | 254 | goto out_req; |
257 | } | 255 | } |
258 | 256 | ||
259 | free_sg(sk, ctx->sg_plaintext_data, &ctx->sg_plaintext_num_elem, | 257 | free_sg(sk, ctx->sg_plaintext_data, &ctx->sg_plaintext_num_elem, |
@@ -268,6 +266,8 @@ static int tls_push_record(struct sock *sk, int flags, | |||
268 | tls_err_abort(sk, EBADMSG); | 266 | tls_err_abort(sk, EBADMSG); |
269 | 267 | ||
270 | tls_advance_record_sn(sk, &tls_ctx->tx); | 268 | tls_advance_record_sn(sk, &tls_ctx->tx); |
269 | out_req: | ||
270 | kfree(req); | ||
271 | return rc; | 271 | return rc; |
272 | } | 272 | } |
273 | 273 | ||