Skip to content

Commit 06030db

Browse files
borkmanndavem330
authored andcommitted
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: c46234e ("tls: RX path for ktls") Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Dave Watson <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a447da7 commit 06030db

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

net/tls/tls_sw.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ int tls_sw_recvmsg(struct sock *sk,
754754
struct sk_buff *skb;
755755
ssize_t copied = 0;
756756
bool cmsg = false;
757-
int err = 0;
757+
int target, err = 0;
758758
long timeo;
759759

760760
flags |= nonblock;
@@ -764,6 +764,7 @@ int tls_sw_recvmsg(struct sock *sk,
764764

765765
lock_sock(sk);
766766

767+
target = sock_rcvlowat(sk, flags & MSG_WAITALL, len);
767768
timeo = sock_rcvtimeo(sk, flags & MSG_DONTWAIT);
768769
do {
769770
bool zc = false;
@@ -856,6 +857,9 @@ int tls_sw_recvmsg(struct sock *sk,
856857
goto recv_end;
857858
}
858859
}
860+
/* If we have a new message from strparser, continue now. */
861+
if (copied >= target && !ctx->recv_pkt)
862+
break;
859863
} while (len);
860864

861865
recv_end:

0 commit comments

Comments
 (0)