Skip to content

Commit 06149fc

Browse files
committed
rxrpc: Allocate an skcipher each time needed rather than reusing
jira LE-1907 Rebuild_History Non-Buildable kernel-5.14.0-284.30.1.el9_2 commit-author David Howells <[email protected]> commit 30d95ef In the rxkad security class, allocate the skcipher used to do packet encryption and decription rather than allocating one up front and reusing it for each packet. Reusing the skcipher precludes doing crypto in parallel. Signed-off-by: David Howells <[email protected]> cc: Marc Dionne <[email protected]> cc: [email protected] (cherry picked from commit 30d95ef) Signed-off-by: Jonathan Maple <[email protected]>
1 parent 1952ffe commit 06149fc

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

net/rxrpc/ar-internal.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,6 @@ struct rxrpc_call {
583583
unsigned long expect_term_by; /* When we expect call termination by */
584584
u32 next_rx_timo; /* Timeout for next Rx packet (jif) */
585585
u32 next_req_timo; /* Timeout for next Rx request packet (jif) */
586-
struct skcipher_request *cipher_req; /* Packet cipher request buffer */
587586
struct timer_list timer; /* Combined event timer */
588587
struct work_struct processor; /* Event processor */
589588
rxrpc_notify_rx_t notify_rx; /* kernel service Rx notification function */
@@ -597,7 +596,6 @@ struct rxrpc_call {
597596
struct rxrpc_txbuf *tx_pending; /* Tx buffer being filled */
598597
wait_queue_head_t waitq; /* Wait queue for channel or Tx */
599598
s64 tx_total_len; /* Total length left to be transmitted (or -1) */
600-
__be32 crypto_buf[2]; /* Temporary packet crypto buffer */
601599
unsigned long user_call_ID; /* user-defined call ID */
602600
unsigned long flags;
603601
unsigned long events;

net/rxrpc/rxkad.c

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -233,26 +233,15 @@ static int rxkad_prime_packet_security(struct rxrpc_connection *conn,
233233
static struct skcipher_request *rxkad_get_call_crypto(struct rxrpc_call *call)
234234
{
235235
struct crypto_skcipher *tfm = &call->conn->rxkad.cipher->base;
236-
struct skcipher_request *cipher_req = call->cipher_req;
237236

238-
if (!cipher_req) {
239-
cipher_req = skcipher_request_alloc(tfm, GFP_NOFS);
240-
if (!cipher_req)
241-
return NULL;
242-
call->cipher_req = cipher_req;
243-
}
244-
245-
return cipher_req;
237+
return skcipher_request_alloc(tfm, GFP_NOFS);
246238
}
247239

248240
/*
249241
* Clean up the crypto on a call.
250242
*/
251243
static void rxkad_free_call_crypto(struct rxrpc_call *call)
252244
{
253-
if (call->cipher_req)
254-
skcipher_request_free(call->cipher_req);
255-
call->cipher_req = NULL;
256245
}
257246

258247
/*
@@ -348,6 +337,9 @@ static int rxkad_secure_packet(struct rxrpc_call *call, struct rxrpc_txbuf *txb)
348337
struct skcipher_request *req;
349338
struct rxrpc_crypt iv;
350339
struct scatterlist sg;
340+
union {
341+
__be32 buf[2];
342+
} crypto __aligned(8);
351343
u32 x, y;
352344
int ret;
353345

@@ -372,17 +364,17 @@ static int rxkad_secure_packet(struct rxrpc_call *call, struct rxrpc_txbuf *txb)
372364
/* calculate the security checksum */
373365
x = (ntohl(txb->wire.cid) & RXRPC_CHANNELMASK) << (32 - RXRPC_CIDSHIFT);
374366
x |= txb->seq & 0x3fffffff;
375-
call->crypto_buf[0] = txb->wire.callNumber;
376-
call->crypto_buf[1] = htonl(x);
367+
crypto.buf[0] = txb->wire.callNumber;
368+
crypto.buf[1] = htonl(x);
377369

378-
sg_init_one(&sg, call->crypto_buf, 8);
370+
sg_init_one(&sg, crypto.buf, 8);
379371
skcipher_request_set_sync_tfm(req, call->conn->rxkad.cipher);
380372
skcipher_request_set_callback(req, 0, NULL, NULL);
381373
skcipher_request_set_crypt(req, &sg, &sg, 8, iv.x);
382374
crypto_skcipher_encrypt(req);
383375
skcipher_request_zero(req);
384376

385-
y = ntohl(call->crypto_buf[1]);
377+
y = ntohl(crypto.buf[1]);
386378
y = (y >> 16) & 0xffff;
387379
if (y == 0)
388380
y = 1; /* zero checksums are not permitted */
@@ -403,6 +395,7 @@ static int rxkad_secure_packet(struct rxrpc_call *call, struct rxrpc_txbuf *txb)
403395
break;
404396
}
405397

398+
skcipher_request_free(req);
406399
_leave(" = %d [set %x]", ret, y);
407400
return ret;
408401
}
@@ -593,8 +586,12 @@ static int rxkad_verify_packet(struct rxrpc_call *call, struct sk_buff *skb)
593586
struct skcipher_request *req;
594587
struct rxrpc_crypt iv;
595588
struct scatterlist sg;
589+
union {
590+
__be32 buf[2];
591+
} crypto __aligned(8);
596592
rxrpc_seq_t seq = sp->hdr.seq;
597593
bool aborted;
594+
int ret;
598595
u16 cksum;
599596
u32 x, y;
600597

@@ -614,17 +611,17 @@ static int rxkad_verify_packet(struct rxrpc_call *call, struct sk_buff *skb)
614611
/* validate the security checksum */
615612
x = (call->cid & RXRPC_CHANNELMASK) << (32 - RXRPC_CIDSHIFT);
616613
x |= seq & 0x3fffffff;
617-
call->crypto_buf[0] = htonl(call->call_id);
618-
call->crypto_buf[1] = htonl(x);
614+
crypto.buf[0] = htonl(call->call_id);
615+
crypto.buf[1] = htonl(x);
619616

620-
sg_init_one(&sg, call->crypto_buf, 8);
617+
sg_init_one(&sg, crypto.buf, 8);
621618
skcipher_request_set_sync_tfm(req, call->conn->rxkad.cipher);
622619
skcipher_request_set_callback(req, 0, NULL, NULL);
623620
skcipher_request_set_crypt(req, &sg, &sg, 8, iv.x);
624621
crypto_skcipher_encrypt(req);
625622
skcipher_request_zero(req);
626623

627-
y = ntohl(call->crypto_buf[1]);
624+
y = ntohl(crypto.buf[1]);
628625
cksum = (y >> 16) & 0xffff;
629626
if (cksum == 0)
630627
cksum = 1; /* zero checksums are not permitted */
@@ -637,15 +634,22 @@ static int rxkad_verify_packet(struct rxrpc_call *call, struct sk_buff *skb)
637634

638635
switch (call->conn->params.security_level) {
639636
case RXRPC_SECURITY_PLAIN:
640-
return 0;
637+
ret = 0;
638+
break;
641639
case RXRPC_SECURITY_AUTH:
642-
return rxkad_verify_packet_1(call, skb, seq, req);
640+
ret = rxkad_verify_packet_1(call, skb, seq, req);
641+
break;
643642
case RXRPC_SECURITY_ENCRYPT:
644-
return rxkad_verify_packet_2(call, skb, seq, req);
643+
ret = rxkad_verify_packet_2(call, skb, seq, req);
644+
break;
645645
default:
646-
return -ENOANO;
646+
ret = -ENOANO;
647+
break;
647648
}
648649

650+
skcipher_request_free(req);
651+
return ret;
652+
649653
protocol_error:
650654
if (aborted)
651655
rxrpc_send_abort_packet(call);

0 commit comments

Comments
 (0)