aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Borkmann <daniel@iogearbox.net>2018-06-14 21:07:46 -0400
committerDavid S. Miller <davem@davemloft.net>2018-06-15 12:14:30 -0400
commit06030dbaf3b6c5801dcdb7fe4fbab3b91c8da84a (patch)
tree8b74374786d0408b81f5f42ed6cacc8f6d7fd3b9
parenta447da7d00410278c90d3576782a43f8b675d7be (diff)
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: c46234ebb4d1 ("tls: RX path for ktls") Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Dave Watson <davejwatson@fb.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/tls/tls_sw.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
index 2945a3bd538c..f127fac88acf 100644
--- a/net/tls/tls_sw.c
+++ b/net/tls/tls_sw.c
@@ -754,7 +754,7 @@ int tls_sw_recvmsg(struct sock *sk,
754 struct sk_buff *skb; 754 struct sk_buff *skb;
755 ssize_t copied = 0; 755 ssize_t copied = 0;
756 bool cmsg = false; 756 bool cmsg = false;
757 int err = 0; 757 int target, err = 0;
758 long timeo; 758 long timeo;
759 759
760 flags |= nonblock; 760 flags |= nonblock;
@@ -764,6 +764,7 @@ int tls_sw_recvmsg(struct sock *sk,
764 764
765 lock_sock(sk); 765 lock_sock(sk);
766 766
767 target = sock_rcvlowat(sk, flags & MSG_WAITALL, len);
767 timeo = sock_rcvtimeo(sk, flags & MSG_DONTWAIT); 768 timeo = sock_rcvtimeo(sk, flags & MSG_DONTWAIT);
768 do { 769 do {
769 bool zc = false; 770 bool zc = false;
@@ -856,6 +857,9 @@ fallback_to_reg_recv:
856 goto recv_end; 857 goto recv_end;
857 } 858 }
858 } 859 }
860 /* If we have a new message from strparser, continue now. */
861 if (copied >= target && !ctx->recv_pkt)
862 break;
859 } while (len); 863 } while (len);
860 864
861recv_end: 865recv_end: