aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Watson <davejwatson@fb.com>2018-05-01 16:05:39 -0400
committerDavid S. Miller <davem@davemloft.net>2018-05-01 18:57:52 -0400
commitc212d2c7fc4736d49be102fb7a1a545cdc2f1fea (patch)
treef4ebbd4af00a32f8f96ea2d92498c533d33da615
parentedd7ceb78296fb1574958991b6655c3c2cedf124 (diff)
net/tls: Don't recursively call push_record during tls_write_space callbacks
It is reported that in some cases, write_space may be called in do_tcp_sendpages, such that we recursively invoke do_tcp_sendpages again: [ 660.468802] ? do_tcp_sendpages+0x8d/0x580 [ 660.468826] ? tls_push_sg+0x74/0x130 [tls] [ 660.468852] ? tls_push_record+0x24a/0x390 [tls] [ 660.468880] ? tls_write_space+0x6a/0x80 [tls] ... tls_push_sg already does a loop over all sending sg's, so ignore any tls_write_space notifications until we are done sending. We then have to call the previous write_space to wake up poll() waiters after we are done with the send loop. Reported-by: Andre Tomt <andre@tomt.net> Signed-off-by: Dave Watson <davejwatson@fb.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/tls.h1
-rw-r--r--net/tls/tls_main.c7
2 files changed, 8 insertions, 0 deletions
diff --git a/include/net/tls.h b/include/net/tls.h
index 3da8e13a6d96..b400d0bb7448 100644
--- a/include/net/tls.h
+++ b/include/net/tls.h
@@ -148,6 +148,7 @@ struct tls_context {
148 struct scatterlist *partially_sent_record; 148 struct scatterlist *partially_sent_record;
149 u16 partially_sent_offset; 149 u16 partially_sent_offset;
150 unsigned long flags; 150 unsigned long flags;
151 bool in_tcp_sendpages;
151 152
152 u16 pending_open_record_frags; 153 u16 pending_open_record_frags;
153 int (*push_pending_record)(struct sock *sk, int flags); 154 int (*push_pending_record)(struct sock *sk, int flags);
diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c
index 0d379970960e..cc03e00785c7 100644
--- a/net/tls/tls_main.c
+++ b/net/tls/tls_main.c
@@ -114,6 +114,7 @@ int tls_push_sg(struct sock *sk,
114 size = sg->length - offset; 114 size = sg->length - offset;
115 offset += sg->offset; 115 offset += sg->offset;
116 116
117 ctx->in_tcp_sendpages = true;
117 while (1) { 118 while (1) {
118 if (sg_is_last(sg)) 119 if (sg_is_last(sg))
119 sendpage_flags = flags; 120 sendpage_flags = flags;
@@ -148,6 +149,8 @@ retry:
148 } 149 }
149 150
150 clear_bit(TLS_PENDING_CLOSED_RECORD, &ctx->flags); 151 clear_bit(TLS_PENDING_CLOSED_RECORD, &ctx->flags);
152 ctx->in_tcp_sendpages = false;
153 ctx->sk_write_space(sk);
151 154
152 return 0; 155 return 0;
153} 156}
@@ -217,6 +220,10 @@ static void tls_write_space(struct sock *sk)
217{ 220{
218 struct tls_context *ctx = tls_get_ctx(sk); 221 struct tls_context *ctx = tls_get_ctx(sk);
219 222
223 /* We are already sending pages, ignore notification */
224 if (ctx->in_tcp_sendpages)
225 return;
226
220 if (!sk->sk_write_pending && tls_is_pending_closed_record(ctx)) { 227 if (!sk->sk_write_pending && tls_is_pending_closed_record(ctx)) {
221 gfp_t sk_allocation = sk->sk_allocation; 228 gfp_t sk_allocation = sk->sk_allocation;
222 int rc; 229 int rc;