netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Przemek Kitszel <przemyslaw.kitszel@intel.com>
To: Simon Horman <horms@kernel.org>
Cc: Boris Pismenny <borisp@nvidia.com>,
	John Fastabend <john.fastabend@gmail.com>,
	<netdev@vger.kernel.org>, "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Paolo Abeni <pabeni@redhat.com>, Jakub Kicinski <kuba@kernel.org>
Subject: Re: [PATCH net-next] net: tls: Pass union tls_crypto_context pointer to memzero_explicit
Date: Fri, 5 Jul 2024 15:54:59 +0200	[thread overview]
Message-ID: <bb960821-a67b-4d61-afeb-ead10ea2a4dc@intel.com> (raw)
In-Reply-To: <20240705-tls-memzero-v1-1-0496871cfe9b@kernel.org>

On 7/5/24 15:41, Simon Horman wrote:
> Pass union tls_crypto_context pointer, rather than struct
> tls_crypto_info pointer, to memzero_explicit().
> 
> The address of the pointer is the same before and after.
> But the new construct means that the size of the dereferenced pointer type
> matches the size being zeroed. Which aids static analysis.
> 
> As reported by Smatch:
> 
>    .../tls_main.c:842 do_tls_setsockopt_conf() error: memzero_explicit() 'crypto_info' too small (4 vs 56)
> 
> No functional change intended.
> Compile tested only.
> 
> Signed-off-by: Simon Horman <horms@kernel.org>

Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
one small nitpick only

> ---
>   net/tls/tls_main.c | 9 ++++++---
>   1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c
> index 90b7f253d363..e712b2faeb81 100644
> --- a/net/tls/tls_main.c
> +++ b/net/tls/tls_main.c
> @@ -616,6 +616,7 @@ static int do_tls_setsockopt_conf(struct sock *sk, sockptr_t optval,
>   	struct tls_crypto_info *alt_crypto_info;
>   	struct tls_context *ctx = tls_get_ctx(sk);
>   	const struct tls_cipher_desc *cipher_desc;
> +	union tls_crypto_context *crypto_ctx;
>   	int rc = 0;
>   	int conf;
>   
> @@ -623,13 +624,15 @@ static int do_tls_setsockopt_conf(struct sock *sk, sockptr_t optval,
>   		return -EINVAL;
>   
>   	if (tx) {
> -		crypto_info = &ctx->crypto_send.info;
> +		crypto_ctx = &ctx->crypto_send;
>   		alt_crypto_info = &ctx->crypto_recv.info;
>   	} else {
> -		crypto_info = &ctx->crypto_recv.info;
> +		crypto_ctx = &ctx->crypto_recv;
>   		alt_crypto_info = &ctx->crypto_send.info;
>   	}
>   
> +	crypto_info = &crypto_ctx->info;
> +
>   	/* Currently we don't support set crypto info more than one time */
>   	if (TLS_CRYPTO_INFO_READY(crypto_info))
>   		return -EBUSY;
> @@ -710,7 +713,7 @@ static int do_tls_setsockopt_conf(struct sock *sk, sockptr_t optval,
>   	return 0;
>   
>   err_crypto_info:
> -	memzero_explicit(crypto_info, sizeof(union tls_crypto_context));
> +	memzero_explicit(crypto_ctx, sizeof(union tls_crypto_context));

nit: That's a good fix to aid static analyzers, and reviewers.
Now it's also easy to follow the standard style and pass
sizeof(*crypto_ctx) instead of the type.

>   	return rc;
>   }


  reply	other threads:[~2024-07-05 13:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-05 13:41 [PATCH net-next] net: tls: Pass union tls_crypto_context pointer to memzero_explicit Simon Horman
2024-07-05 13:54 ` Przemek Kitszel [this message]
2024-07-05 15:21   ` Simon Horman

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=bb960821-a67b-4d61-afeb-ead10ea2a4dc@intel.com \
    --to=przemyslaw.kitszel@intel.com \
    --cc=borisp@nvidia.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).