git: 9d2e5039ee18 - stable/15 - ktls: Propagate EPG_FLAG_ANON to mapped mbufs

Mark Johnston <[email protected]>
Newsgroups gmane.os.freebsd.devel.cvs.src
Message-ID <6a74a1d7.46c1e.433f571b__8762.09941213659$1786028675$gmane$org@gitrepo.freebsd.org>
The branch stable/15 has been updated by markj:

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

commit 9d2e5039ee18eb9545b26a8934e650c1f06139cb
Author:     Mark Johnston <[email protected]>
AuthorDate: 2026-07-29 18:45:36 +0000
Commit:     Mark Johnston <[email protected]>
CommitDate: 2026-08-06 13:24:43 +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 90af03e29dfb..c3f59a66b84e 100644
--- a/sys/kern/kern_mbuf.c
+++ b/sys/kern/kern_mbuf.c
@@ -1022,6 +1022,9 @@ _mb_unmapped_to_ext(struct mbuf *m, struct mbuf **mres)
 		m_extadd(m_new, (char *)sf_buf_kva(sf), PAGE_SIZE,
 		    mb_unmapped_free_mext, sf, mref, m->m_flags & 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 5f7d061bfb55..06d1bcabc267 100644
--- a/sys/kern/uipc_ktls.c
+++ b/sys/kern/uipc_ktls.c
@@ -2442,7 +2442,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 8a0a8e31d5b4..cba7702c6ebb 100644
--- a/sys/sys/mbuf.h
+++ b/sys/sys/mbuf.h
@@ -617,6 +617,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.