All of lore.kernel.org
 help / color / mirror / Atom feed
From: Boris Pismenny <borisp@mellanox.com>
To: Dave Watson <davejwatson@fb.com>,
	"David S. Miller" <davem@davemloft.net>,
	Tom Herbert <tom@quantonium.net>,
	Alexei Starovoitov <alexei.starovoitov@gmail.com>,
	herbert@gondor.apana.org.au, linux-crypto@vger.kernel.org,
	netdev@vger.kernel.org
Cc: Atul Gupta <atul.gupta@chelsio.com>,
	Vakul Garg <vakul.garg@nxp.com>,
	Hannes Frederic Sowa <hannes@stressinduktion.org>,
	Steffen Klassert <steffen.klassert@secunet.com>,
	John Fastabend <john.fastabend@gmail.com>,
	Daniel Borkmann <daniel@iogearbox.net>
Subject: Re: [PATCH net-next 5/6] tls: RX path for ktls
Date: Wed, 21 Mar 2018 07:20:55 +0200	[thread overview]
Message-ID: <95b3174b-c860-3c87-2c8e-0917ccb72f1d@mellanox.com> (raw)
In-Reply-To: <20180320175434.GA23938@davejwatson-mba.local>



On 3/20/2018 7:54 PM, Dave Watson wrote:
> Add rx path for tls software implementation.
> 
> recvmsg, splice_read, and poll implemented.
> 
> An additional sockopt TLS_RX is added, with the same interface as
> TLS_TX.  Either TLX_RX or TLX_TX may be provided separately, or
> together (with two different setsockopt calls with appropriate keys).
> 
> Control messages are passed via CMSG in a similar way to transmit.
> If no cmsg buffer is passed, then only application data records
> will be passed to userspace, and EIO is returned for other types of
> alerts.
> 
> EBADMSG is passed for decryption errors, and EMSGSIZE is passed for
> framing errors (either framing too big *or* too small with crypto
> overhead). EINVAL is returned for TLS versions that do not match the
> original setsockopt call.  All are unrecoverable.
> 
> strparser is used to parse TLS framing.   Decryption is done directly
> in to userspace buffers if they are large enough to support it, otherwise
> sk_cow_data is called (similar to ipsec), and buffers are decrypted in
> place and copied.  splice_read always decrypts in place, since no
> buffers are provided to decrypt in to.
> 
> sk_poll is overridden, and only returns POLLIN if a full TLS message is
> received.  Otherwise we wait for strparser to finish reading a full frame.
> Actual decryption is only done during recvmsg or splice_read calls.
> 
> Signed-off-by: Dave Watson <davejwatson@fb.com>
> ---
...
> +
> +static int tls_read_size(struct strparser *strp, struct sk_buff *skb)
> +{
> +	struct tls_context *tls_ctx = tls_get_ctx(strp->sk);
> +	struct tls_sw_context *ctx = tls_sw_ctx(tls_ctx);
> +	char header[tls_ctx->rx.prepend_size];
> +	struct strp_msg *rxm = strp_msg(skb);
> +	size_t cipher_overhead;
> +	size_t data_len = 0;
> +	int ret;
> +
> +	/* Verify that we have a full TLS header, or wait for more data */
> +	if (rxm->offset + tls_ctx->rx.prepend_size > skb->len)
> +		return 0;
> +
> +	/* Linearize header to local buffer */
> +	ret = skb_copy_bits(skb, rxm->offset, header, tls_ctx->rx.prepend_size);
> +
> +	if (ret < 0)
> +		goto read_failure;
> +
> +	ctx->control = header[0];
> +
> +	data_len = ((header[4] & 0xFF) | (header[3] << 8));
> +
> +	cipher_overhead = tls_ctx->rx.tag_size + tls_ctx->rx.iv_size;
> +
> +	if (data_len > TLS_MAX_PAYLOAD_SIZE + cipher_overhead) {
> +		ret = -EMSGSIZE;
> +		goto read_failure;
> +	}
> +	if (data_len < cipher_overhead) {
> +		ret = -EMSGSIZE;

I think this should be considered EBADMSG, because this error is cipher 
dependent. At least, that's what happens within OpenSSL. Also, EMSGSIZE 
is usually used only for too long messages.

> +		goto read_failure;
> +	}
> +
> +	if (header[1] != TLS_VERSION_MINOR(tls_ctx->crypto_recv.version) ||
> +	    header[2] != TLS_VERSION_MAJOR(tls_ctx->crypto_recv.version)) {
> +		ret = -EINVAL;
> +		goto read_failure;
> +	}
> +
> +	return data_len + TLS_HEADER_SIZE;
> +
> +read_failure:
> +	tls_err_abort(strp->sk, ret);
> +
> +	return ret;
> +}
> +
...

  reply	other threads:[~2018-03-21  5:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1521567760.git.davejwatson@fb.com>
2018-03-20 17:53 ` [PATCH net-next 1/6] tls: Generalize zerocopy_from_iter Dave Watson
2018-03-20 17:53 ` [PATCH net-next 2/6] tls: Move cipher info to a separate struct Dave Watson
2018-03-20 17:53 ` [PATCH net-next 3/6] tls: Pass error code explicitly to tls_err_abort Dave Watson
2018-03-20 17:54 ` [PATCH net-next 4/6] tls: Refactor variable names Dave Watson
2018-03-20 17:54 ` [PATCH net-next 5/6] tls: RX path for ktls Dave Watson
2018-03-21  5:20   ` Boris Pismenny [this message]
2018-03-21 15:10     ` Dave Watson
2018-03-20 17:54 ` [PATCH net-next 6/6] tls: Add receive path documentation Dave Watson

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=95b3174b-c860-3c87-2c8e-0917ccb72f1d@mellanox.com \
    --to=borisp@mellanox.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=atul.gupta@chelsio.com \
    --cc=daniel@iogearbox.net \
    --cc=davejwatson@fb.com \
    --cc=davem@davemloft.net \
    --cc=hannes@stressinduktion.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=john.fastabend@gmail.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=steffen.klassert@secunet.com \
    --cc=tom@quantonium.net \
    --cc=vakul.garg@nxp.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.