@@ -233,26 +233,15 @@ static int rxkad_prime_packet_security(struct rxrpc_connection *conn,
233
233
static struct skcipher_request * rxkad_get_call_crypto (struct rxrpc_call * call )
234
234
{
235
235
struct crypto_skcipher * tfm = & call -> conn -> rxkad .cipher -> base ;
236
- struct skcipher_request * cipher_req = call -> cipher_req ;
237
236
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 );
246
238
}
247
239
248
240
/*
249
241
* Clean up the crypto on a call.
250
242
*/
251
243
static void rxkad_free_call_crypto (struct rxrpc_call * call )
252
244
{
253
- if (call -> cipher_req )
254
- skcipher_request_free (call -> cipher_req );
255
- call -> cipher_req = NULL ;
256
245
}
257
246
258
247
/*
@@ -348,6 +337,9 @@ static int rxkad_secure_packet(struct rxrpc_call *call, struct rxrpc_txbuf *txb)
348
337
struct skcipher_request * req ;
349
338
struct rxrpc_crypt iv ;
350
339
struct scatterlist sg ;
340
+ union {
341
+ __be32 buf [2 ];
342
+ } crypto __aligned (8 );
351
343
u32 x , y ;
352
344
int ret ;
353
345
@@ -372,17 +364,17 @@ static int rxkad_secure_packet(struct rxrpc_call *call, struct rxrpc_txbuf *txb)
372
364
/* calculate the security checksum */
373
365
x = (ntohl (txb -> wire .cid ) & RXRPC_CHANNELMASK ) << (32 - RXRPC_CIDSHIFT );
374
366
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 );
377
369
378
- sg_init_one (& sg , call -> crypto_buf , 8 );
370
+ sg_init_one (& sg , crypto . buf , 8 );
379
371
skcipher_request_set_sync_tfm (req , call -> conn -> rxkad .cipher );
380
372
skcipher_request_set_callback (req , 0 , NULL , NULL );
381
373
skcipher_request_set_crypt (req , & sg , & sg , 8 , iv .x );
382
374
crypto_skcipher_encrypt (req );
383
375
skcipher_request_zero (req );
384
376
385
- y = ntohl (call -> crypto_buf [1 ]);
377
+ y = ntohl (crypto . buf [1 ]);
386
378
y = (y >> 16 ) & 0xffff ;
387
379
if (y == 0 )
388
380
y = 1 ; /* zero checksums are not permitted */
@@ -403,6 +395,7 @@ static int rxkad_secure_packet(struct rxrpc_call *call, struct rxrpc_txbuf *txb)
403
395
break ;
404
396
}
405
397
398
+ skcipher_request_free (req );
406
399
_leave (" = %d [set %x]" , ret , y );
407
400
return ret ;
408
401
}
@@ -593,8 +586,12 @@ static int rxkad_verify_packet(struct rxrpc_call *call, struct sk_buff *skb)
593
586
struct skcipher_request * req ;
594
587
struct rxrpc_crypt iv ;
595
588
struct scatterlist sg ;
589
+ union {
590
+ __be32 buf [2 ];
591
+ } crypto __aligned (8 );
596
592
rxrpc_seq_t seq = sp -> hdr .seq ;
597
593
bool aborted ;
594
+ int ret ;
598
595
u16 cksum ;
599
596
u32 x , y ;
600
597
@@ -614,17 +611,17 @@ static int rxkad_verify_packet(struct rxrpc_call *call, struct sk_buff *skb)
614
611
/* validate the security checksum */
615
612
x = (call -> cid & RXRPC_CHANNELMASK ) << (32 - RXRPC_CIDSHIFT );
616
613
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 );
619
616
620
- sg_init_one (& sg , call -> crypto_buf , 8 );
617
+ sg_init_one (& sg , crypto . buf , 8 );
621
618
skcipher_request_set_sync_tfm (req , call -> conn -> rxkad .cipher );
622
619
skcipher_request_set_callback (req , 0 , NULL , NULL );
623
620
skcipher_request_set_crypt (req , & sg , & sg , 8 , iv .x );
624
621
crypto_skcipher_encrypt (req );
625
622
skcipher_request_zero (req );
626
623
627
- y = ntohl (call -> crypto_buf [1 ]);
624
+ y = ntohl (crypto . buf [1 ]);
628
625
cksum = (y >> 16 ) & 0xffff ;
629
626
if (cksum == 0 )
630
627
cksum = 1 ; /* zero checksums are not permitted */
@@ -637,15 +634,22 @@ static int rxkad_verify_packet(struct rxrpc_call *call, struct sk_buff *skb)
637
634
638
635
switch (call -> conn -> params .security_level ) {
639
636
case RXRPC_SECURITY_PLAIN :
640
- return 0 ;
637
+ ret = 0 ;
638
+ break ;
641
639
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 ;
643
642
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 ;
645
645
default :
646
- return - ENOANO ;
646
+ ret = - ENOANO ;
647
+ break ;
647
648
}
648
649
650
+ skcipher_request_free (req );
651
+ return ret ;
652
+
649
653
protocol_error :
650
654
if (aborted )
651
655
rxrpc_send_abort_packet (call );
0 commit comments