Skip to content

Commit 5f309ad

Browse files
qsnkuba-moo
authored andcommitted
tls: get crypto_info size from tls_cipher_desc in do_tls_setsockopt_conf
We can simplify do_tls_setsockopt_conf using tls_cipher_desc. Also use get_cipher_desc's result to check if the cipher_type coming from userspace is valid. Signed-off-by: Sabrina Dubroca <sd@queasysnail.net> Link: https://lore.kernel.org/r/e97658eb4c6a5832f8ba20a06c4f36a77763c59e.1692977948.git.sd@queasysnail.net Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent e907277 commit 5f309ad

1 file changed

Lines changed: 8 additions & 31 deletions

File tree

net/tls/tls_main.c

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ static int do_tls_setsockopt_conf(struct sock *sk, sockptr_t optval,
739739
struct tls_crypto_info *crypto_info;
740740
struct tls_crypto_info *alt_crypto_info;
741741
struct tls_context *ctx = tls_get_ctx(sk);
742-
size_t optsize;
742+
const struct tls_cipher_desc *cipher_desc;
743743
int rc = 0;
744744
int conf;
745745

@@ -780,46 +780,23 @@ static int do_tls_setsockopt_conf(struct sock *sk, sockptr_t optval,
780780
}
781781
}
782782

783-
switch (crypto_info->cipher_type) {
784-
case TLS_CIPHER_AES_GCM_128:
785-
optsize = sizeof(struct tls12_crypto_info_aes_gcm_128);
786-
break;
787-
case TLS_CIPHER_AES_GCM_256: {
788-
optsize = sizeof(struct tls12_crypto_info_aes_gcm_256);
789-
break;
783+
cipher_desc = get_cipher_desc(crypto_info->cipher_type);
784+
if (!cipher_desc) {
785+
rc = -EINVAL;
786+
goto err_crypto_info;
790787
}
791-
case TLS_CIPHER_AES_CCM_128:
792-
optsize = sizeof(struct tls12_crypto_info_aes_ccm_128);
793-
break;
794-
case TLS_CIPHER_CHACHA20_POLY1305:
795-
optsize = sizeof(struct tls12_crypto_info_chacha20_poly1305);
796-
break;
797-
case TLS_CIPHER_SM4_GCM:
798-
optsize = sizeof(struct tls12_crypto_info_sm4_gcm);
799-
break;
800-
case TLS_CIPHER_SM4_CCM:
801-
optsize = sizeof(struct tls12_crypto_info_sm4_ccm);
802-
break;
788+
789+
switch (crypto_info->cipher_type) {
803790
case TLS_CIPHER_ARIA_GCM_128:
804-
if (crypto_info->version != TLS_1_2_VERSION) {
805-
rc = -EINVAL;
806-
goto err_crypto_info;
807-
}
808-
optsize = sizeof(struct tls12_crypto_info_aria_gcm_128);
809-
break;
810791
case TLS_CIPHER_ARIA_GCM_256:
811792
if (crypto_info->version != TLS_1_2_VERSION) {
812793
rc = -EINVAL;
813794
goto err_crypto_info;
814795
}
815-
optsize = sizeof(struct tls12_crypto_info_aria_gcm_256);
816796
break;
817-
default:
818-
rc = -EINVAL;
819-
goto err_crypto_info;
820797
}
821798

822-
if (optlen != optsize) {
799+
if (optlen != cipher_desc->crypto_info) {
823800
rc = -EINVAL;
824801
goto err_crypto_info;
825802
}

0 commit comments

Comments
 (0)