Commit 0a26cf3f authored by Doron Roberts-Kedes's avatar Doron Roberts-Kedes Committed by David S. Miller

tls: Skip zerocopy path for ITER_KVEC

The zerocopy path ultimately calls iov_iter_get_pages, which defines the
step function for ITER_KVECs as simply, return -EFAULT. Taking the
non-zerocopy path for ITER_KVECs avoids the unnecessary fallback.

See https://lore.kernel.org/lkml/20150401023311.GL29656@ZenIV.linux.org.uk/T/#u
for a discussion of why zerocopy for vmalloc data is not a good idea.

Discovered while testing NBD traffic encrypted with ktls.

Fixes: c46234eb ("tls: RX path for ktls")
Signed-off-by: default avatarDoron Roberts-Kedes <doronrk@fb.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 2ed9db30
...@@ -362,6 +362,7 @@ int tls_sw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) ...@@ -362,6 +362,7 @@ int tls_sw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
int record_room; int record_room;
bool full_record; bool full_record;
int orig_size; int orig_size;
bool is_kvec = msg->msg_iter.type & ITER_KVEC;
if (msg->msg_flags & ~(MSG_MORE | MSG_DONTWAIT | MSG_NOSIGNAL)) if (msg->msg_flags & ~(MSG_MORE | MSG_DONTWAIT | MSG_NOSIGNAL))
return -ENOTSUPP; return -ENOTSUPP;
...@@ -410,8 +411,7 @@ int tls_sw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) ...@@ -410,8 +411,7 @@ int tls_sw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
try_to_copy -= required_size - ctx->sg_encrypted_size; try_to_copy -= required_size - ctx->sg_encrypted_size;
full_record = true; full_record = true;
} }
if (!is_kvec && (full_record || eor)) {
if (full_record || eor) {
ret = zerocopy_from_iter(sk, &msg->msg_iter, ret = zerocopy_from_iter(sk, &msg->msg_iter,
try_to_copy, &ctx->sg_plaintext_num_elem, try_to_copy, &ctx->sg_plaintext_num_elem,
&ctx->sg_plaintext_size, &ctx->sg_plaintext_size,
...@@ -779,6 +779,7 @@ int tls_sw_recvmsg(struct sock *sk, ...@@ -779,6 +779,7 @@ int tls_sw_recvmsg(struct sock *sk,
bool cmsg = false; bool cmsg = false;
int target, err = 0; int target, err = 0;
long timeo; long timeo;
bool is_kvec = msg->msg_iter.type & ITER_KVEC;
flags |= nonblock; flags |= nonblock;
...@@ -822,7 +823,7 @@ int tls_sw_recvmsg(struct sock *sk, ...@@ -822,7 +823,7 @@ int tls_sw_recvmsg(struct sock *sk,
page_count = iov_iter_npages(&msg->msg_iter, page_count = iov_iter_npages(&msg->msg_iter,
MAX_SKB_FRAGS); MAX_SKB_FRAGS);
to_copy = rxm->full_len - tls_ctx->rx.overhead_size; to_copy = rxm->full_len - tls_ctx->rx.overhead_size;
if (to_copy <= len && page_count < MAX_SKB_FRAGS && if (!is_kvec && to_copy <= len && page_count < MAX_SKB_FRAGS &&
likely(!(flags & MSG_PEEK))) { likely(!(flags & MSG_PEEK))) {
struct scatterlist sgin[MAX_SKB_FRAGS + 1]; struct scatterlist sgin[MAX_SKB_FRAGS + 1];
int pages = 0; int pages = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment