From: Dan Carpenter Date: Fri, 23 Jun 2017 10:15:44 +0000 (+0300) Subject: tls: return -EFAULT if copy_to_user() fails X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=ac55cd619335c577f29eea599a6a35b6b48797e8;p=GitHub%2Fmoto-9609%2Fandroid_kernel_motorola_exynos9610.git tls: return -EFAULT if copy_to_user() fails The copy_to_user() function returns the number of bytes remaining but we want to return -EFAULT here. Fixes: 3c4d7559159b ("tls: kernel TLS support") Signed-off-by: Dan Carpenter Acked-by: Dave Watson Signed-off-by: David S. Miller --- diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c index 2ebc328bda96..a03130a47b85 100644 --- a/net/tls/tls_main.c +++ b/net/tls/tls_main.c @@ -273,7 +273,8 @@ static int do_tls_getsockopt_tx(struct sock *sk, char __user *optval, } if (len == sizeof(crypto_info)) { - rc = copy_to_user(optval, crypto_info, sizeof(*crypto_info)); + if (copy_to_user(optval, crypto_info, sizeof(*crypto_info))) + rc = -EFAULT; goto out; } @@ -293,9 +294,10 @@ static int do_tls_getsockopt_tx(struct sock *sk, char __user *optval, memcpy(crypto_info_aes_gcm_128->iv, ctx->iv, TLS_CIPHER_AES_GCM_128_IV_SIZE); release_sock(sk); - rc = copy_to_user(optval, - crypto_info_aes_gcm_128, - sizeof(*crypto_info_aes_gcm_128)); + if (copy_to_user(optval, + crypto_info_aes_gcm_128, + sizeof(*crypto_info_aes_gcm_128))) + rc = -EFAULT; break; } default: