@@ -1007,16 +1007,17 @@ static void esp_destroy(struct xfrm_state *x)
10071007 crypto_free_aead (aead );
10081008}
10091009
1010- static int esp_init_aead (struct xfrm_state * x )
1010+ static int esp_init_aead (struct xfrm_state * x , struct netlink_ext_ack * extack )
10111011{
10121012 char aead_name [CRYPTO_MAX_ALG_NAME ];
10131013 struct crypto_aead * aead ;
10141014 int err ;
10151015
1016- err = - ENAMETOOLONG ;
10171016 if (snprintf (aead_name , CRYPTO_MAX_ALG_NAME , "%s(%s)" ,
1018- x -> geniv , x -> aead -> alg_name ) >= CRYPTO_MAX_ALG_NAME )
1019- goto error ;
1017+ x -> geniv , x -> aead -> alg_name ) >= CRYPTO_MAX_ALG_NAME ) {
1018+ NL_SET_ERR_MSG (extack , "Algorithm name is too long" );
1019+ return - ENAMETOOLONG ;
1020+ }
10201021
10211022 aead = crypto_alloc_aead (aead_name , 0 , 0 );
10221023 err = PTR_ERR (aead );
@@ -1034,11 +1035,15 @@ static int esp_init_aead(struct xfrm_state *x)
10341035 if (err )
10351036 goto error ;
10361037
1038+ return 0 ;
1039+
10371040error :
1041+ NL_SET_ERR_MSG (extack , "Kernel was unable to initialize cryptographic operations" );
10381042 return err ;
10391043}
10401044
1041- static int esp_init_authenc (struct xfrm_state * x )
1045+ static int esp_init_authenc (struct xfrm_state * x ,
1046+ struct netlink_ext_ack * extack )
10421047{
10431048 struct crypto_aead * aead ;
10441049 struct crypto_authenc_key_param * param ;
@@ -1049,10 +1054,6 @@ static int esp_init_authenc(struct xfrm_state *x)
10491054 unsigned int keylen ;
10501055 int err ;
10511056
1052- err = - EINVAL ;
1053- if (!x -> ealg )
1054- goto error ;
1055-
10561057 err = - ENAMETOOLONG ;
10571058
10581059 if ((x -> props .flags & XFRM_STATE_ESN )) {
@@ -1061,22 +1062,28 @@ static int esp_init_authenc(struct xfrm_state *x)
10611062 x -> geniv ?: "" , x -> geniv ? "(" : "" ,
10621063 x -> aalg ? x -> aalg -> alg_name : "digest_null" ,
10631064 x -> ealg -> alg_name ,
1064- x -> geniv ? ")" : "" ) >= CRYPTO_MAX_ALG_NAME )
1065+ x -> geniv ? ")" : "" ) >= CRYPTO_MAX_ALG_NAME ) {
1066+ NL_SET_ERR_MSG (extack , "Algorithm name is too long" );
10651067 goto error ;
1068+ }
10661069 } else {
10671070 if (snprintf (authenc_name , CRYPTO_MAX_ALG_NAME ,
10681071 "%s%sauthenc(%s,%s)%s" ,
10691072 x -> geniv ?: "" , x -> geniv ? "(" : "" ,
10701073 x -> aalg ? x -> aalg -> alg_name : "digest_null" ,
10711074 x -> ealg -> alg_name ,
1072- x -> geniv ? ")" : "" ) >= CRYPTO_MAX_ALG_NAME )
1075+ x -> geniv ? ")" : "" ) >= CRYPTO_MAX_ALG_NAME ) {
1076+ NL_SET_ERR_MSG (extack , "Algorithm name is too long" );
10731077 goto error ;
1078+ }
10741079 }
10751080
10761081 aead = crypto_alloc_aead (authenc_name , 0 , 0 );
10771082 err = PTR_ERR (aead );
1078- if (IS_ERR (aead ))
1083+ if (IS_ERR (aead )) {
1084+ NL_SET_ERR_MSG (extack , "Kernel was unable to initialize cryptographic operations" );
10791085 goto error ;
1086+ }
10801087
10811088 x -> data = aead ;
10821089
@@ -1106,17 +1113,16 @@ static int esp_init_authenc(struct xfrm_state *x)
11061113 err = - EINVAL ;
11071114 if (aalg_desc -> uinfo .auth .icv_fullbits / 8 !=
11081115 crypto_aead_authsize (aead )) {
1109- pr_info ("ESP: %s digestsize %u != %u\n" ,
1110- x -> aalg -> alg_name ,
1111- crypto_aead_authsize (aead ),
1112- aalg_desc -> uinfo .auth .icv_fullbits / 8 );
1116+ NL_SET_ERR_MSG (extack , "Kernel was unable to initialize cryptographic operations" );
11131117 goto free_key ;
11141118 }
11151119
11161120 err = crypto_aead_setauthsize (
11171121 aead , x -> aalg -> alg_trunc_len / 8 );
1118- if (err )
1122+ if (err ) {
1123+ NL_SET_ERR_MSG (extack , "Kernel was unable to initialize cryptographic operations" );
11191124 goto free_key ;
1125+ }
11201126 }
11211127
11221128 param -> enckeylen = cpu_to_be32 ((x -> ealg -> alg_key_len + 7 ) / 8 );
@@ -1131,18 +1137,22 @@ static int esp_init_authenc(struct xfrm_state *x)
11311137 return err ;
11321138}
11331139
1134- static int esp_init_state (struct xfrm_state * x )
1140+ static int esp_init_state (struct xfrm_state * x , struct netlink_ext_ack * extack )
11351141{
11361142 struct crypto_aead * aead ;
11371143 u32 align ;
11381144 int err ;
11391145
11401146 x -> data = NULL ;
11411147
1142- if (x -> aead )
1143- err = esp_init_aead (x );
1144- else
1145- err = esp_init_authenc (x );
1148+ if (x -> aead ) {
1149+ err = esp_init_aead (x , extack );
1150+ } else if (x -> ealg ) {
1151+ err = esp_init_authenc (x , extack );
1152+ } else {
1153+ NL_SET_ERR_MSG (extack , "ESP: AEAD or CRYPT must be provided" );
1154+ err = - EINVAL ;
1155+ }
11461156
11471157 if (err )
11481158 goto error ;
@@ -1160,6 +1170,7 @@ static int esp_init_state(struct xfrm_state *x)
11601170
11611171 switch (encap -> encap_type ) {
11621172 default :
1173+ NL_SET_ERR_MSG (extack , "Unsupported encapsulation type for ESP" );
11631174 err = - EINVAL ;
11641175 goto error ;
11651176 case UDP_ENCAP_ESPINUDP :
0 commit comments