Skip to content

Commit b6fe4c2

Browse files
qsnkuba-moo
authored andcommitted
tls: always set record_type in tls_process_cmsg
When userspace wants to send a non-DATA record (via the TLS_SET_RECORD_TYPE cmsg), we need to send any pending data from a previous MSG_MORE send() as a separate DATA record. If that DATA record is encrypted asynchronously, tls_handle_open_record will return -EINPROGRESS. This is currently treated as an error by tls_process_cmsg, and it will skip setting record_type to the correct value, but the caller (tls_sw_sendmsg_locked) handles that return value correctly and proceeds with sending the new message with an incorrect record_type (DATA instead of whatever was requested in the cmsg). Always set record_type before handling the open record. If tls_handle_open_record returns an error, record_type will be ignored. If it succeeds, whether with synchronous crypto (returning 0) or asynchronous (returning -EINPROGRESS), the caller will proceed correctly. 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/0457252e578a10a94e40c72ba6288b3a64f31662.1760432043.git.sd@queasysnail.net Signed-off-by: Jakub Kicinski <[email protected]>
1 parent b014a4e commit b6fe4c2

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

net/tls/tls_main.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,9 @@ int tls_process_cmsg(struct sock *sk, struct msghdr *msg,
255255
if (msg->msg_flags & MSG_MORE)
256256
return -EINVAL;
257257

258-
rc = tls_handle_open_record(sk, msg->msg_flags);
259-
if (rc)
260-
return rc;
261-
262258
*record_type = *(unsigned char *)CMSG_DATA(cmsg);
263-
rc = 0;
259+
260+
rc = tls_handle_open_record(sk, msg->msg_flags);
264261
break;
265262
default:
266263
return -EINVAL;

0 commit comments

Comments
 (0)