Skip to content

Commit 3ac0f3e

Browse files
Dave Watsongregkh
authored andcommitted
net/tls: Don't recursively call push_record during tls_write_space callbacks
[ Upstream commit c212d2c ] 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 <[email protected]> Signed-off-by: Dave Watson <[email protected]> Signed-off-by: David S. Miller <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 78ac65e commit 3ac0f3e

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

include/net/tls.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ struct tls_context {
9898
struct scatterlist *partially_sent_record;
9999
u16 partially_sent_offset;
100100
unsigned long flags;
101+
bool in_tcp_sendpages;
101102

102103
u16 pending_open_record_frags;
103104
int (*push_pending_record)(struct sock *sk, int flags);

net/tls/tls_main.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ int tls_push_sg(struct sock *sk,
8787
size = sg->length - offset;
8888
offset += sg->offset;
8989

90+
ctx->in_tcp_sendpages = true;
9091
while (1) {
9192
if (sg_is_last(sg))
9293
sendpage_flags = flags;
@@ -121,6 +122,8 @@ int tls_push_sg(struct sock *sk,
121122
}
122123

123124
clear_bit(TLS_PENDING_CLOSED_RECORD, &ctx->flags);
125+
ctx->in_tcp_sendpages = false;
126+
ctx->sk_write_space(sk);
124127

125128
return 0;
126129
}
@@ -190,6 +193,10 @@ static void tls_write_space(struct sock *sk)
190193
{
191194
struct tls_context *ctx = tls_get_ctx(sk);
192195

196+
/* We are already sending pages, ignore notification */
197+
if (ctx->in_tcp_sendpages)
198+
return;
199+
193200
if (!sk->sk_write_pending && tls_is_pending_closed_record(ctx)) {
194201
gfp_t sk_allocation = sk->sk_allocation;
195202
int rc;

0 commit comments

Comments
 (0)