@@ -69,32 +69,28 @@ static int ceph_x_encrypt(struct ceph_crypto_key *secret, void *buf,
69
69
return sizeof (u32 ) + ciphertext_len ;
70
70
}
71
71
72
- static int ceph_x_decrypt (struct ceph_crypto_key * secret ,
73
- void * * p , void * end , void * * obuf , size_t olen )
72
+ static int ceph_x_decrypt (struct ceph_crypto_key * secret , void * * p , void * end )
74
73
{
75
- struct ceph_x_encrypt_header head ;
76
- size_t head_len = sizeof (head );
77
- int len , ret ;
78
-
79
- len = ceph_decode_32 (p );
80
- if (* p + len > end )
81
- return - EINVAL ;
74
+ struct ceph_x_encrypt_header * hdr = * p + sizeof (u32 );
75
+ int ciphertext_len , plaintext_len ;
76
+ int ret ;
82
77
83
- dout ("ceph_x_decrypt len %d\n" , len );
84
- if (* obuf == NULL ) {
85
- * obuf = kmalloc (len , GFP_NOFS );
86
- if (!* obuf )
87
- return - ENOMEM ;
88
- olen = len ;
89
- }
78
+ ceph_decode_32_safe (p , end , ciphertext_len , e_inval );
79
+ ceph_decode_need (p , end , ciphertext_len , e_inval );
90
80
91
- ret = ceph_decrypt2 (secret , & head , & head_len , * obuf , & olen , * p , len );
81
+ ret = ceph_crypt (secret , false, * p , end - * p , ciphertext_len ,
82
+ & plaintext_len );
92
83
if (ret )
93
84
return ret ;
94
- if (head .struct_v != 1 || le64_to_cpu (head .magic ) != CEPHX_ENC_MAGIC )
85
+
86
+ if (hdr -> struct_v != 1 || le64_to_cpu (hdr -> magic ) != CEPHX_ENC_MAGIC )
95
87
return - EPERM ;
96
- * p += len ;
97
- return olen ;
88
+
89
+ * p += ciphertext_len ;
90
+ return plaintext_len - sizeof (struct ceph_x_encrypt_header );
91
+
92
+ e_inval :
93
+ return - EINVAL ;
98
94
}
99
95
100
96
/*
@@ -149,12 +145,10 @@ static int process_one_ticket(struct ceph_auth_client *ac,
149
145
int type ;
150
146
u8 tkt_struct_v , blob_struct_v ;
151
147
struct ceph_x_ticket_handler * th ;
152
- void * dbuf = NULL ;
153
148
void * dp , * dend ;
154
149
int dlen ;
155
150
char is_enc ;
156
151
struct timespec validity ;
157
- void * ticket_buf = NULL ;
158
152
void * tp , * tpend ;
159
153
void * * ptp ;
160
154
struct ceph_crypto_key new_session_key ;
@@ -179,14 +173,12 @@ static int process_one_ticket(struct ceph_auth_client *ac,
179
173
}
180
174
181
175
/* blob for me */
182
- dlen = ceph_x_decrypt ( secret , p , end , & dbuf , 0 );
183
- if ( dlen <= 0 ) {
184
- ret = dlen ;
176
+ dp = * p + ceph_x_encrypt_offset ( );
177
+ ret = ceph_x_decrypt ( secret , p , end );
178
+ if ( ret < 0 )
185
179
goto out ;
186
- }
187
- dout (" decrypted %d bytes\n" , dlen );
188
- dp = dbuf ;
189
- dend = dp + dlen ;
180
+ dout (" decrypted %d bytes\n" , ret );
181
+ dend = dp + ret ;
190
182
191
183
tkt_struct_v = ceph_decode_8 (& dp );
192
184
if (tkt_struct_v != 1 )
@@ -207,15 +199,13 @@ static int process_one_ticket(struct ceph_auth_client *ac,
207
199
ceph_decode_8_safe (p , end , is_enc , bad );
208
200
if (is_enc ) {
209
201
/* encrypted */
210
- dout (" encrypted ticket\n" );
211
- dlen = ceph_x_decrypt (& th -> session_key , p , end , & ticket_buf , 0 );
212
- if (dlen < 0 ) {
213
- ret = dlen ;
202
+ tp = * p + ceph_x_encrypt_offset ();
203
+ ret = ceph_x_decrypt (& th -> session_key , p , end );
204
+ if (ret < 0 )
214
205
goto out ;
215
- }
216
- tp = ticket_buf ;
206
+ dout (" encrypted ticket, decrypted %d bytes\n" , ret );
217
207
ptp = & tp ;
218
- tpend = * ptp + dlen ;
208
+ tpend = tp + ret ;
219
209
} else {
220
210
/* unencrypted */
221
211
ptp = p ;
@@ -246,8 +236,6 @@ static int process_one_ticket(struct ceph_auth_client *ac,
246
236
xi -> have_keys |= th -> service ;
247
237
248
238
out :
249
- kfree (ticket_buf );
250
- kfree (dbuf );
251
239
return ret ;
252
240
253
241
bad :
@@ -638,24 +626,22 @@ static int ceph_x_verify_authorizer_reply(struct ceph_auth_client *ac,
638
626
struct ceph_authorizer * a , size_t len )
639
627
{
640
628
struct ceph_x_authorizer * au = (void * )a ;
641
- int ret = 0 ;
642
- struct ceph_x_authorize_reply reply ;
643
- void * preply = & reply ;
644
629
void * p = au -> enc_buf ;
630
+ struct ceph_x_authorize_reply * reply = p + ceph_x_encrypt_offset ();
631
+ int ret ;
645
632
646
- ret = ceph_x_decrypt (& au -> session_key , & p , p + CEPHX_AU_ENC_BUF_LEN ,
647
- & preply , sizeof (reply ));
633
+ ret = ceph_x_decrypt (& au -> session_key , & p , p + CEPHX_AU_ENC_BUF_LEN );
648
634
if (ret < 0 )
649
635
return ret ;
650
- if (ret != sizeof (reply ))
636
+ if (ret != sizeof (* reply ))
651
637
return - EPERM ;
652
638
653
- if (au -> nonce + 1 != le64_to_cpu (reply . nonce_plus_one ))
639
+ if (au -> nonce + 1 != le64_to_cpu (reply -> nonce_plus_one ))
654
640
ret = - EPERM ;
655
641
else
656
642
ret = 0 ;
657
643
dout ("verify_authorizer_reply nonce %llx got %llx ret %d\n" ,
658
- au -> nonce , le64_to_cpu (reply . nonce_plus_one ), ret );
644
+ au -> nonce , le64_to_cpu (reply -> nonce_plus_one ), ret );
659
645
return ret ;
660
646
}
661
647
0 commit comments