| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* Kerberos-based RxRPC security |
|---|
| 2 | 3 | * |
|---|
| 3 | 4 | * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. |
|---|
| 4 | 5 | * Written by David Howells (dhowells@redhat.com) |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or |
|---|
| 7 | | - * modify it under the terms of the GNU General Public License |
|---|
| 8 | | - * as published by the Free Software Foundation; either version |
|---|
| 9 | | - * 2 of the License, or (at your option) any later version. |
|---|
| 10 | 6 | */ |
|---|
| 11 | 7 | |
|---|
| 12 | 8 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
|---|
| .. | .. |
|---|
| 46 | 42 | * alloc routine, but since we have it to hand, we use it to decrypt RESPONSE |
|---|
| 47 | 43 | * packets |
|---|
| 48 | 44 | */ |
|---|
| 49 | | -static struct crypto_skcipher *rxkad_ci; |
|---|
| 45 | +static struct crypto_sync_skcipher *rxkad_ci; |
|---|
| 46 | +static struct skcipher_request *rxkad_ci_req; |
|---|
| 50 | 47 | static DEFINE_MUTEX(rxkad_ci_mutex); |
|---|
| 51 | 48 | |
|---|
| 52 | 49 | /* |
|---|
| .. | .. |
|---|
| 54 | 51 | */ |
|---|
| 55 | 52 | static int rxkad_init_connection_security(struct rxrpc_connection *conn) |
|---|
| 56 | 53 | { |
|---|
| 57 | | - struct crypto_skcipher *ci; |
|---|
| 54 | + struct crypto_sync_skcipher *ci; |
|---|
| 58 | 55 | struct rxrpc_key_token *token; |
|---|
| 59 | 56 | int ret; |
|---|
| 60 | 57 | |
|---|
| .. | .. |
|---|
| 63 | 60 | token = conn->params.key->payload.data[0]; |
|---|
| 64 | 61 | conn->security_ix = token->security_index; |
|---|
| 65 | 62 | |
|---|
| 66 | | - ci = crypto_alloc_skcipher("pcbc(fcrypt)", 0, CRYPTO_ALG_ASYNC); |
|---|
| 63 | + ci = crypto_alloc_sync_skcipher("pcbc(fcrypt)", 0, 0); |
|---|
| 67 | 64 | if (IS_ERR(ci)) { |
|---|
| 68 | 65 | _debug("no cipher"); |
|---|
| 69 | 66 | ret = PTR_ERR(ci); |
|---|
| 70 | 67 | goto error; |
|---|
| 71 | 68 | } |
|---|
| 72 | 69 | |
|---|
| 73 | | - if (crypto_skcipher_setkey(ci, token->kad->session_key, |
|---|
| 70 | + if (crypto_sync_skcipher_setkey(ci, token->kad->session_key, |
|---|
| 74 | 71 | sizeof(token->kad->session_key)) < 0) |
|---|
| 75 | 72 | BUG(); |
|---|
| 76 | 73 | |
|---|
| .. | .. |
|---|
| 103 | 100 | */ |
|---|
| 104 | 101 | static int rxkad_prime_packet_security(struct rxrpc_connection *conn) |
|---|
| 105 | 102 | { |
|---|
| 103 | + struct skcipher_request *req; |
|---|
| 106 | 104 | struct rxrpc_key_token *token; |
|---|
| 107 | | - SKCIPHER_REQUEST_ON_STACK(req, conn->cipher); |
|---|
| 108 | 105 | struct scatterlist sg; |
|---|
| 109 | 106 | struct rxrpc_crypt iv; |
|---|
| 110 | 107 | __be32 *tmpbuf; |
|---|
| .. | .. |
|---|
| 119 | 116 | if (!tmpbuf) |
|---|
| 120 | 117 | return -ENOMEM; |
|---|
| 121 | 118 | |
|---|
| 119 | + req = skcipher_request_alloc(&conn->cipher->base, GFP_NOFS); |
|---|
| 120 | + if (!req) { |
|---|
| 121 | + kfree(tmpbuf); |
|---|
| 122 | + return -ENOMEM; |
|---|
| 123 | + } |
|---|
| 124 | + |
|---|
| 122 | 125 | token = conn->params.key->payload.data[0]; |
|---|
| 123 | 126 | memcpy(&iv, token->kad->session_key, sizeof(iv)); |
|---|
| 124 | 127 | |
|---|
| .. | .. |
|---|
| 128 | 131 | tmpbuf[3] = htonl(conn->security_ix); |
|---|
| 129 | 132 | |
|---|
| 130 | 133 | sg_init_one(&sg, tmpbuf, tmpsize); |
|---|
| 131 | | - skcipher_request_set_tfm(req, conn->cipher); |
|---|
| 134 | + skcipher_request_set_sync_tfm(req, conn->cipher); |
|---|
| 132 | 135 | skcipher_request_set_callback(req, 0, NULL, NULL); |
|---|
| 133 | 136 | skcipher_request_set_crypt(req, &sg, &sg, tmpsize, iv.x); |
|---|
| 134 | 137 | crypto_skcipher_encrypt(req); |
|---|
| 135 | | - skcipher_request_zero(req); |
|---|
| 138 | + skcipher_request_free(req); |
|---|
| 136 | 139 | |
|---|
| 137 | 140 | memcpy(&conn->csum_iv, tmpbuf + 2, sizeof(conn->csum_iv)); |
|---|
| 138 | 141 | kfree(tmpbuf); |
|---|
| 139 | 142 | _leave(" = 0"); |
|---|
| 140 | 143 | return 0; |
|---|
| 144 | +} |
|---|
| 145 | + |
|---|
| 146 | +/* |
|---|
| 147 | + * Allocate and prepare the crypto request on a call. For any particular call, |
|---|
| 148 | + * this is called serially for the packets, so no lock should be necessary. |
|---|
| 149 | + */ |
|---|
| 150 | +static struct skcipher_request *rxkad_get_call_crypto(struct rxrpc_call *call) |
|---|
| 151 | +{ |
|---|
| 152 | + struct crypto_skcipher *tfm = &call->conn->cipher->base; |
|---|
| 153 | + struct skcipher_request *cipher_req = call->cipher_req; |
|---|
| 154 | + |
|---|
| 155 | + if (!cipher_req) { |
|---|
| 156 | + cipher_req = skcipher_request_alloc(tfm, GFP_NOFS); |
|---|
| 157 | + if (!cipher_req) |
|---|
| 158 | + return NULL; |
|---|
| 159 | + call->cipher_req = cipher_req; |
|---|
| 160 | + } |
|---|
| 161 | + |
|---|
| 162 | + return cipher_req; |
|---|
| 163 | +} |
|---|
| 164 | + |
|---|
| 165 | +/* |
|---|
| 166 | + * Clean up the crypto on a call. |
|---|
| 167 | + */ |
|---|
| 168 | +static void rxkad_free_call_crypto(struct rxrpc_call *call) |
|---|
| 169 | +{ |
|---|
| 170 | + if (call->cipher_req) |
|---|
| 171 | + skcipher_request_free(call->cipher_req); |
|---|
| 172 | + call->cipher_req = NULL; |
|---|
| 141 | 173 | } |
|---|
| 142 | 174 | |
|---|
| 143 | 175 | /* |
|---|
| .. | .. |
|---|
| 167 | 199 | memset(&iv, 0, sizeof(iv)); |
|---|
| 168 | 200 | |
|---|
| 169 | 201 | sg_init_one(&sg, sechdr, 8); |
|---|
| 170 | | - skcipher_request_set_tfm(req, call->conn->cipher); |
|---|
| 202 | + skcipher_request_set_sync_tfm(req, call->conn->cipher); |
|---|
| 171 | 203 | skcipher_request_set_callback(req, 0, NULL, NULL); |
|---|
| 172 | 204 | skcipher_request_set_crypt(req, &sg, &sg, 8, iv.x); |
|---|
| 173 | 205 | crypto_skcipher_encrypt(req); |
|---|
| .. | .. |
|---|
| 191 | 223 | struct rxrpc_skb_priv *sp; |
|---|
| 192 | 224 | struct rxrpc_crypt iv; |
|---|
| 193 | 225 | struct scatterlist sg[16]; |
|---|
| 194 | | - struct sk_buff *trailer; |
|---|
| 195 | 226 | unsigned int len; |
|---|
| 196 | 227 | u16 check; |
|---|
| 197 | | - int nsg; |
|---|
| 198 | 228 | int err; |
|---|
| 199 | 229 | |
|---|
| 200 | 230 | sp = rxrpc_skb(skb); |
|---|
| .. | .. |
|---|
| 212 | 242 | memcpy(&iv, token->kad->session_key, sizeof(iv)); |
|---|
| 213 | 243 | |
|---|
| 214 | 244 | sg_init_one(&sg[0], sechdr, sizeof(rxkhdr)); |
|---|
| 215 | | - skcipher_request_set_tfm(req, call->conn->cipher); |
|---|
| 245 | + skcipher_request_set_sync_tfm(req, call->conn->cipher); |
|---|
| 216 | 246 | skcipher_request_set_callback(req, 0, NULL, NULL); |
|---|
| 217 | 247 | skcipher_request_set_crypt(req, &sg[0], &sg[0], sizeof(rxkhdr), iv.x); |
|---|
| 218 | 248 | crypto_skcipher_encrypt(req); |
|---|
| 219 | 249 | |
|---|
| 220 | 250 | /* we want to encrypt the skbuff in-place */ |
|---|
| 221 | | - nsg = skb_cow_data(skb, 0, &trailer); |
|---|
| 222 | | - err = -ENOMEM; |
|---|
| 223 | | - if (nsg < 0 || nsg > 16) |
|---|
| 251 | + err = -EMSGSIZE; |
|---|
| 252 | + if (skb_shinfo(skb)->nr_frags > 16) |
|---|
| 224 | 253 | goto out; |
|---|
| 225 | 254 | |
|---|
| 226 | 255 | len = data_size + call->conn->size_align - 1; |
|---|
| 227 | 256 | len &= ~(call->conn->size_align - 1); |
|---|
| 228 | 257 | |
|---|
| 229 | | - sg_init_table(sg, nsg); |
|---|
| 258 | + sg_init_table(sg, ARRAY_SIZE(sg)); |
|---|
| 230 | 259 | err = skb_to_sgvec(skb, sg, 0, len); |
|---|
| 231 | 260 | if (unlikely(err < 0)) |
|---|
| 232 | 261 | goto out; |
|---|
| .. | .. |
|---|
| 250 | 279 | void *sechdr) |
|---|
| 251 | 280 | { |
|---|
| 252 | 281 | struct rxrpc_skb_priv *sp; |
|---|
| 253 | | - SKCIPHER_REQUEST_ON_STACK(req, call->conn->cipher); |
|---|
| 282 | + struct skcipher_request *req; |
|---|
| 254 | 283 | struct rxrpc_crypt iv; |
|---|
| 255 | 284 | struct scatterlist sg; |
|---|
| 256 | 285 | u32 x, y; |
|---|
| .. | .. |
|---|
| 269 | 298 | if (ret < 0) |
|---|
| 270 | 299 | return ret; |
|---|
| 271 | 300 | |
|---|
| 301 | + req = rxkad_get_call_crypto(call); |
|---|
| 302 | + if (!req) |
|---|
| 303 | + return -ENOMEM; |
|---|
| 304 | + |
|---|
| 272 | 305 | /* continue encrypting from where we left off */ |
|---|
| 273 | 306 | memcpy(&iv, call->conn->csum_iv.x, sizeof(iv)); |
|---|
| 274 | 307 | |
|---|
| .. | .. |
|---|
| 279 | 312 | call->crypto_buf[1] = htonl(x); |
|---|
| 280 | 313 | |
|---|
| 281 | 314 | sg_init_one(&sg, call->crypto_buf, 8); |
|---|
| 282 | | - skcipher_request_set_tfm(req, call->conn->cipher); |
|---|
| 315 | + skcipher_request_set_sync_tfm(req, call->conn->cipher); |
|---|
| 283 | 316 | skcipher_request_set_callback(req, 0, NULL, NULL); |
|---|
| 284 | 317 | skcipher_request_set_crypt(req, &sg, &sg, 8, iv.x); |
|---|
| 285 | 318 | crypto_skcipher_encrypt(req); |
|---|
| .. | .. |
|---|
| 323 | 356 | struct rxkad_level1_hdr sechdr; |
|---|
| 324 | 357 | struct rxrpc_crypt iv; |
|---|
| 325 | 358 | struct scatterlist sg[16]; |
|---|
| 326 | | - struct sk_buff *trailer; |
|---|
| 327 | 359 | bool aborted; |
|---|
| 328 | 360 | u32 data_size, buf; |
|---|
| 329 | 361 | u16 check; |
|---|
| 330 | | - int nsg, ret; |
|---|
| 362 | + int ret; |
|---|
| 331 | 363 | |
|---|
| 332 | 364 | _enter(""); |
|---|
| 333 | 365 | |
|---|
| .. | .. |
|---|
| 340 | 372 | /* Decrypt the skbuff in-place. TODO: We really want to decrypt |
|---|
| 341 | 373 | * directly into the target buffer. |
|---|
| 342 | 374 | */ |
|---|
| 343 | | - nsg = skb_cow_data(skb, 0, &trailer); |
|---|
| 344 | | - if (nsg < 0 || nsg > 16) |
|---|
| 345 | | - goto nomem; |
|---|
| 346 | | - |
|---|
| 347 | | - sg_init_table(sg, nsg); |
|---|
| 375 | + sg_init_table(sg, ARRAY_SIZE(sg)); |
|---|
| 348 | 376 | ret = skb_to_sgvec(skb, sg, offset, 8); |
|---|
| 349 | 377 | if (unlikely(ret < 0)) |
|---|
| 350 | 378 | return ret; |
|---|
| .. | .. |
|---|
| 352 | 380 | /* start the decryption afresh */ |
|---|
| 353 | 381 | memset(&iv, 0, sizeof(iv)); |
|---|
| 354 | 382 | |
|---|
| 355 | | - skcipher_request_set_tfm(req, call->conn->cipher); |
|---|
| 383 | + skcipher_request_set_sync_tfm(req, call->conn->cipher); |
|---|
| 356 | 384 | skcipher_request_set_callback(req, 0, NULL, NULL); |
|---|
| 357 | 385 | skcipher_request_set_crypt(req, sg, sg, 8, iv.x); |
|---|
| 358 | 386 | crypto_skcipher_decrypt(req); |
|---|
| .. | .. |
|---|
| 392 | 420 | if (aborted) |
|---|
| 393 | 421 | rxrpc_send_abort_packet(call); |
|---|
| 394 | 422 | return -EPROTO; |
|---|
| 395 | | - |
|---|
| 396 | | -nomem: |
|---|
| 397 | | - _leave(" = -ENOMEM"); |
|---|
| 398 | | - return -ENOMEM; |
|---|
| 399 | 423 | } |
|---|
| 400 | 424 | |
|---|
| 401 | 425 | /* |
|---|
| .. | .. |
|---|
| 410 | 434 | struct rxkad_level2_hdr sechdr; |
|---|
| 411 | 435 | struct rxrpc_crypt iv; |
|---|
| 412 | 436 | struct scatterlist _sg[4], *sg; |
|---|
| 413 | | - struct sk_buff *trailer; |
|---|
| 414 | 437 | bool aborted; |
|---|
| 415 | 438 | u32 data_size, buf; |
|---|
| 416 | 439 | u16 check; |
|---|
| .. | .. |
|---|
| 427 | 450 | /* Decrypt the skbuff in-place. TODO: We really want to decrypt |
|---|
| 428 | 451 | * directly into the target buffer. |
|---|
| 429 | 452 | */ |
|---|
| 430 | | - nsg = skb_cow_data(skb, 0, &trailer); |
|---|
| 431 | | - if (nsg < 0) |
|---|
| 432 | | - goto nomem; |
|---|
| 433 | | - |
|---|
| 434 | 453 | sg = _sg; |
|---|
| 435 | | - if (unlikely(nsg > 4)) { |
|---|
| 454 | + nsg = skb_shinfo(skb)->nr_frags + 1; |
|---|
| 455 | + if (nsg <= 4) { |
|---|
| 456 | + nsg = 4; |
|---|
| 457 | + } else { |
|---|
| 436 | 458 | sg = kmalloc_array(nsg, sizeof(*sg), GFP_NOIO); |
|---|
| 437 | 459 | if (!sg) |
|---|
| 438 | 460 | goto nomem; |
|---|
| .. | .. |
|---|
| 450 | 472 | token = call->conn->params.key->payload.data[0]; |
|---|
| 451 | 473 | memcpy(&iv, token->kad->session_key, sizeof(iv)); |
|---|
| 452 | 474 | |
|---|
| 453 | | - skcipher_request_set_tfm(req, call->conn->cipher); |
|---|
| 475 | + skcipher_request_set_sync_tfm(req, call->conn->cipher); |
|---|
| 454 | 476 | skcipher_request_set_callback(req, 0, NULL, NULL); |
|---|
| 455 | 477 | skcipher_request_set_crypt(req, sg, sg, len, iv.x); |
|---|
| 456 | 478 | crypto_skcipher_decrypt(req); |
|---|
| .. | .. |
|---|
| 506 | 528 | unsigned int offset, unsigned int len, |
|---|
| 507 | 529 | rxrpc_seq_t seq, u16 expected_cksum) |
|---|
| 508 | 530 | { |
|---|
| 509 | | - SKCIPHER_REQUEST_ON_STACK(req, call->conn->cipher); |
|---|
| 531 | + struct skcipher_request *req; |
|---|
| 510 | 532 | struct rxrpc_crypt iv; |
|---|
| 511 | 533 | struct scatterlist sg; |
|---|
| 512 | 534 | bool aborted; |
|---|
| .. | .. |
|---|
| 519 | 541 | if (!call->conn->cipher) |
|---|
| 520 | 542 | return 0; |
|---|
| 521 | 543 | |
|---|
| 544 | + req = rxkad_get_call_crypto(call); |
|---|
| 545 | + if (!req) |
|---|
| 546 | + return -ENOMEM; |
|---|
| 547 | + |
|---|
| 522 | 548 | /* continue encrypting from where we left off */ |
|---|
| 523 | 549 | memcpy(&iv, call->conn->csum_iv.x, sizeof(iv)); |
|---|
| 524 | 550 | |
|---|
| .. | .. |
|---|
| 529 | 555 | call->crypto_buf[1] = htonl(x); |
|---|
| 530 | 556 | |
|---|
| 531 | 557 | sg_init_one(&sg, call->crypto_buf, 8); |
|---|
| 532 | | - skcipher_request_set_tfm(req, call->conn->cipher); |
|---|
| 558 | + skcipher_request_set_sync_tfm(req, call->conn->cipher); |
|---|
| 533 | 559 | skcipher_request_set_callback(req, 0, NULL, NULL); |
|---|
| 534 | 560 | skcipher_request_set_crypt(req, &sg, &sg, 8, iv.x); |
|---|
| 535 | 561 | crypto_skcipher_encrypt(req); |
|---|
| .. | .. |
|---|
| 622 | 648 | u32 serial; |
|---|
| 623 | 649 | int ret; |
|---|
| 624 | 650 | |
|---|
| 625 | | - _enter("{%d,%x}", conn->debug_id, key_serial(conn->params.key)); |
|---|
| 651 | + _enter("{%d,%x}", conn->debug_id, key_serial(conn->server_key)); |
|---|
| 626 | 652 | |
|---|
| 627 | | - ret = key_validate(conn->params.key); |
|---|
| 653 | + ret = key_validate(conn->server_key); |
|---|
| 628 | 654 | if (ret < 0) |
|---|
| 629 | 655 | return ret; |
|---|
| 630 | 656 | |
|---|
| .. | .. |
|---|
| 751 | 777 | /* |
|---|
| 752 | 778 | * encrypt the response packet |
|---|
| 753 | 779 | */ |
|---|
| 754 | | -static void rxkad_encrypt_response(struct rxrpc_connection *conn, |
|---|
| 755 | | - struct rxkad_response *resp, |
|---|
| 756 | | - const struct rxkad_key *s2) |
|---|
| 780 | +static int rxkad_encrypt_response(struct rxrpc_connection *conn, |
|---|
| 781 | + struct rxkad_response *resp, |
|---|
| 782 | + const struct rxkad_key *s2) |
|---|
| 757 | 783 | { |
|---|
| 758 | | - SKCIPHER_REQUEST_ON_STACK(req, conn->cipher); |
|---|
| 784 | + struct skcipher_request *req; |
|---|
| 759 | 785 | struct rxrpc_crypt iv; |
|---|
| 760 | 786 | struct scatterlist sg[1]; |
|---|
| 787 | + |
|---|
| 788 | + req = skcipher_request_alloc(&conn->cipher->base, GFP_NOFS); |
|---|
| 789 | + if (!req) |
|---|
| 790 | + return -ENOMEM; |
|---|
| 761 | 791 | |
|---|
| 762 | 792 | /* continue encrypting from where we left off */ |
|---|
| 763 | 793 | memcpy(&iv, s2->session_key, sizeof(iv)); |
|---|
| 764 | 794 | |
|---|
| 765 | 795 | sg_init_table(sg, 1); |
|---|
| 766 | 796 | sg_set_buf(sg, &resp->encrypted, sizeof(resp->encrypted)); |
|---|
| 767 | | - skcipher_request_set_tfm(req, conn->cipher); |
|---|
| 797 | + skcipher_request_set_sync_tfm(req, conn->cipher); |
|---|
| 768 | 798 | skcipher_request_set_callback(req, 0, NULL, NULL); |
|---|
| 769 | 799 | skcipher_request_set_crypt(req, sg, sg, sizeof(resp->encrypted), iv.x); |
|---|
| 770 | 800 | crypto_skcipher_encrypt(req); |
|---|
| 771 | | - skcipher_request_zero(req); |
|---|
| 801 | + skcipher_request_free(req); |
|---|
| 802 | + return 0; |
|---|
| 772 | 803 | } |
|---|
| 773 | 804 | |
|---|
| 774 | 805 | /* |
|---|
| .. | .. |
|---|
| 843 | 874 | |
|---|
| 844 | 875 | /* calculate the response checksum and then do the encryption */ |
|---|
| 845 | 876 | rxkad_calc_response_checksum(resp); |
|---|
| 846 | | - rxkad_encrypt_response(conn, resp, token->kad); |
|---|
| 847 | | - ret = rxkad_send_response(conn, &sp->hdr, resp, token->kad); |
|---|
| 877 | + ret = rxkad_encrypt_response(conn, resp, token->kad); |
|---|
| 878 | + if (ret == 0) |
|---|
| 879 | + ret = rxkad_send_response(conn, &sp->hdr, resp, token->kad); |
|---|
| 848 | 880 | kfree(resp); |
|---|
| 849 | 881 | return ret; |
|---|
| 850 | 882 | |
|---|
| .. | .. |
|---|
| 1021 | 1053 | struct rxkad_response *resp, |
|---|
| 1022 | 1054 | const struct rxrpc_crypt *session_key) |
|---|
| 1023 | 1055 | { |
|---|
| 1024 | | - SKCIPHER_REQUEST_ON_STACK(req, rxkad_ci); |
|---|
| 1056 | + struct skcipher_request *req = rxkad_ci_req; |
|---|
| 1025 | 1057 | struct scatterlist sg[1]; |
|---|
| 1026 | 1058 | struct rxrpc_crypt iv; |
|---|
| 1027 | 1059 | |
|---|
| 1028 | 1060 | _enter(",,%08x%08x", |
|---|
| 1029 | 1061 | ntohl(session_key->n[0]), ntohl(session_key->n[1])); |
|---|
| 1030 | 1062 | |
|---|
| 1031 | | - ASSERT(rxkad_ci != NULL); |
|---|
| 1032 | | - |
|---|
| 1033 | 1063 | mutex_lock(&rxkad_ci_mutex); |
|---|
| 1034 | | - if (crypto_skcipher_setkey(rxkad_ci, session_key->x, |
|---|
| 1035 | | - sizeof(*session_key)) < 0) |
|---|
| 1064 | + if (crypto_sync_skcipher_setkey(rxkad_ci, session_key->x, |
|---|
| 1065 | + sizeof(*session_key)) < 0) |
|---|
| 1036 | 1066 | BUG(); |
|---|
| 1037 | 1067 | |
|---|
| 1038 | 1068 | memcpy(&iv, session_key, sizeof(iv)); |
|---|
| 1039 | 1069 | |
|---|
| 1040 | 1070 | sg_init_table(sg, 1); |
|---|
| 1041 | 1071 | sg_set_buf(sg, &resp->encrypted, sizeof(resp->encrypted)); |
|---|
| 1042 | | - skcipher_request_set_tfm(req, rxkad_ci); |
|---|
| 1072 | + skcipher_request_set_sync_tfm(req, rxkad_ci); |
|---|
| 1043 | 1073 | skcipher_request_set_callback(req, 0, NULL, NULL); |
|---|
| 1044 | 1074 | skcipher_request_set_crypt(req, sg, sg, sizeof(resp->encrypted), iv.x); |
|---|
| 1045 | 1075 | crypto_skcipher_decrypt(req); |
|---|
| .. | .. |
|---|
| 1107 | 1137 | ret = -ENOMEM; |
|---|
| 1108 | 1138 | ticket = kmalloc(ticket_len, GFP_NOFS); |
|---|
| 1109 | 1139 | if (!ticket) |
|---|
| 1110 | | - goto temporary_error; |
|---|
| 1140 | + goto temporary_error_free_resp; |
|---|
| 1111 | 1141 | |
|---|
| 1112 | 1142 | eproto = tracepoint_string("rxkad_tkt_short"); |
|---|
| 1113 | 1143 | abort_code = RXKADPACKETSHORT; |
|---|
| .. | .. |
|---|
| 1139 | 1169 | if (response->encrypted.checksum != csum) |
|---|
| 1140 | 1170 | goto protocol_error_free; |
|---|
| 1141 | 1171 | |
|---|
| 1142 | | - spin_lock(&conn->channel_lock); |
|---|
| 1172 | + spin_lock(&conn->bundle->channel_lock); |
|---|
| 1143 | 1173 | for (i = 0; i < RXRPC_MAXCALLS; i++) { |
|---|
| 1144 | 1174 | struct rxrpc_call *call; |
|---|
| 1145 | 1175 | u32 call_id = ntohl(response->encrypted.call_id[i]); |
|---|
| .. | .. |
|---|
| 1156 | 1186 | if (call_id > conn->channels[i].call_counter) { |
|---|
| 1157 | 1187 | call = rcu_dereference_protected( |
|---|
| 1158 | 1188 | conn->channels[i].call, |
|---|
| 1159 | | - lockdep_is_held(&conn->channel_lock)); |
|---|
| 1189 | + lockdep_is_held(&conn->bundle->channel_lock)); |
|---|
| 1160 | 1190 | if (call && call->state < RXRPC_CALL_COMPLETE) |
|---|
| 1161 | 1191 | goto protocol_error_unlock; |
|---|
| 1162 | 1192 | conn->channels[i].call_counter = call_id; |
|---|
| 1163 | 1193 | } |
|---|
| 1164 | 1194 | } |
|---|
| 1165 | | - spin_unlock(&conn->channel_lock); |
|---|
| 1195 | + spin_unlock(&conn->bundle->channel_lock); |
|---|
| 1166 | 1196 | |
|---|
| 1167 | 1197 | eproto = tracepoint_string("rxkad_rsp_seq"); |
|---|
| 1168 | 1198 | abort_code = RXKADOUTOFSEQUENCE; |
|---|
| .. | .. |
|---|
| 1189 | 1219 | return 0; |
|---|
| 1190 | 1220 | |
|---|
| 1191 | 1221 | protocol_error_unlock: |
|---|
| 1192 | | - spin_unlock(&conn->channel_lock); |
|---|
| 1222 | + spin_unlock(&conn->bundle->channel_lock); |
|---|
| 1193 | 1223 | protocol_error_free: |
|---|
| 1194 | 1224 | kfree(ticket); |
|---|
| 1195 | 1225 | protocol_error: |
|---|
| .. | .. |
|---|
| 1200 | 1230 | |
|---|
| 1201 | 1231 | temporary_error_free_ticket: |
|---|
| 1202 | 1232 | kfree(ticket); |
|---|
| 1233 | +temporary_error_free_resp: |
|---|
| 1203 | 1234 | kfree(response); |
|---|
| 1204 | 1235 | temporary_error: |
|---|
| 1205 | 1236 | /* Ignore the response packet if we got a temporary error such as |
|---|
| .. | .. |
|---|
| 1217 | 1248 | _enter(""); |
|---|
| 1218 | 1249 | |
|---|
| 1219 | 1250 | if (conn->cipher) |
|---|
| 1220 | | - crypto_free_skcipher(conn->cipher); |
|---|
| 1251 | + crypto_free_sync_skcipher(conn->cipher); |
|---|
| 1221 | 1252 | } |
|---|
| 1222 | 1253 | |
|---|
| 1223 | 1254 | /* |
|---|
| .. | .. |
|---|
| 1225 | 1256 | */ |
|---|
| 1226 | 1257 | static int rxkad_init(void) |
|---|
| 1227 | 1258 | { |
|---|
| 1259 | + struct crypto_sync_skcipher *tfm; |
|---|
| 1260 | + struct skcipher_request *req; |
|---|
| 1261 | + |
|---|
| 1228 | 1262 | /* pin the cipher we need so that the crypto layer doesn't invoke |
|---|
| 1229 | 1263 | * keventd to go get it */ |
|---|
| 1230 | | - rxkad_ci = crypto_alloc_skcipher("pcbc(fcrypt)", 0, CRYPTO_ALG_ASYNC); |
|---|
| 1231 | | - return PTR_ERR_OR_ZERO(rxkad_ci); |
|---|
| 1264 | + tfm = crypto_alloc_sync_skcipher("pcbc(fcrypt)", 0, 0); |
|---|
| 1265 | + if (IS_ERR(tfm)) |
|---|
| 1266 | + return PTR_ERR(tfm); |
|---|
| 1267 | + |
|---|
| 1268 | + req = skcipher_request_alloc(&tfm->base, GFP_KERNEL); |
|---|
| 1269 | + if (!req) |
|---|
| 1270 | + goto nomem_tfm; |
|---|
| 1271 | + |
|---|
| 1272 | + rxkad_ci_req = req; |
|---|
| 1273 | + rxkad_ci = tfm; |
|---|
| 1274 | + return 0; |
|---|
| 1275 | + |
|---|
| 1276 | +nomem_tfm: |
|---|
| 1277 | + crypto_free_sync_skcipher(tfm); |
|---|
| 1278 | + return -ENOMEM; |
|---|
| 1232 | 1279 | } |
|---|
| 1233 | 1280 | |
|---|
| 1234 | 1281 | /* |
|---|
| .. | .. |
|---|
| 1236 | 1283 | */ |
|---|
| 1237 | 1284 | static void rxkad_exit(void) |
|---|
| 1238 | 1285 | { |
|---|
| 1239 | | - if (rxkad_ci) |
|---|
| 1240 | | - crypto_free_skcipher(rxkad_ci); |
|---|
| 1286 | + crypto_free_sync_skcipher(rxkad_ci); |
|---|
| 1287 | + skcipher_request_free(rxkad_ci_req); |
|---|
| 1241 | 1288 | } |
|---|
| 1242 | 1289 | |
|---|
| 1243 | 1290 | /* |
|---|
| .. | .. |
|---|
| 1246 | 1293 | const struct rxrpc_security rxkad = { |
|---|
| 1247 | 1294 | .name = "rxkad", |
|---|
| 1248 | 1295 | .security_index = RXRPC_SECURITY_RXKAD, |
|---|
| 1296 | + .no_key_abort = RXKADUNKNOWNKEY, |
|---|
| 1249 | 1297 | .init = rxkad_init, |
|---|
| 1250 | 1298 | .exit = rxkad_exit, |
|---|
| 1251 | 1299 | .init_connection_security = rxkad_init_connection_security, |
|---|
| 1252 | 1300 | .prime_packet_security = rxkad_prime_packet_security, |
|---|
| 1253 | 1301 | .secure_packet = rxkad_secure_packet, |
|---|
| 1254 | 1302 | .verify_packet = rxkad_verify_packet, |
|---|
| 1303 | + .free_call_crypto = rxkad_free_call_crypto, |
|---|
| 1255 | 1304 | .locate_data = rxkad_locate_data, |
|---|
| 1256 | 1305 | .issue_challenge = rxkad_issue_challenge, |
|---|
| 1257 | 1306 | .respond_to_challenge = rxkad_respond_to_challenge, |
|---|