Skip to content

Commit b014a4e

Browse files
qsnkuba-moo
authored andcommitted
tls: wait for async encrypt in case of error during latter iterations of sendmsg
If we hit an error during the main loop of tls_sw_sendmsg_locked (eg failed allocation), we jump to send_end and immediately return. Previous iterations may have queued async encryption requests that are still pending. We should wait for those before returning, as we could otherwise be reading from memory that userspace believes we're not using anymore, which would be a sort of use-after-free. This is similar to what tls_sw_recvmsg already does: failures during the main loop jump to the "wait for async" code, not straight to the unlock/return. Fixes: a42055e ("net/tls: Add support for async encryption of records for performance") Reported-by: Jann Horn <[email protected]> Signed-off-by: Sabrina Dubroca <[email protected]> Link: https://patch.msgid.link/c793efe9673b87f808d84fdefc0f732217030c52.1760432043.git.sd@queasysnail.net Signed-off-by: Jakub Kicinski <[email protected]>
1 parent ce5af41 commit b014a4e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

net/tls/tls_sw.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ static int tls_sw_sendmsg_locked(struct sock *sk, struct msghdr *msg,
10541054
if (ret == -EINPROGRESS)
10551055
num_async++;
10561056
else if (ret != -EAGAIN)
1057-
goto send_end;
1057+
goto end;
10581058
}
10591059
}
10601060

@@ -1226,8 +1226,9 @@ static int tls_sw_sendmsg_locked(struct sock *sk, struct msghdr *msg,
12261226
goto alloc_encrypted;
12271227
}
12281228

1229+
send_end:
12291230
if (!num_async) {
1230-
goto send_end;
1231+
goto end;
12311232
} else if (num_zc || eor) {
12321233
int err;
12331234

@@ -1245,7 +1246,7 @@ static int tls_sw_sendmsg_locked(struct sock *sk, struct msghdr *msg,
12451246
tls_tx_records(sk, msg->msg_flags);
12461247
}
12471248

1248-
send_end:
1249+
end:
12491250
ret = sk_stream_error(sk, msg->msg_flags, ret);
12501251
return copied > 0 ? copied : ret;
12511252
}

0 commit comments

Comments
 (0)