aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2018-02-08 10:59:07 -0500
committerDavid S. Miller <davem@davemloft.net>2018-02-08 13:48:29 -0500
commit8c2f826dc36314059ac146c78d3bf8056b626446 (patch)
tree21719e202e2e3f0ada53fb30562a72cdec238842
parentc70255868148a498ba418bc6c2f9df212d30d393 (diff)
rxrpc: Don't put crypto buffers on the stack
Don't put buffers of data to be handed to crypto on the stack as this may cause an assertion failure in the kernel (see below). Fix this by using an kmalloc'd buffer instead. kernel BUG at ./include/linux/scatterlist.h:147! ... RIP: 0010:rxkad_encrypt_response.isra.6+0x191/0x1b0 [rxrpc] RSP: 0018:ffffbe2fc06cfca8 EFLAGS: 00010246 RAX: 0000000000000000 RBX: ffff989277d59900 RCX: 0000000000000028 RDX: 0000259dc06cfd88 RSI: 0000000000000025 RDI: ffffbe30406cfd88 RBP: ffffbe2fc06cfd60 R08: ffffbe2fc06cfd08 R09: ffffbe2fc06cfd08 R10: 0000000000000000 R11: 0000000000000000 R12: 1ffff7c5f80d9f95 R13: ffffbe2fc06cfd88 R14: ffff98927a3f7aa0 R15: ffffbe2fc06cfd08 FS: 0000000000000000(0000) GS:ffff98927fc00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 000055b1ff28f0f8 CR3: 000000001b412003 CR4: 00000000003606f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: rxkad_respond_to_challenge+0x297/0x330 [rxrpc] rxrpc_process_connection+0xd1/0x690 [rxrpc] ? process_one_work+0x1c3/0x680 ? __lock_is_held+0x59/0xa0 process_one_work+0x249/0x680 worker_thread+0x3a/0x390 ? process_one_work+0x680/0x680 kthread+0x121/0x140 ? kthread_create_worker_on_cpu+0x70/0x70 ret_from_fork+0x3a/0x50 Reported-by: Jonathan Billings <jsbillings@jsbillings.org> Reported-by: Marc Dionne <marc.dionne@auristor.com> Signed-off-by: David Howells <dhowells@redhat.com> Tested-by: Jonathan Billings <jsbillings@jsbillings.org> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/rxrpc/conn_event.c1
-rw-r--r--net/rxrpc/rxkad.c92
2 files changed, 52 insertions, 41 deletions
diff --git a/net/rxrpc/conn_event.c b/net/rxrpc/conn_event.c
index 4ca11be6be3c..b1dfae107431 100644
--- a/net/rxrpc/conn_event.c
+++ b/net/rxrpc/conn_event.c
@@ -460,6 +460,7 @@ void rxrpc_process_connection(struct work_struct *work)
460 case -EKEYEXPIRED: 460 case -EKEYEXPIRED:
461 case -EKEYREJECTED: 461 case -EKEYREJECTED:
462 goto protocol_error; 462 goto protocol_error;
463 case -ENOMEM:
463 case -EAGAIN: 464 case -EAGAIN:
464 goto requeue_and_leave; 465 goto requeue_and_leave;
465 case -ECONNABORTED: 466 case -ECONNABORTED:
diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
index c38b3a1de56c..77cb23c7bd0a 100644
--- a/net/rxrpc/rxkad.c
+++ b/net/rxrpc/rxkad.c
@@ -773,8 +773,7 @@ static int rxkad_respond_to_challenge(struct rxrpc_connection *conn,
773{ 773{
774 const struct rxrpc_key_token *token; 774 const struct rxrpc_key_token *token;
775 struct rxkad_challenge challenge; 775 struct rxkad_challenge challenge;
776 struct rxkad_response resp 776 struct rxkad_response *resp;
777 __attribute__((aligned(8))); /* must be aligned for crypto */
778 struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 777 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
779 const char *eproto; 778 const char *eproto;
780 u32 version, nonce, min_level, abort_code; 779 u32 version, nonce, min_level, abort_code;
@@ -818,26 +817,29 @@ static int rxkad_respond_to_challenge(struct rxrpc_connection *conn,
818 token = conn->params.key->payload.data[0]; 817 token = conn->params.key->payload.data[0];
819 818
820 /* build the response packet */ 819 /* build the response packet */
821 memset(&resp, 0, sizeof(resp)); 820 resp = kzalloc(sizeof(struct rxkad_response), GFP_NOFS);
822 821 if (!resp)
823 resp.version = htonl(RXKAD_VERSION); 822 return -ENOMEM;
824 resp.encrypted.epoch = htonl(conn->proto.epoch); 823
825 resp.encrypted.cid = htonl(conn->proto.cid); 824 resp->version = htonl(RXKAD_VERSION);
826 resp.encrypted.securityIndex = htonl(conn->security_ix); 825 resp->encrypted.epoch = htonl(conn->proto.epoch);
827 resp.encrypted.inc_nonce = htonl(nonce + 1); 826 resp->encrypted.cid = htonl(conn->proto.cid);
828 resp.encrypted.level = htonl(conn->params.security_level); 827 resp->encrypted.securityIndex = htonl(conn->security_ix);
829 resp.kvno = htonl(token->kad->kvno); 828 resp->encrypted.inc_nonce = htonl(nonce + 1);
830 resp.ticket_len = htonl(token->kad->ticket_len); 829 resp->encrypted.level = htonl(conn->params.security_level);
831 830 resp->kvno = htonl(token->kad->kvno);
832 resp.encrypted.call_id[0] = htonl(conn->channels[0].call_counter); 831 resp->ticket_len = htonl(token->kad->ticket_len);
833 resp.encrypted.call_id[1] = htonl(conn->channels[1].call_counter); 832 resp->encrypted.call_id[0] = htonl(conn->channels[0].call_counter);
834 resp.encrypted.call_id[2] = htonl(conn->channels[2].call_counter); 833 resp->encrypted.call_id[1] = htonl(conn->channels[1].call_counter);
835 resp.encrypted.call_id[3] = htonl(conn->channels[3].call_counter); 834 resp->encrypted.call_id[2] = htonl(conn->channels[2].call_counter);
835 resp->encrypted.call_id[3] = htonl(conn->channels[3].call_counter);
836 836
837 /* calculate the response checksum and then do the encryption */ 837 /* calculate the response checksum and then do the encryption */
838 rxkad_calc_response_checksum(&resp); 838 rxkad_calc_response_checksum(resp);
839 rxkad_encrypt_response(conn, &resp, token->kad); 839 rxkad_encrypt_response(conn, resp, token->kad);
840 return rxkad_send_response(conn, &sp->hdr, &resp, token->kad); 840 ret = rxkad_send_response(conn, &sp->hdr, resp, token->kad);
841 kfree(resp);
842 return ret;
841 843
842protocol_error: 844protocol_error:
843 trace_rxrpc_rx_eproto(NULL, sp->hdr.serial, eproto); 845 trace_rxrpc_rx_eproto(NULL, sp->hdr.serial, eproto);
@@ -1048,8 +1050,7 @@ static int rxkad_verify_response(struct rxrpc_connection *conn,
1048 struct sk_buff *skb, 1050 struct sk_buff *skb,
1049 u32 *_abort_code) 1051 u32 *_abort_code)
1050{ 1052{
1051 struct rxkad_response response 1053 struct rxkad_response *response;
1052 __attribute__((aligned(8))); /* must be aligned for crypto */
1053 struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 1054 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
1054 struct rxrpc_crypt session_key; 1055 struct rxrpc_crypt session_key;
1055 const char *eproto; 1056 const char *eproto;
@@ -1061,17 +1062,22 @@ static int rxkad_verify_response(struct rxrpc_connection *conn,
1061 1062
1062 _enter("{%d,%x}", conn->debug_id, key_serial(conn->server_key)); 1063 _enter("{%d,%x}", conn->debug_id, key_serial(conn->server_key));
1063 1064
1065 ret = -ENOMEM;
1066 response = kzalloc(sizeof(struct rxkad_response), GFP_NOFS);
1067 if (!response)
1068 goto temporary_error;
1069
1064 eproto = tracepoint_string("rxkad_rsp_short"); 1070 eproto = tracepoint_string("rxkad_rsp_short");
1065 abort_code = RXKADPACKETSHORT; 1071 abort_code = RXKADPACKETSHORT;
1066 if (skb_copy_bits(skb, sizeof(struct rxrpc_wire_header), 1072 if (skb_copy_bits(skb, sizeof(struct rxrpc_wire_header),
1067 &response, sizeof(response)) < 0) 1073 response, sizeof(*response)) < 0)
1068 goto protocol_error; 1074 goto protocol_error;
1069 if (!pskb_pull(skb, sizeof(response))) 1075 if (!pskb_pull(skb, sizeof(*response)))
1070 BUG(); 1076 BUG();
1071 1077
1072 version = ntohl(response.version); 1078 version = ntohl(response->version);
1073 ticket_len = ntohl(response.ticket_len); 1079 ticket_len = ntohl(response->ticket_len);
1074 kvno = ntohl(response.kvno); 1080 kvno = ntohl(response->kvno);
1075 _proto("Rx RESPONSE %%%u { v=%u kv=%u tl=%u }", 1081 _proto("Rx RESPONSE %%%u { v=%u kv=%u tl=%u }",
1076 sp->hdr.serial, version, kvno, ticket_len); 1082 sp->hdr.serial, version, kvno, ticket_len);
1077 1083
@@ -1105,31 +1111,31 @@ static int rxkad_verify_response(struct rxrpc_connection *conn,
1105 ret = rxkad_decrypt_ticket(conn, skb, ticket, ticket_len, &session_key, 1111 ret = rxkad_decrypt_ticket(conn, skb, ticket, ticket_len, &session_key,
1106 &expiry, _abort_code); 1112 &expiry, _abort_code);
1107 if (ret < 0) 1113 if (ret < 0)
1108 goto temporary_error_free; 1114 goto temporary_error_free_resp;
1109 1115
1110 /* use the session key from inside the ticket to decrypt the 1116 /* use the session key from inside the ticket to decrypt the
1111 * response */ 1117 * response */
1112 rxkad_decrypt_response(conn, &response, &session_key); 1118 rxkad_decrypt_response(conn, response, &session_key);
1113 1119
1114 eproto = tracepoint_string("rxkad_rsp_param"); 1120 eproto = tracepoint_string("rxkad_rsp_param");
1115 abort_code = RXKADSEALEDINCON; 1121 abort_code = RXKADSEALEDINCON;
1116 if (ntohl(response.encrypted.epoch) != conn->proto.epoch) 1122 if (ntohl(response->encrypted.epoch) != conn->proto.epoch)
1117 goto protocol_error_free; 1123 goto protocol_error_free;
1118 if (ntohl(response.encrypted.cid) != conn->proto.cid) 1124 if (ntohl(response->encrypted.cid) != conn->proto.cid)
1119 goto protocol_error_free; 1125 goto protocol_error_free;
1120 if (ntohl(response.encrypted.securityIndex) != conn->security_ix) 1126 if (ntohl(response->encrypted.securityIndex) != conn->security_ix)
1121 goto protocol_error_free; 1127 goto protocol_error_free;
1122 csum = response.encrypted.checksum; 1128 csum = response->encrypted.checksum;
1123 response.encrypted.checksum = 0; 1129 response->encrypted.checksum = 0;
1124 rxkad_calc_response_checksum(&response); 1130 rxkad_calc_response_checksum(response);
1125 eproto = tracepoint_string("rxkad_rsp_csum"); 1131 eproto = tracepoint_string("rxkad_rsp_csum");
1126 if (response.encrypted.checksum != csum) 1132 if (response->encrypted.checksum != csum)
1127 goto protocol_error_free; 1133 goto protocol_error_free;
1128 1134
1129 spin_lock(&conn->channel_lock); 1135 spin_lock(&conn->channel_lock);
1130 for (i = 0; i < RXRPC_MAXCALLS; i++) { 1136 for (i = 0; i < RXRPC_MAXCALLS; i++) {
1131 struct rxrpc_call *call; 1137 struct rxrpc_call *call;
1132 u32 call_id = ntohl(response.encrypted.call_id[i]); 1138 u32 call_id = ntohl(response->encrypted.call_id[i]);
1133 1139
1134 eproto = tracepoint_string("rxkad_rsp_callid"); 1140 eproto = tracepoint_string("rxkad_rsp_callid");
1135 if (call_id > INT_MAX) 1141 if (call_id > INT_MAX)
@@ -1153,12 +1159,12 @@ static int rxkad_verify_response(struct rxrpc_connection *conn,
1153 1159
1154 eproto = tracepoint_string("rxkad_rsp_seq"); 1160 eproto = tracepoint_string("rxkad_rsp_seq");
1155 abort_code = RXKADOUTOFSEQUENCE; 1161 abort_code = RXKADOUTOFSEQUENCE;
1156 if (ntohl(response.encrypted.inc_nonce) != conn->security_nonce + 1) 1162 if (ntohl(response->encrypted.inc_nonce) != conn->security_nonce + 1)
1157 goto protocol_error_free; 1163 goto protocol_error_free;
1158 1164
1159 eproto = tracepoint_string("rxkad_rsp_level"); 1165 eproto = tracepoint_string("rxkad_rsp_level");
1160 abort_code = RXKADLEVELFAIL; 1166 abort_code = RXKADLEVELFAIL;
1161 level = ntohl(response.encrypted.level); 1167 level = ntohl(response->encrypted.level);
1162 if (level > RXRPC_SECURITY_ENCRYPT) 1168 if (level > RXRPC_SECURITY_ENCRYPT)
1163 goto protocol_error_free; 1169 goto protocol_error_free;
1164 conn->params.security_level = level; 1170 conn->params.security_level = level;
@@ -1168,9 +1174,10 @@ static int rxkad_verify_response(struct rxrpc_connection *conn,
1168 * as for a client connection */ 1174 * as for a client connection */
1169 ret = rxrpc_get_server_data_key(conn, &session_key, expiry, kvno); 1175 ret = rxrpc_get_server_data_key(conn, &session_key, expiry, kvno);
1170 if (ret < 0) 1176 if (ret < 0)
1171 goto temporary_error_free; 1177 goto temporary_error_free_ticket;
1172 1178
1173 kfree(ticket); 1179 kfree(ticket);
1180 kfree(response);
1174 _leave(" = 0"); 1181 _leave(" = 0");
1175 return 0; 1182 return 0;
1176 1183
@@ -1179,12 +1186,15 @@ protocol_error_unlock:
1179protocol_error_free: 1186protocol_error_free:
1180 kfree(ticket); 1187 kfree(ticket);
1181protocol_error: 1188protocol_error:
1189 kfree(response);
1182 trace_rxrpc_rx_eproto(NULL, sp->hdr.serial, eproto); 1190 trace_rxrpc_rx_eproto(NULL, sp->hdr.serial, eproto);
1183 *_abort_code = abort_code; 1191 *_abort_code = abort_code;
1184 return -EPROTO; 1192 return -EPROTO;
1185 1193
1186temporary_error_free: 1194temporary_error_free_ticket:
1187 kfree(ticket); 1195 kfree(ticket);
1196temporary_error_free_resp:
1197 kfree(response);
1188temporary_error: 1198temporary_error:
1189 /* Ignore the response packet if we got a temporary error such as 1199 /* Ignore the response packet if we got a temporary error such as
1190 * ENOMEM. We just want to send the challenge again. Note that we 1200 * ENOMEM. We just want to send the challenge again. Note that we