net/tls: move version check after second userspace fetch
Subsystems (3)
PATCH 1/1 net/tls: move version check after second userspace fetch
Even the userspace buffer optval passed the version check (i.e., tmp_crypto_info.version == TLS_1_2_VERSION) after the first fetch, it can still be changed before the second copy_from_user() and hence, a version different than TLS_1_2_VERSION may be copied into crypto_info. This patch moves the version check after the second userspace fetch.
--- net/tls/tls_main.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
net/tls/tls_main.c +6 -6
@@ -354,12 +354,6 @@ static int do_tls_setsockopt_tx(struct sock *sk, char __user *optval, goto out; } -/* check version */ -if (tmp_crypto_info.version !=TLS_1_2_VERSION ) { - rc = -ENOTSUPP ; - goto out; - } -/* get user crypto info */ crypto_info = &ctx->crypto_send;
@@ -382,6 +376,12 @@ static int do_tls_setsockopt_tx(struct sock *sk, char __user *optval, rc = -EFAULT ; goto err_crypto_info; } + +/* check version */ +if (crypto_info->version !=TLS_1_2_VERSION ) { + rc = -ENOTSUPP ; + goto err_crypto_info; + }break ; }default :
Signature · 1 line
2.7.4
David Miller
maintainerFrom: Meng Xu <[email protected]>
Date: Sun, 24 Sep 2017 11:14:55 -0400
Quoted 16 lines
net/tls/tls_main.c +6
-0@@ -382,6 +376,12 @@ static int do_tls_setsockopt_tx(struct sock *sk, char __user *optval, rc = -EFAULT ; goto err_crypto_info; } + +/* check version */ +if (crypto_info->version !=TLS_1_2_VERSION ) { + rc = -ENOTSUPP ; + goto err_crypto_info; + }break ; }default :Signature · 1 line
2.7.4
Please, again, deduce this into a single userspace copy. Otherwise we're going to add this check for every cipher we add new support for.
Copy the on-stack crypto info ("tmp_crypto_info") into 'crypto_info' and then bring in from userspace any further bytes that need to be copied.
That guarantees that the version will not change, and the existing check can stay where it is.