@@ -773,8 +773,7 @@ static int rxkad_respond_to_challenge(struct rxrpc_connection *conn,
773
773
{
774
774
const struct rxrpc_key_token * token ;
775
775
struct rxkad_challenge challenge ;
776
- struct rxkad_response resp
777
- __attribute__((aligned (8 ))); /* must be aligned for crypto */
776
+ struct rxkad_response * resp ;
778
777
struct rxrpc_skb_priv * sp = rxrpc_skb (skb );
779
778
const char * eproto ;
780
779
u32 version , nonce , min_level , abort_code ;
@@ -818,26 +817,29 @@ static int rxkad_respond_to_challenge(struct rxrpc_connection *conn,
818
817
token = conn -> params .key -> payload .data [0 ];
819
818
820
819
/* build the response packet */
821
- memset (& resp , 0 , sizeof (resp ));
822
-
823
- resp .version = htonl (RXKAD_VERSION );
824
- resp .encrypted .epoch = htonl (conn -> proto .epoch );
825
- resp .encrypted .cid = htonl (conn -> proto .cid );
826
- resp .encrypted .securityIndex = htonl (conn -> security_ix );
827
- resp .encrypted .inc_nonce = htonl (nonce + 1 );
828
- resp .encrypted .level = htonl (conn -> params .security_level );
829
- resp .kvno = htonl (token -> kad -> kvno );
830
- resp .ticket_len = htonl (token -> kad -> ticket_len );
831
-
832
- resp .encrypted .call_id [0 ] = htonl (conn -> channels [0 ].call_counter );
833
- resp .encrypted .call_id [1 ] = htonl (conn -> channels [1 ].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 );
820
+ resp = kzalloc (sizeof (struct rxkad_response ), GFP_NOFS );
821
+ if (!resp )
822
+ return - ENOMEM ;
823
+
824
+ resp -> version = htonl (RXKAD_VERSION );
825
+ resp -> encrypted .epoch = htonl (conn -> proto .epoch );
826
+ resp -> encrypted .cid = htonl (conn -> proto .cid );
827
+ resp -> encrypted .securityIndex = htonl (conn -> security_ix );
828
+ resp -> encrypted .inc_nonce = htonl (nonce + 1 );
829
+ resp -> encrypted .level = htonl (conn -> params .security_level );
830
+ resp -> kvno = htonl (token -> kad -> kvno );
831
+ resp -> ticket_len = htonl (token -> kad -> ticket_len );
832
+ resp -> encrypted .call_id [0 ] = htonl (conn -> channels [0 ].call_counter );
833
+ resp -> encrypted .call_id [1 ] = htonl (conn -> channels [1 ].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
837
/* calculate the response checksum and then do the encryption */
838
- rxkad_calc_response_checksum (& resp );
839
- rxkad_encrypt_response (conn , & resp , token -> kad );
840
- return rxkad_send_response (conn , & sp -> hdr , & resp , token -> kad );
838
+ rxkad_calc_response_checksum (resp );
839
+ rxkad_encrypt_response (conn , resp , token -> kad );
840
+ ret = rxkad_send_response (conn , & sp -> hdr , resp , token -> kad );
841
+ kfree (resp );
842
+ return ret ;
841
843
842
844
protocol_error :
843
845
trace_rxrpc_rx_eproto (NULL , sp -> hdr .serial , eproto );
@@ -1048,8 +1050,7 @@ static int rxkad_verify_response(struct rxrpc_connection *conn,
1048
1050
struct sk_buff * skb ,
1049
1051
u32 * _abort_code )
1050
1052
{
1051
- struct rxkad_response response
1052
- __attribute__((aligned (8 ))); /* must be aligned for crypto */
1053
+ struct rxkad_response * response ;
1053
1054
struct rxrpc_skb_priv * sp = rxrpc_skb (skb );
1054
1055
struct rxrpc_crypt session_key ;
1055
1056
const char * eproto ;
@@ -1061,17 +1062,22 @@ static int rxkad_verify_response(struct rxrpc_connection *conn,
1061
1062
1062
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
1070
eproto = tracepoint_string ("rxkad_rsp_short" );
1065
1071
abort_code = RXKADPACKETSHORT ;
1066
1072
if (skb_copy_bits (skb , sizeof (struct rxrpc_wire_header ),
1067
- & response , sizeof (response )) < 0 )
1073
+ response , sizeof (* response )) < 0 )
1068
1074
goto protocol_error ;
1069
- if (!pskb_pull (skb , sizeof (response )))
1075
+ if (!pskb_pull (skb , sizeof (* response )))
1070
1076
BUG ();
1071
1077
1072
- version = ntohl (response . version );
1073
- ticket_len = ntohl (response . ticket_len );
1074
- kvno = ntohl (response . kvno );
1078
+ version = ntohl (response -> version );
1079
+ ticket_len = ntohl (response -> ticket_len );
1080
+ kvno = ntohl (response -> kvno );
1075
1081
_proto ("Rx RESPONSE %%%u { v=%u kv=%u tl=%u }" ,
1076
1082
sp -> hdr .serial , version , kvno , ticket_len );
1077
1083
@@ -1105,31 +1111,31 @@ static int rxkad_verify_response(struct rxrpc_connection *conn,
1105
1111
ret = rxkad_decrypt_ticket (conn , skb , ticket , ticket_len , & session_key ,
1106
1112
& expiry , _abort_code );
1107
1113
if (ret < 0 )
1108
- goto temporary_error_free ;
1114
+ goto temporary_error_free_resp ;
1109
1115
1110
1116
/* use the session key from inside the ticket to decrypt the
1111
1117
* response */
1112
- rxkad_decrypt_response (conn , & response , & session_key );
1118
+ rxkad_decrypt_response (conn , response , & session_key );
1113
1119
1114
1120
eproto = tracepoint_string ("rxkad_rsp_param" );
1115
1121
abort_code = RXKADSEALEDINCON ;
1116
- if (ntohl (response . encrypted .epoch ) != conn -> proto .epoch )
1122
+ if (ntohl (response -> encrypted .epoch ) != conn -> proto .epoch )
1117
1123
goto protocol_error_free ;
1118
- if (ntohl (response . encrypted .cid ) != conn -> proto .cid )
1124
+ if (ntohl (response -> encrypted .cid ) != conn -> proto .cid )
1119
1125
goto protocol_error_free ;
1120
- if (ntohl (response . encrypted .securityIndex ) != conn -> security_ix )
1126
+ if (ntohl (response -> encrypted .securityIndex ) != conn -> security_ix )
1121
1127
goto protocol_error_free ;
1122
- csum = response . encrypted .checksum ;
1123
- response . encrypted .checksum = 0 ;
1124
- rxkad_calc_response_checksum (& response );
1128
+ csum = response -> encrypted .checksum ;
1129
+ response -> encrypted .checksum = 0 ;
1130
+ rxkad_calc_response_checksum (response );
1125
1131
eproto = tracepoint_string ("rxkad_rsp_csum" );
1126
- if (response . encrypted .checksum != csum )
1132
+ if (response -> encrypted .checksum != csum )
1127
1133
goto protocol_error_free ;
1128
1134
1129
1135
spin_lock (& conn -> channel_lock );
1130
1136
for (i = 0 ; i < RXRPC_MAXCALLS ; i ++ ) {
1131
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
1140
eproto = tracepoint_string ("rxkad_rsp_callid" );
1135
1141
if (call_id > INT_MAX )
@@ -1153,12 +1159,12 @@ static int rxkad_verify_response(struct rxrpc_connection *conn,
1153
1159
1154
1160
eproto = tracepoint_string ("rxkad_rsp_seq" );
1155
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
1163
goto protocol_error_free ;
1158
1164
1159
1165
eproto = tracepoint_string ("rxkad_rsp_level" );
1160
1166
abort_code = RXKADLEVELFAIL ;
1161
- level = ntohl (response . encrypted .level );
1167
+ level = ntohl (response -> encrypted .level );
1162
1168
if (level > RXRPC_SECURITY_ENCRYPT )
1163
1169
goto protocol_error_free ;
1164
1170
conn -> params .security_level = level ;
@@ -1168,9 +1174,10 @@ static int rxkad_verify_response(struct rxrpc_connection *conn,
1168
1174
* as for a client connection */
1169
1175
ret = rxrpc_get_server_data_key (conn , & session_key , expiry , kvno );
1170
1176
if (ret < 0 )
1171
- goto temporary_error_free ;
1177
+ goto temporary_error_free_ticket ;
1172
1178
1173
1179
kfree (ticket );
1180
+ kfree (response );
1174
1181
_leave (" = 0" );
1175
1182
return 0 ;
1176
1183
@@ -1179,12 +1186,15 @@ static int rxkad_verify_response(struct rxrpc_connection *conn,
1179
1186
protocol_error_free :
1180
1187
kfree (ticket );
1181
1188
protocol_error :
1189
+ kfree (response );
1182
1190
trace_rxrpc_rx_eproto (NULL , sp -> hdr .serial , eproto );
1183
1191
* _abort_code = abort_code ;
1184
1192
return - EPROTO ;
1185
1193
1186
- temporary_error_free :
1194
+ temporary_error_free_ticket :
1187
1195
kfree (ticket );
1196
+ temporary_error_free_resp :
1197
+ kfree (response );
1188
1198
temporary_error :
1189
1199
/* Ignore the response packet if we got a temporary error such as
1190
1200
* ENOMEM. We just want to send the challenge again. Note that we
0 commit comments