Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: Yutaro Hayakawa <yhayakawa3720@gmail.com>
Cc: netdev@vger.kernel.org, michio.honda@ed.ac.uk
Subject: Re: [PATCH RFC net-next] net/tls: Implement getsockopt SOL_TLS TLS_RX
Date: Fri, 28 Aug 2020 09:52:23 -0700	[thread overview]
Message-ID: <20200828095223.21d07617@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> (raw)
In-Reply-To: <20200818141224.5113-1-yhayakawa3720@gmail.com>

On Tue, 18 Aug 2020 14:12:24 +0000 Yutaro Hayakawa wrote:

> @@ -352,7 +352,11 @@ static int do_tls_getsockopt_tx(struct sock *sk, char __user *optval,
>  	}
>  
>  	/* get user crypto info */
> -	crypto_info = &ctx->crypto_send.info;
> +	if (tx) {
> +		crypto_info = &ctx->crypto_send.info;
> +	} else {
> +		crypto_info = &ctx->crypto_recv.info;
> +	}

No need for parenthesis, if both branches have one line.

>  
>  	if (!TLS_CRYPTO_INFO_READY(crypto_info)) {
>  		rc = -EBUSY;
> @@ -378,11 +382,19 @@ static int do_tls_getsockopt_tx(struct sock *sk, char __user *optval,
>  			goto out;
>  		}
>  		lock_sock(sk);
> -		memcpy(crypto_info_aes_gcm_128->iv,
> -		       ctx->tx.iv + TLS_CIPHER_AES_GCM_128_SALT_SIZE,
> -		       TLS_CIPHER_AES_GCM_128_IV_SIZE);
> -		memcpy(crypto_info_aes_gcm_128->rec_seq, ctx->tx.rec_seq,
> -		       TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE);
> +		if (tx) {
> +			memcpy(crypto_info_aes_gcm_128->iv,
> +			       ctx->tx.iv + TLS_CIPHER_AES_GCM_128_SALT_SIZE,
> +			       TLS_CIPHER_AES_GCM_128_IV_SIZE);
> +			memcpy(crypto_info_aes_gcm_128->rec_seq, ctx->tx.rec_seq,
> +			       TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE);
> +		} else {
> +			memcpy(crypto_info_aes_gcm_128->iv,
> +			       ctx->rx.iv + TLS_CIPHER_AES_GCM_128_SALT_SIZE,
> +			       TLS_CIPHER_AES_GCM_128_IV_SIZE);
> +			memcpy(crypto_info_aes_gcm_128->rec_seq, ctx->rx.rec_seq,
> +			       TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE);
> +		}

Instead of all the duplication choose the right struct cipher_context
above, like we do for crypto_info.

>  		release_sock(sk);
>  		if (copy_to_user(optval,
>  				 crypto_info_aes_gcm_128,
> @@ -402,11 +414,19 @@ static int do_tls_getsockopt_tx(struct sock *sk, char __user *optval,
>  			goto out;
>  		}
>  		lock_sock(sk);
> -		memcpy(crypto_info_aes_gcm_256->iv,
> -		       ctx->tx.iv + TLS_CIPHER_AES_GCM_256_SALT_SIZE,
> -		       TLS_CIPHER_AES_GCM_256_IV_SIZE);
> -		memcpy(crypto_info_aes_gcm_256->rec_seq, ctx->tx.rec_seq,
> -		       TLS_CIPHER_AES_GCM_256_REC_SEQ_SIZE);
> +		if (tx) {
> +			memcpy(crypto_info_aes_gcm_256->iv,
> +			       ctx->tx.iv + TLS_CIPHER_AES_GCM_256_SALT_SIZE,
> +			       TLS_CIPHER_AES_GCM_256_IV_SIZE);
> +			memcpy(crypto_info_aes_gcm_256->rec_seq, ctx->tx.rec_seq,
> +			       TLS_CIPHER_AES_GCM_256_REC_SEQ_SIZE);
> +		} else {
> +			memcpy(crypto_info_aes_gcm_256->iv,
> +			       ctx->rx.iv + TLS_CIPHER_AES_GCM_256_SALT_SIZE,
> +			       TLS_CIPHER_AES_GCM_256_IV_SIZE);
> +			memcpy(crypto_info_aes_gcm_256->rec_seq, ctx->rx.rec_seq,
> +			       TLS_CIPHER_AES_GCM_256_REC_SEQ_SIZE);
> +		}

ditto.

>  		release_sock(sk);
>  		if (copy_to_user(optval,
>  				 crypto_info_aes_gcm_256,


  parent reply	other threads:[~2020-08-28 16:52 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-18 14:12 Yutaro Hayakawa
2020-08-28 11:14 ` Yutaro Hayakawa
2020-08-28 16:52 ` Jakub Kicinski [this message]
2020-08-30 14:01   ` [PATCH RFC v2 " Yutaro Hayakawa
2020-08-30 17:48     ` Yutaro Hayakawa
2020-08-30 19:07       ` [PATCH RFC v3 " Yutaro Hayakawa
2020-08-31 18:30         ` Jakub Kicinski
2020-09-01 13:59           ` [PATCH " Yutaro Hayakawa
2020-09-01 18:47             ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200828095223.21d07617@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com \
    --to=kuba@kernel.org \
    --cc=michio.honda@ed.ac.uk \
    --cc=netdev@vger.kernel.org \
    --cc=yhayakawa3720@gmail.com \
    --subject='Re: [PATCH RFC net-next] net/tls: Implement getsockopt SOL_TLS TLS_RX' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).