git: f77e35a8e452 - stable/15 - cxgbe: Various assertions for lengths in KTLS work requests

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Thu, 19 Nov 2026 15:42:35 UTC
The branch stable/15 has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=f77e35a8e45290515591a6b9bb165d571c42b4c7

commit f77e35a8e45290515591a6b9bb165d571c42b4c7
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2026-09-30 19:19:11 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2026-11-19 15:42:19 +0000

    cxgbe: Various assertions for lengths in KTLS work requests
    
    The construction of KTLS work requests is quite fragile, and these
    assertions ensure that the constructed work requests match the length
    fields encoded in some of the WR structures.
    
    Sponsored by:   Chelsio Communications
    
    (cherry picked from commit 17126d54c40a2e3f3e2a81e31a07c299416ddf4a)
---
 sys/dev/cxgbe/crypto/t7_kern_tls.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/sys/dev/cxgbe/crypto/t7_kern_tls.c b/sys/dev/cxgbe/crypto/t7_kern_tls.c
index b1f53c06f79c..8e54adacb368 100644
--- a/sys/dev/cxgbe/crypto/t7_kern_tls.c
+++ b/sys/dev/cxgbe/crypto/t7_kern_tls.c
@@ -1933,6 +1933,8 @@ ktls_write_tls_wr(struct tlspcb *tlsp, struct sge_txq *txq,
 		panic("%s: failed to append sglist", __func__);
 #endif
 	}
+	KASSERT(txq->gl->sg_nseg == nsegs, ("%s: sg_nseg %u != nsegs %u",
+	    __func__, txq->gl->sg_nseg, nsegs));
 	if (last_ghash_frag) {
 		if (sglist_append_phys(txq->gl, zero_buffer_pa,
 		    AES_GMAC_HASH_LEN) != 0) {
@@ -1943,6 +1945,10 @@ ktls_write_tls_wr(struct tlspcb *tlsp, struct sge_txq *txq,
 	}
 	out = write_gl_to_buf(txq->gl, out);
 
+	KASSERT((char *)out - (char *)(wr + 1) == roundup2(txpkt_lens[0], 16),
+	    ("%s: txpkts_len[0] mismatch: %td vs %u", __func__,
+	    (char *)out - (char *)(wr + 1), roundup2(txpkt_lens[0], 16)));
+
 	if (request_ghash) {
 		/* ULP_TXPKT */
 		txpkt = (void *)out;
@@ -1991,8 +1997,18 @@ ktls_write_tls_wr(struct tlspcb *tlsp, struct sge_txq *txq,
 		m_snd_tag_ref(&tlsp->com);
 
 		txq->kern_tls_ghash_requested++;
+
+		KASSERT((char *)out - (char *)txpkt ==
+		    roundup2(txpkt_lens[1], 16),
+		    ("%s: txpkts_len[1] mismatch: %td vs %u", __func__,
+		    (char *)out - (char *)txpkt, roundup2(txpkt_lens[1], 16)));
+
 	}
 
+	KASSERT((char *)out - (char *)wr == roundup2(wr_len, 16),
+	    ("%s: wr_len mismatch: %td vs %u", __func__,
+	    (char *)out - (char *)wr, roundup2(wr_len, 16)));
+
 	if (using_scratch) {
 		out = dst;
 		copy_to_txd(eq, txq->ss, &out, wr_len);