aboutsummaryrefslogtreecommitdiffstats
path: root/net/rxrpc
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2016-06-26 17:55:24 -0400
committerDavid Howells <dhowells@redhat.com>2016-07-06 05:43:05 -0400
commita263629da519b2064588377416e067727e2cbdf9 (patch)
tree13438d940f9a8c3aa4824955d2242813f95b4900 /net/rxrpc
parent689f4c646d6a8f0730eec11e06e5909de0b5d5d2 (diff)
rxrpc: Avoid using stack memory in SG lists in rxkad
rxkad uses stack memory in SG lists which would not work if stacks were allocated from vmalloc memory. In fact, in most cases this isn't even necessary as the stack memory ends up getting copied over to kmalloc memory. This patch eliminates all the unnecessary stack memory uses by supplying the final destination directly to the crypto API. In two instances where a temporary buffer is actually needed we also switch use a scratch area in the rxrpc_call struct (only one DATA packet will be being secured or verified at a time). Finally there is no need to split a split-page buffer into two SG entries so code dealing with that has been removed. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Andy Lutomirski <luto@kernel.org> Signed-off-by: David Howells <dhowells@redhat.com>
Diffstat (limited to 'net/rxrpc')
-rw-r--r--net/rxrpc/ar-internal.h8
-rw-r--r--net/rxrpc/conn_event.c5
-rw-r--r--net/rxrpc/conn_object.c6
-rw-r--r--net/rxrpc/insecure.c7
-rw-r--r--net/rxrpc/rxkad.c150
5 files changed, 65 insertions, 111 deletions
diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
index 702db72196fb..796368d1fb25 100644
--- a/net/rxrpc/ar-internal.h
+++ b/net/rxrpc/ar-internal.h
@@ -141,17 +141,16 @@ struct rxrpc_security {
141 int (*init_connection_security)(struct rxrpc_connection *); 141 int (*init_connection_security)(struct rxrpc_connection *);
142 142
143 /* prime a connection's packet security */ 143 /* prime a connection's packet security */
144 void (*prime_packet_security)(struct rxrpc_connection *); 144 int (*prime_packet_security)(struct rxrpc_connection *);
145 145
146 /* impose security on a packet */ 146 /* impose security on a packet */
147 int (*secure_packet)(const struct rxrpc_call *, 147 int (*secure_packet)(struct rxrpc_call *,
148 struct sk_buff *, 148 struct sk_buff *,
149 size_t, 149 size_t,
150 void *); 150 void *);
151 151
152 /* verify the security on a received packet */ 152 /* verify the security on a received packet */
153 int (*verify_packet)(const struct rxrpc_call *, struct sk_buff *, 153 int (*verify_packet)(struct rxrpc_call *, struct sk_buff *, u32 *);
154 u32 *);
155 154
156 /* issue a challenge */ 155 /* issue a challenge */
157 int (*issue_challenge)(struct rxrpc_connection *); 156 int (*issue_challenge)(struct rxrpc_connection *);
@@ -399,6 +398,7 @@ struct rxrpc_call {
399 struct sk_buff_head rx_oos_queue; /* packets received out of sequence */ 398 struct sk_buff_head rx_oos_queue; /* packets received out of sequence */
400 struct sk_buff *tx_pending; /* Tx socket buffer being filled */ 399 struct sk_buff *tx_pending; /* Tx socket buffer being filled */
401 wait_queue_head_t tx_waitq; /* wait for Tx window space to become available */ 400 wait_queue_head_t tx_waitq; /* wait for Tx window space to become available */
401 __be32 crypto_buf[2]; /* Temporary packet crypto buffer */
402 unsigned long user_call_ID; /* user-defined call ID */ 402 unsigned long user_call_ID; /* user-defined call ID */
403 unsigned long creation_jif; /* time of call creation */ 403 unsigned long creation_jif; /* time of call creation */
404 unsigned long flags; 404 unsigned long flags;
diff --git a/net/rxrpc/conn_event.c b/net/rxrpc/conn_event.c
index bf6971555eac..6a3c96707831 100644
--- a/net/rxrpc/conn_event.c
+++ b/net/rxrpc/conn_event.c
@@ -188,7 +188,10 @@ static int rxrpc_process_event(struct rxrpc_connection *conn,
188 if (ret < 0) 188 if (ret < 0)
189 return ret; 189 return ret;
190 190
191 conn->security->prime_packet_security(conn); 191 ret = conn->security->prime_packet_security(conn);
192 if (ret < 0)
193 return ret;
194
192 read_lock_bh(&conn->lock); 195 read_lock_bh(&conn->lock);
193 spin_lock(&conn->state_lock); 196 spin_lock(&conn->state_lock);
194 197
diff --git a/net/rxrpc/conn_object.c b/net/rxrpc/conn_object.c
index 2c2456ff2853..c2c0926af546 100644
--- a/net/rxrpc/conn_object.c
+++ b/net/rxrpc/conn_object.c
@@ -138,7 +138,9 @@ rxrpc_alloc_client_connection(struct rxrpc_conn_parameters *cp, gfp_t gfp)
138 if (ret < 0) 138 if (ret < 0)
139 goto error_1; 139 goto error_1;
140 140
141 conn->security->prime_packet_security(conn); 141 ret = conn->security->prime_packet_security(conn);
142 if (ret < 0)
143 goto error_2;
142 144
143 write_lock(&rxrpc_connection_lock); 145 write_lock(&rxrpc_connection_lock);
144 list_add_tail(&conn->link, &rxrpc_connections); 146 list_add_tail(&conn->link, &rxrpc_connections);
@@ -152,6 +154,8 @@ rxrpc_alloc_client_connection(struct rxrpc_conn_parameters *cp, gfp_t gfp)
152 _leave(" = %p", conn); 154 _leave(" = %p", conn);
153 return conn; 155 return conn;
154 156
157error_2:
158 conn->security->clear(conn);
155error_1: 159error_1:
156 rxrpc_put_client_connection_id(conn); 160 rxrpc_put_client_connection_id(conn);
157error_0: 161error_0:
diff --git a/net/rxrpc/insecure.c b/net/rxrpc/insecure.c
index e571403613c1..c21ad213b337 100644
--- a/net/rxrpc/insecure.c
+++ b/net/rxrpc/insecure.c
@@ -17,11 +17,12 @@ static int none_init_connection_security(struct rxrpc_connection *conn)
17 return 0; 17 return 0;
18} 18}
19 19
20static void none_prime_packet_security(struct rxrpc_connection *conn) 20static int none_prime_packet_security(struct rxrpc_connection *conn)
21{ 21{
22 return 0;
22} 23}
23 24
24static int none_secure_packet(const struct rxrpc_call *call, 25static int none_secure_packet(struct rxrpc_call *call,
25 struct sk_buff *skb, 26 struct sk_buff *skb,
26 size_t data_size, 27 size_t data_size,
27 void *sechdr) 28 void *sechdr)
@@ -29,7 +30,7 @@ static int none_secure_packet(const struct rxrpc_call *call,
29 return 0; 30 return 0;
30} 31}
31 32
32static int none_verify_packet(const struct rxrpc_call *call, 33static int none_verify_packet(struct rxrpc_call *call,
33 struct sk_buff *skb, 34 struct sk_buff *skb,
34 u32 *_abort_code) 35 u32 *_abort_code)
35{ 36{
diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
index 23c05ec6fa28..3acc7c1241d4 100644
--- a/net/rxrpc/rxkad.c
+++ b/net/rxrpc/rxkad.c
@@ -103,43 +103,43 @@ error:
103 * prime the encryption state with the invariant parts of a connection's 103 * prime the encryption state with the invariant parts of a connection's
104 * description 104 * description
105 */ 105 */
106static void rxkad_prime_packet_security(struct rxrpc_connection *conn) 106static int rxkad_prime_packet_security(struct rxrpc_connection *conn)
107{ 107{
108 struct rxrpc_key_token *token; 108 struct rxrpc_key_token *token;
109 SKCIPHER_REQUEST_ON_STACK(req, conn->cipher); 109 SKCIPHER_REQUEST_ON_STACK(req, conn->cipher);
110 struct scatterlist sg[2]; 110 struct scatterlist sg;
111 struct rxrpc_crypt iv; 111 struct rxrpc_crypt iv;
112 struct { 112 __be32 *tmpbuf;
113 __be32 x[4]; 113 size_t tmpsize = 4 * sizeof(__be32);
114 } tmpbuf __attribute__((aligned(16))); /* must all be in same page */
115 114
116 _enter(""); 115 _enter("");
117 116
118 if (!conn->params.key) 117 if (!conn->params.key)
119 return; 118 return 0;
119
120 tmpbuf = kmalloc(tmpsize, GFP_KERNEL);
121 if (!tmpbuf)
122 return -ENOMEM;
120 123
121 token = conn->params.key->payload.data[0]; 124 token = conn->params.key->payload.data[0];
122 memcpy(&iv, token->kad->session_key, sizeof(iv)); 125 memcpy(&iv, token->kad->session_key, sizeof(iv));
123 126
124 tmpbuf.x[0] = htonl(conn->proto.epoch); 127 tmpbuf[0] = htonl(conn->proto.epoch);
125 tmpbuf.x[1] = htonl(conn->proto.cid); 128 tmpbuf[1] = htonl(conn->proto.cid);
126 tmpbuf.x[2] = 0; 129 tmpbuf[2] = 0;
127 tmpbuf.x[3] = htonl(conn->security_ix); 130 tmpbuf[3] = htonl(conn->security_ix);
128
129 sg_init_one(&sg[0], &tmpbuf, sizeof(tmpbuf));
130 sg_init_one(&sg[1], &tmpbuf, sizeof(tmpbuf));
131 131
132 sg_init_one(&sg, tmpbuf, tmpsize);
132 skcipher_request_set_tfm(req, conn->cipher); 133 skcipher_request_set_tfm(req, conn->cipher);
133 skcipher_request_set_callback(req, 0, NULL, NULL); 134 skcipher_request_set_callback(req, 0, NULL, NULL);
134 skcipher_request_set_crypt(req, &sg[1], &sg[0], sizeof(tmpbuf), iv.x); 135 skcipher_request_set_crypt(req, &sg, &sg, tmpsize, iv.x);
135
136 crypto_skcipher_encrypt(req); 136 crypto_skcipher_encrypt(req);
137 skcipher_request_zero(req); 137 skcipher_request_zero(req);
138 138
139 memcpy(&conn->csum_iv, &tmpbuf.x[2], sizeof(conn->csum_iv)); 139 memcpy(&conn->csum_iv, tmpbuf + 2, sizeof(conn->csum_iv));
140 ASSERTCMP((u32 __force)conn->csum_iv.n[0], ==, (u32 __force)tmpbuf.x[2]); 140 kfree(tmpbuf);
141 141 _leave(" = 0");
142 _leave(""); 142 return 0;
143} 143}
144 144
145/* 145/*
@@ -152,12 +152,9 @@ static int rxkad_secure_packet_auth(const struct rxrpc_call *call,
152{ 152{
153 struct rxrpc_skb_priv *sp; 153 struct rxrpc_skb_priv *sp;
154 SKCIPHER_REQUEST_ON_STACK(req, call->conn->cipher); 154 SKCIPHER_REQUEST_ON_STACK(req, call->conn->cipher);
155 struct rxkad_level1_hdr hdr;
155 struct rxrpc_crypt iv; 156 struct rxrpc_crypt iv;
156 struct scatterlist sg[2]; 157 struct scatterlist sg;
157 struct {
158 struct rxkad_level1_hdr hdr;
159 __be32 first; /* first four bytes of data and padding */
160 } tmpbuf __attribute__((aligned(8))); /* must all be in same page */
161 u16 check; 158 u16 check;
162 159
163 sp = rxrpc_skb(skb); 160 sp = rxrpc_skb(skb);
@@ -167,24 +164,19 @@ static int rxkad_secure_packet_auth(const struct rxrpc_call *call,
167 check = sp->hdr.seq ^ sp->hdr.callNumber; 164 check = sp->hdr.seq ^ sp->hdr.callNumber;
168 data_size |= (u32)check << 16; 165 data_size |= (u32)check << 16;
169 166
170 tmpbuf.hdr.data_size = htonl(data_size); 167 hdr.data_size = htonl(data_size);
171 memcpy(&tmpbuf.first, sechdr + 4, sizeof(tmpbuf.first)); 168 memcpy(sechdr, &hdr, sizeof(hdr));
172 169
173 /* start the encryption afresh */ 170 /* start the encryption afresh */
174 memset(&iv, 0, sizeof(iv)); 171 memset(&iv, 0, sizeof(iv));
175 172
176 sg_init_one(&sg[0], &tmpbuf, sizeof(tmpbuf)); 173 sg_init_one(&sg, sechdr, 8);
177 sg_init_one(&sg[1], &tmpbuf, sizeof(tmpbuf));
178
179 skcipher_request_set_tfm(req, call->conn->cipher); 174 skcipher_request_set_tfm(req, call->conn->cipher);
180 skcipher_request_set_callback(req, 0, NULL, NULL); 175 skcipher_request_set_callback(req, 0, NULL, NULL);
181 skcipher_request_set_crypt(req, &sg[1], &sg[0], sizeof(tmpbuf), iv.x); 176 skcipher_request_set_crypt(req, &sg, &sg, 8, iv.x);
182
183 crypto_skcipher_encrypt(req); 177 crypto_skcipher_encrypt(req);
184 skcipher_request_zero(req); 178 skcipher_request_zero(req);
185 179
186 memcpy(sechdr, &tmpbuf, sizeof(tmpbuf));
187
188 _leave(" = 0"); 180 _leave(" = 0");
189 return 0; 181 return 0;
190} 182}
@@ -198,8 +190,7 @@ static int rxkad_secure_packet_encrypt(const struct rxrpc_call *call,
198 void *sechdr) 190 void *sechdr)
199{ 191{
200 const struct rxrpc_key_token *token; 192 const struct rxrpc_key_token *token;
201 struct rxkad_level2_hdr rxkhdr 193 struct rxkad_level2_hdr rxkhdr;
202 __attribute__((aligned(8))); /* must be all on one page */
203 struct rxrpc_skb_priv *sp; 194 struct rxrpc_skb_priv *sp;
204 SKCIPHER_REQUEST_ON_STACK(req, call->conn->cipher); 195 SKCIPHER_REQUEST_ON_STACK(req, call->conn->cipher);
205 struct rxrpc_crypt iv; 196 struct rxrpc_crypt iv;
@@ -218,18 +209,16 @@ static int rxkad_secure_packet_encrypt(const struct rxrpc_call *call,
218 209
219 rxkhdr.data_size = htonl(data_size | (u32)check << 16); 210 rxkhdr.data_size = htonl(data_size | (u32)check << 16);
220 rxkhdr.checksum = 0; 211 rxkhdr.checksum = 0;
212 memcpy(sechdr, &rxkhdr, sizeof(rxkhdr));
221 213
222 /* encrypt from the session key */ 214 /* encrypt from the session key */
223 token = call->conn->params.key->payload.data[0]; 215 token = call->conn->params.key->payload.data[0];
224 memcpy(&iv, token->kad->session_key, sizeof(iv)); 216 memcpy(&iv, token->kad->session_key, sizeof(iv));
225 217
226 sg_init_one(&sg[0], sechdr, sizeof(rxkhdr)); 218 sg_init_one(&sg[0], sechdr, sizeof(rxkhdr));
227 sg_init_one(&sg[1], &rxkhdr, sizeof(rxkhdr));
228
229 skcipher_request_set_tfm(req, call->conn->cipher); 219 skcipher_request_set_tfm(req, call->conn->cipher);
230 skcipher_request_set_callback(req, 0, NULL, NULL); 220 skcipher_request_set_callback(req, 0, NULL, NULL);
231 skcipher_request_set_crypt(req, &sg[1], &sg[0], sizeof(rxkhdr), iv.x); 221 skcipher_request_set_crypt(req, &sg[0], &sg[0], sizeof(rxkhdr), iv.x);
232
233 crypto_skcipher_encrypt(req); 222 crypto_skcipher_encrypt(req);
234 223
235 /* we want to encrypt the skbuff in-place */ 224 /* we want to encrypt the skbuff in-place */
@@ -243,9 +232,7 @@ static int rxkad_secure_packet_encrypt(const struct rxrpc_call *call,
243 232
244 sg_init_table(sg, nsg); 233 sg_init_table(sg, nsg);
245 skb_to_sgvec(skb, sg, 0, len); 234 skb_to_sgvec(skb, sg, 0, len);
246
247 skcipher_request_set_crypt(req, sg, sg, len, iv.x); 235 skcipher_request_set_crypt(req, sg, sg, len, iv.x);
248
249 crypto_skcipher_encrypt(req); 236 crypto_skcipher_encrypt(req);
250 237
251 _leave(" = 0"); 238 _leave(" = 0");
@@ -259,7 +246,7 @@ out:
259/* 246/*
260 * checksum an RxRPC packet header 247 * checksum an RxRPC packet header
261 */ 248 */
262static int rxkad_secure_packet(const struct rxrpc_call *call, 249static int rxkad_secure_packet(struct rxrpc_call *call,
263 struct sk_buff *skb, 250 struct sk_buff *skb,
264 size_t data_size, 251 size_t data_size,
265 void *sechdr) 252 void *sechdr)
@@ -267,10 +254,7 @@ static int rxkad_secure_packet(const struct rxrpc_call *call,
267 struct rxrpc_skb_priv *sp; 254 struct rxrpc_skb_priv *sp;
268 SKCIPHER_REQUEST_ON_STACK(req, call->conn->cipher); 255 SKCIPHER_REQUEST_ON_STACK(req, call->conn->cipher);
269 struct rxrpc_crypt iv; 256 struct rxrpc_crypt iv;
270 struct scatterlist sg[2]; 257 struct scatterlist sg;
271 struct {
272 __be32 x[2];
273 } tmpbuf __attribute__((aligned(8))); /* must all be in same page */
274 u32 x, y; 258 u32 x, y;
275 int ret; 259 int ret;
276 260
@@ -293,20 +277,17 @@ static int rxkad_secure_packet(const struct rxrpc_call *call,
293 /* calculate the security checksum */ 277 /* calculate the security checksum */
294 x = call->channel << (32 - RXRPC_CIDSHIFT); 278 x = call->channel << (32 - RXRPC_CIDSHIFT);
295 x |= sp->hdr.seq & 0x3fffffff; 279 x |= sp->hdr.seq & 0x3fffffff;
296 tmpbuf.x[0] = htonl(sp->hdr.callNumber); 280 call->crypto_buf[0] = htonl(sp->hdr.callNumber);
297 tmpbuf.x[1] = htonl(x); 281 call->crypto_buf[1] = htonl(x);
298
299 sg_init_one(&sg[0], &tmpbuf, sizeof(tmpbuf));
300 sg_init_one(&sg[1], &tmpbuf, sizeof(tmpbuf));
301 282
283 sg_init_one(&sg, call->crypto_buf, 8);
302 skcipher_request_set_tfm(req, call->conn->cipher); 284 skcipher_request_set_tfm(req, call->conn->cipher);
303 skcipher_request_set_callback(req, 0, NULL, NULL); 285 skcipher_request_set_callback(req, 0, NULL, NULL);
304 skcipher_request_set_crypt(req, &sg[1], &sg[0], sizeof(tmpbuf), iv.x); 286 skcipher_request_set_crypt(req, &sg, &sg, 8, iv.x);
305
306 crypto_skcipher_encrypt(req); 287 crypto_skcipher_encrypt(req);
307 skcipher_request_zero(req); 288 skcipher_request_zero(req);
308 289
309 y = ntohl(tmpbuf.x[1]); 290 y = ntohl(call->crypto_buf[1]);
310 y = (y >> 16) & 0xffff; 291 y = (y >> 16) & 0xffff;
311 if (y == 0) 292 if (y == 0)
312 y = 1; /* zero checksums are not permitted */ 293 y = 1; /* zero checksums are not permitted */
@@ -367,7 +348,6 @@ static int rxkad_verify_packet_auth(const struct rxrpc_call *call,
367 skcipher_request_set_tfm(req, call->conn->cipher); 348 skcipher_request_set_tfm(req, call->conn->cipher);
368 skcipher_request_set_callback(req, 0, NULL, NULL); 349 skcipher_request_set_callback(req, 0, NULL, NULL);
369 skcipher_request_set_crypt(req, sg, sg, 8, iv.x); 350 skcipher_request_set_crypt(req, sg, sg, 8, iv.x);
370
371 crypto_skcipher_decrypt(req); 351 crypto_skcipher_decrypt(req);
372 skcipher_request_zero(req); 352 skcipher_request_zero(req);
373 353
@@ -452,7 +432,6 @@ static int rxkad_verify_packet_encrypt(const struct rxrpc_call *call,
452 skcipher_request_set_tfm(req, call->conn->cipher); 432 skcipher_request_set_tfm(req, call->conn->cipher);
453 skcipher_request_set_callback(req, 0, NULL, NULL); 433 skcipher_request_set_callback(req, 0, NULL, NULL);
454 skcipher_request_set_crypt(req, sg, sg, skb->len, iv.x); 434 skcipher_request_set_crypt(req, sg, sg, skb->len, iv.x);
455
456 crypto_skcipher_decrypt(req); 435 crypto_skcipher_decrypt(req);
457 skcipher_request_zero(req); 436 skcipher_request_zero(req);
458 if (sg != _sg) 437 if (sg != _sg)
@@ -498,17 +477,14 @@ nomem:
498/* 477/*
499 * verify the security on a received packet 478 * verify the security on a received packet
500 */ 479 */
501static int rxkad_verify_packet(const struct rxrpc_call *call, 480static int rxkad_verify_packet(struct rxrpc_call *call,
502 struct sk_buff *skb, 481 struct sk_buff *skb,
503 u32 *_abort_code) 482 u32 *_abort_code)
504{ 483{
505 SKCIPHER_REQUEST_ON_STACK(req, call->conn->cipher); 484 SKCIPHER_REQUEST_ON_STACK(req, call->conn->cipher);
506 struct rxrpc_skb_priv *sp; 485 struct rxrpc_skb_priv *sp;
507 struct rxrpc_crypt iv; 486 struct rxrpc_crypt iv;
508 struct scatterlist sg[2]; 487 struct scatterlist sg;
509 struct {
510 __be32 x[2];
511 } tmpbuf __attribute__((aligned(8))); /* must all be in same page */
512 u16 cksum; 488 u16 cksum;
513 u32 x, y; 489 u32 x, y;
514 int ret; 490 int ret;
@@ -533,20 +509,17 @@ static int rxkad_verify_packet(const struct rxrpc_call *call,
533 /* validate the security checksum */ 509 /* validate the security checksum */
534 x = call->channel << (32 - RXRPC_CIDSHIFT); 510 x = call->channel << (32 - RXRPC_CIDSHIFT);
535 x |= sp->hdr.seq & 0x3fffffff; 511 x |= sp->hdr.seq & 0x3fffffff;
536 tmpbuf.x[0] = htonl(call->call_id); 512 call->crypto_buf[0] = htonl(call->call_id);
537 tmpbuf.x[1] = htonl(x); 513 call->crypto_buf[1] = htonl(x);
538
539 sg_init_one(&sg[0], &tmpbuf, sizeof(tmpbuf));
540 sg_init_one(&sg[1], &tmpbuf, sizeof(tmpbuf));
541 514
515 sg_init_one(&sg, call->crypto_buf, 8);
542 skcipher_request_set_tfm(req, call->conn->cipher); 516 skcipher_request_set_tfm(req, call->conn->cipher);
543 skcipher_request_set_callback(req, 0, NULL, NULL); 517 skcipher_request_set_callback(req, 0, NULL, NULL);
544 skcipher_request_set_crypt(req, &sg[1], &sg[0], sizeof(tmpbuf), iv.x); 518 skcipher_request_set_crypt(req, &sg, &sg, 8, iv.x);
545
546 crypto_skcipher_encrypt(req); 519 crypto_skcipher_encrypt(req);
547 skcipher_request_zero(req); 520 skcipher_request_zero(req);
548 521
549 y = ntohl(tmpbuf.x[1]); 522 y = ntohl(call->crypto_buf[1]);
550 cksum = (y >> 16) & 0xffff; 523 cksum = (y >> 16) & 0xffff;
551 if (cksum == 0) 524 if (cksum == 0)
552 cksum = 1; /* zero checksums are not permitted */ 525 cksum = 1; /* zero checksums are not permitted */
@@ -710,29 +683,6 @@ static void rxkad_calc_response_checksum(struct rxkad_response *response)
710} 683}
711 684
712/* 685/*
713 * load a scatterlist with a potentially split-page buffer
714 */
715static void rxkad_sg_set_buf2(struct scatterlist sg[2],
716 void *buf, size_t buflen)
717{
718 int nsg = 1;
719
720 sg_init_table(sg, 2);
721
722 sg_set_buf(&sg[0], buf, buflen);
723 if (sg[0].offset + buflen > PAGE_SIZE) {
724 /* the buffer was split over two pages */
725 sg[0].length = PAGE_SIZE - sg[0].offset;
726 sg_set_buf(&sg[1], buf + sg[0].length, buflen - sg[0].length);
727 nsg++;
728 }
729
730 sg_mark_end(&sg[nsg - 1]);
731
732 ASSERTCMP(sg[0].length + sg[1].length, ==, buflen);
733}
734
735/*
736 * encrypt the response packet 686 * encrypt the response packet
737 */ 687 */
738static void rxkad_encrypt_response(struct rxrpc_connection *conn, 688static void rxkad_encrypt_response(struct rxrpc_connection *conn,
@@ -741,17 +691,16 @@ static void rxkad_encrypt_response(struct rxrpc_connection *conn,
741{ 691{
742 SKCIPHER_REQUEST_ON_STACK(req, conn->cipher); 692 SKCIPHER_REQUEST_ON_STACK(req, conn->cipher);
743 struct rxrpc_crypt iv; 693 struct rxrpc_crypt iv;
744 struct scatterlist sg[2]; 694 struct scatterlist sg[1];
745 695
746 /* continue encrypting from where we left off */ 696 /* continue encrypting from where we left off */
747 memcpy(&iv, s2->session_key, sizeof(iv)); 697 memcpy(&iv, s2->session_key, sizeof(iv));
748 698
749 rxkad_sg_set_buf2(sg, &resp->encrypted, sizeof(resp->encrypted)); 699 sg_init_table(sg, 1);
750 700 sg_set_buf(sg, &resp->encrypted, sizeof(resp->encrypted));
751 skcipher_request_set_tfm(req, conn->cipher); 701 skcipher_request_set_tfm(req, conn->cipher);
752 skcipher_request_set_callback(req, 0, NULL, NULL); 702 skcipher_request_set_callback(req, 0, NULL, NULL);
753 skcipher_request_set_crypt(req, sg, sg, sizeof(resp->encrypted), iv.x); 703 skcipher_request_set_crypt(req, sg, sg, sizeof(resp->encrypted), iv.x);
754
755 crypto_skcipher_encrypt(req); 704 crypto_skcipher_encrypt(req);
756 skcipher_request_zero(req); 705 skcipher_request_zero(req);
757} 706}
@@ -887,10 +836,8 @@ static int rxkad_decrypt_ticket(struct rxrpc_connection *conn,
887 } 836 }
888 837
889 sg_init_one(&sg[0], ticket, ticket_len); 838 sg_init_one(&sg[0], ticket, ticket_len);
890
891 skcipher_request_set_callback(req, 0, NULL, NULL); 839 skcipher_request_set_callback(req, 0, NULL, NULL);
892 skcipher_request_set_crypt(req, sg, sg, ticket_len, iv.x); 840 skcipher_request_set_crypt(req, sg, sg, ticket_len, iv.x);
893
894 crypto_skcipher_decrypt(req); 841 crypto_skcipher_decrypt(req);
895 skcipher_request_free(req); 842 skcipher_request_free(req);
896 843
@@ -1001,7 +948,7 @@ static void rxkad_decrypt_response(struct rxrpc_connection *conn,
1001 const struct rxrpc_crypt *session_key) 948 const struct rxrpc_crypt *session_key)
1002{ 949{
1003 SKCIPHER_REQUEST_ON_STACK(req, rxkad_ci); 950 SKCIPHER_REQUEST_ON_STACK(req, rxkad_ci);
1004 struct scatterlist sg[2]; 951 struct scatterlist sg[1];
1005 struct rxrpc_crypt iv; 952 struct rxrpc_crypt iv;
1006 953
1007 _enter(",,%08x%08x", 954 _enter(",,%08x%08x",
@@ -1016,12 +963,11 @@ static void rxkad_decrypt_response(struct rxrpc_connection *conn,
1016 963
1017 memcpy(&iv, session_key, sizeof(iv)); 964 memcpy(&iv, session_key, sizeof(iv));
1018 965
1019 rxkad_sg_set_buf2(sg, &resp->encrypted, sizeof(resp->encrypted)); 966 sg_init_table(sg, 1);
1020 967 sg_set_buf(sg, &resp->encrypted, sizeof(resp->encrypted));
1021 skcipher_request_set_tfm(req, rxkad_ci); 968 skcipher_request_set_tfm(req, rxkad_ci);
1022 skcipher_request_set_callback(req, 0, NULL, NULL); 969 skcipher_request_set_callback(req, 0, NULL, NULL);
1023 skcipher_request_set_crypt(req, sg, sg, sizeof(resp->encrypted), iv.x); 970 skcipher_request_set_crypt(req, sg, sg, sizeof(resp->encrypted), iv.x);
1024
1025 crypto_skcipher_decrypt(req); 971 crypto_skcipher_decrypt(req);
1026 skcipher_request_zero(req); 972 skcipher_request_zero(req);
1027 973