Commit 06030dba authored by Daniel Borkmann's avatar Daniel Borkmann Committed by David S. Miller

tls: fix waitall behavior in tls_sw_recvmsg

Current behavior in tls_sw_recvmsg() is to wait for incoming tls
messages and copy up to exactly len bytes of data that the user
provided. This is problematic in the sense that i) if no packet
is currently queued in strparser we keep waiting until one has been
processed and pushed into tls receive layer for tls_wait_data() to
wake up and push the decrypted bits to user space. Given after
tls decryption, we're back at streaming data, use sock_rcvlowat()
hint from tcp socket instead. Retain current behavior with MSG_WAITALL
flag and otherwise use the hint target for breaking the loop and
returning to application. This is done if currently no ctx->recv_pkt
is ready, otherwise continue to process it from our strparser
backlog.

Fixes: c46234eb ("tls: RX path for ktls")
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarDave Watson <davejwatson@fb.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a447da7d
...@@ -754,7 +754,7 @@ int tls_sw_recvmsg(struct sock *sk, ...@@ -754,7 +754,7 @@ int tls_sw_recvmsg(struct sock *sk,
struct sk_buff *skb; struct sk_buff *skb;
ssize_t copied = 0; ssize_t copied = 0;
bool cmsg = false; bool cmsg = false;
int err = 0; int target, err = 0;
long timeo; long timeo;
flags |= nonblock; flags |= nonblock;
...@@ -764,6 +764,7 @@ int tls_sw_recvmsg(struct sock *sk, ...@@ -764,6 +764,7 @@ int tls_sw_recvmsg(struct sock *sk,
lock_sock(sk); lock_sock(sk);
target = sock_rcvlowat(sk, flags & MSG_WAITALL, len);
timeo = sock_rcvtimeo(sk, flags & MSG_DONTWAIT); timeo = sock_rcvtimeo(sk, flags & MSG_DONTWAIT);
do { do {
bool zc = false; bool zc = false;
...@@ -856,6 +857,9 @@ int tls_sw_recvmsg(struct sock *sk, ...@@ -856,6 +857,9 @@ int tls_sw_recvmsg(struct sock *sk,
goto recv_end; goto recv_end;
} }
} }
/* If we have a new message from strparser, continue now. */
if (copied >= target && !ctx->recv_pkt)
break;
} while (len); } while (len);
recv_end: recv_end:
......
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