git: 0af1065b3a57 - stable/14 - ktls: Propagate EPG_FLAG_ANON to mapped mbufs

Mark Johnston <[email protected]>
Newsgroups gmane.os.freebsd.devel.cvs.src
Message-ID <6a7353c2.455f3.773d46b7__38523.0004134186$1785943052$gmane$org@gitrepo.freebsd.org>
The branch stable/14 has been updated by markj:

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

commit 0af1065b3a5721a9e5433622dcc8a7adb96ad2ed
Author:     Mark Johnston <[email protected]>
AuthorDate: 2026-07-29 18:45:36 +0000
Commit:     Mark Johnston <[email protected]>
CommitDate: 2026-08-05 15:15:14 +0000

    ktls: Propagate EPG_FLAG_ANON to mapped mbufs
    
    Otherwise ktls_mbuf_crypto_state() will reject mbufs created by
    _mb_unmapped_to_ext(), which arises when transmitting packets through an
    interface that doesn't support unmapped mbufs, and the loopback
    interface in particular.
    
    PR:             296498
    Fixes:          3444414cb463 ("ktls: Don't attempt to modify non-anonymous mbufs on the receive path")
    Reviewed by:    gallatin, jhb
    MFC after:      1 week
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D57557
    
    (cherry picked from commit 815976ee14121bafe8a8ab002459d32f8928f2de)
---
 sys/kern/kern_mbuf.c | 3 +++
 sys/kern/uipc_ktls.c | 3 ++-
 sys/sys/mbuf.h       | 1 +
 3 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/sys/kern/kern_mbuf.c b/sys/kern/kern_mbuf.c
index 69d82086c7a5..16e1d8af56ae 100644
--- a/sys/kern/kern_mbuf.c
+++ b/sys/kern/kern_mbuf.c
@@ -1021,6 +1021,9 @@ _mb_unmapped_to_ext(struct mbuf *m, struct mbuf **mres)
 		ref_inc++;
 		m_extadd(m_new, (char *)sf_buf_kva(sf), PAGE_SIZE,
 		    mb_unmapped_free_mext, sf, mref, M_RDONLY, EXT_SFBUF);
+		m_new->m_ext.ext_flags |=
+		    (m->m_epg_flags & EPG_FLAG_ANON) != 0 ?
+		    EXT_FLAG_SFBUF_ANON : 0;
 		m_new->m_data += segoff;
 		m_new->m_len = seglen;
 
diff --git a/sys/kern/uipc_ktls.c b/sys/kern/uipc_ktls.c
index dc370d033a7a..81914324fe5b 100644
--- a/sys/kern/uipc_ktls.c
+++ b/sys/kern/uipc_ktls.c
@@ -2360,7 +2360,8 @@ ktls_mbuf_crypto_state(struct mbuf *mb, int offset, int len)
 		    (mb->m_epg_flags & EPG_FLAG_ANON) == 0)
 			return (KTLS_MBUF_CRYPTO_ST_SHAREDMBUF);
 		if ((mb->m_flags & M_EXT) != 0 &&
-		    mb->m_ext.ext_type == EXT_SFBUF)
+		    mb->m_ext.ext_type == EXT_SFBUF &&
+		    (mb->m_ext.ext_flags & EXT_FLAG_SFBUF_ANON) == 0)
 			return (KTLS_MBUF_CRYPTO_ST_SHAREDMBUF);
 
 		m_flags_ored |= mb->m_flags;
diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h
index 2ba2836f84ac..23b6c0de3d1a 100644
--- a/sys/sys/mbuf.h
+++ b/sys/sys/mbuf.h
@@ -618,6 +618,7 @@ m_epg_pagelen(const struct mbuf *m, int pidx, int pgoff)
  */
 #define	EXT_FLAG_EMBREF		0x000001	/* embedded ext_count */
 #define	EXT_FLAG_EXTREF		0x000002	/* external ext_cnt, notyet */
+#define	EXT_FLAG_SFBUF_ANON	0x000004	/* sendfile buffer is mutable */
 
 #define	EXT_FLAG_NOFREE		0x000010	/* don't free mbuf to pool, notyet */
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.