]> git.hungrycats.org Git - linux/commitdiff
SUNRPC: Reject a TLS alert record that is not two octets
authorChuck Lever <cel@kernel.org>
Sat, 8 Aug 2026 15:40:10 +0000 (11:40 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 6 Nov 2026 17:06:08 +0000 (12:06 -0500)
commit d16bebe45272ced4f962d27b9efd8b32a3876bd9 upstream.

tls_alert_recv() reads two octets from the kvec it is handed and does
not check the length (net/handshake/alert.c). svc_tcp_sock_recv_cmsg()
calls it for any positive receive, and the alert[] buffer it supplies
carries no initializer. A one-octet alert body leaves the description
read from uninitialized stack and reported through
trace_tls_alert_recv().

The peer controls that length. Neither tls_rx_msg_size() nor
tls_rx_one_record() enforces the two-octet Alert payload. A TLS 1.3
record carrying only the inner content-type octet decrypts to a
zero-length payload. RFC 8446 Section 5.1 requires a record with an
Alert type to carry exactly one message, so any other length is
malformed.

Require exactly two octets before parsing and return -EBADMSG
otherwise. That closes the transport rather than acting on a partly
uninitialized alert. Gate the path on a control message rather than a
positive count so that a zero-length record reaches the check.

Fixes: bee47cb026e7 ("sunrpc: fix handling of server side tls alerts")
Cc: stable@vger.kernel.org
Link: https://patch.msgid.link/20260808-svcsock-cmsg-fixes-v3-2-62d9a631c880@kernel.org
Signed-off-by: Chuck Lever <cel@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/sunrpc/svcsock.c

index ceb4d504409f46e63e8e5cb44caa500a6399d631..51031450062f242bec7ba31318236365d526841d 100644 (file)
@@ -289,13 +289,23 @@ svc_tcp_sock_recv_cmsg(struct socket *sock, unsigned int *msg_flags)
        iov_iter_kvec(&msg.msg_iter, ITER_DEST, &alert_kvec, 1,
                      alert_kvec.iov_len);
        ret = sock_recvmsg(sock, &msg, MSG_DONTWAIT);
-       if (ret > 0) {
+       /* put_cmsg() shrinks msg_controllen, so a short one means
+        * kTLS filled in u.cmsg.
+        */
+       if (ret >= 0 && msg.msg_controllen < sizeof(u)) {
                /* Returning the count would credit the RPC stream with
                 * octets that never reached the caller's buffer.
                 */
                if (tls_get_record_type(sock->sk, &u.cmsg) !=
                    TLS_RECORD_TYPE_ALERT)
                        return -EAGAIN;
+               /* An Alert record carries exactly one two-octet message
+                * (RFC 8446 Section 5.1). alert_kvec caps the receive at two,
+                * so a longer record produces the same count. MSG_EOR appears
+                * only once kTLS has drained the whole record.
+                */
+               if (ret != sizeof(alert) || !(msg.msg_flags & MSG_EOR))
+                       return -EBADMSG;
                iov_iter_revert(&msg.msg_iter, ret);
                ret = svc_tcp_sock_process_cmsg(sock, &msg, &u.cmsg, -EAGAIN);
        }