git: c01bb3300cc9 - main - mbuf: unshare headers again where m_pullup() did it implicitly

From: Olivier Cochard <olivier_at_FreeBSD.org>
Date: Thu, 19 Nov 2026 09:02:29 UTC
The branch main has been updated by olivier:

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

commit c01bb3300cc9097a879ca5139c7d1d492184ed6e
Author:     Olivier Cochard <olivier@FreeBSD.org>
AuthorDate: 2026-11-18 00:23:06 +0000
Commit:     Olivier Cochard <olivier@FreeBSD.org>
CommitDate: 2026-11-19 08:56:02 +0000

    mbuf: unshare headers again where m_pullup() did it implicitly
    
    Since the inline m_pullup() returns a contiguous mbuf untouched, callers using
    "!M_WRITABLE(m) || m_len < len" kept writing into a shared cluster.
    Forwarded multicast fragments left with a corrupted IP header.
    Use m_copyup(), which always allocates a new header mbuf, at those sites.
    
    Reviewed by:    glebius, pouria
    Approved by:    pouria
    Fixes:          671babc79497 ("mbuf: make m_pullup() an inline over most expected case")
    Sponsored by:   Netflix
    Differential Revision:  https://ron-dev.freebsd.org/FreeBSD/src/pulls/109
---
 sys/netgraph/ng_ether.c   | 4 ++--
 sys/netinet/igmp.c        | 4 ++--
 sys/netinet/ip_mroute.c   | 6 +++---
 sys/netinet6/ip6_mroute.c | 6 +++---
 sys/netinet6/ip6_output.c | 2 +-
 5 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/sys/netgraph/ng_ether.c b/sys/netgraph/ng_ether.c
index db56ec504cfe..1ec181402dce 100644
--- a/sys/netgraph/ng_ether.c
+++ b/sys/netgraph/ng_ether.c
@@ -694,8 +694,8 @@ ng_ether_rcv_lower(hook_p hook, item_p item)
 	/* Drop in the MAC address if desired */
 	if (priv->autoSrcAddr) {
 		/* Make the mbuf writable if it's not already */
-		if (!M_WRITABLE(m)
-		    && (m = m_pullup(m, sizeof(struct ether_header))) == NULL)
+		if (!M_WRITABLE(m) &&
+		    (m = m_copyup(m, sizeof(struct ether_header), 0)) == NULL)
 			return (ENOBUFS);
 
 		/* Overwrite source MAC address */
diff --git a/sys/netinet/igmp.c b/sys/netinet/igmp.c
index 5c6c46a4f4f2..1e9c2fb5432f 100644
--- a/sys/netinet/igmp.c
+++ b/sys/netinet/igmp.c
@@ -1509,7 +1509,7 @@ igmp_input(struct mbuf **mp, int *offp, int proto)
 	else
 		minlen += IGMP_MINLEN;
 	if ((!M_WRITABLE(m) || m->m_len < minlen) &&
-	    (m = m_pullup(m, minlen)) == NULL) {
+	    (m = m_copyup(m, minlen, 0)) == NULL) {
 		IGMPSTAT_INC(igps_rcv_tooshort);
 		return (IPPROTO_DONE);
 	}
@@ -1601,7 +1601,7 @@ igmp_input(struct mbuf **mp, int *offp, int proto)
 			   sizeof(struct in_addr) * nsrc;
 			if ((!M_WRITABLE(m) ||
 			     m->m_len < igmpv3len) &&
-			    (m = m_pullup(m, igmpv3len)) == NULL) {
+			    (m = m_copyup(m, igmpv3len, 0)) == NULL) {
 				IGMPSTAT_INC(igps_rcv_tooshort);
 				return (IPPROTO_DONE);
 			}
diff --git a/sys/netinet/ip_mroute.c b/sys/netinet/ip_mroute.c
index 0ab120ae08e0..0e64bab1a531 100644
--- a/sys/netinet/ip_mroute.c
+++ b/sys/netinet/ip_mroute.c
@@ -1460,7 +1460,7 @@ mfc_find_retry:
 
 	mb0 = m_copypacket(m, M_NOWAIT);
 	if (mb0 && (!M_WRITABLE(mb0) || mb0->m_len < hlen))
-		mb0 = m_pullup(mb0, hlen);
+		mb0 = m_copyup(mb0, hlen, 0);
 	if (mb0 == NULL) {
 		free(rte, M_MRTABLE);
 		MRW_WUNLOCK();
@@ -1688,7 +1688,7 @@ ip_mdq(struct mfctable *mfct, struct mbuf *m, struct ifnet *ifp, struct mfc *rt,
 				struct mbuf *mm = m_copym(m, 0, hlen, M_NOWAIT);
 
 				if (mm && (!M_WRITABLE(mm) || mm->m_len < hlen))
-					mm = m_pullup(mm, hlen);
+					mm = m_copyup(mm, hlen, 0);
 				if (mm == NULL)
 					return ENOBUFS;
 
@@ -1832,7 +1832,7 @@ phyint_send(struct ip *ip, struct vif *vifp, struct mbuf *m)
 	 */
 	mb_copy = m_copypacket(m, M_NOWAIT);
 	if (mb_copy && (!M_WRITABLE(mb_copy) || mb_copy->m_len < hlen))
-		mb_copy = m_pullup(mb_copy, hlen);
+		mb_copy = m_copyup(mb_copy, hlen, 0);
 	if (mb_copy == NULL)
 		return;
 
diff --git a/sys/netinet6/ip6_mroute.c b/sys/netinet6/ip6_mroute.c
index e91217ee8b2a..e0f1c1b96d99 100644
--- a/sys/netinet6/ip6_mroute.c
+++ b/sys/netinet6/ip6_mroute.c
@@ -1232,7 +1232,7 @@ X_ip6_mforward(struct ip6_hdr *ip6, struct ifnet *ifp, struct mbuf *m)
 	 * as other references may modify it in the meantime.
 	 */
 	if (mb0 && (!M_WRITABLE(mb0) || mb0->m_len < sizeof(struct ip6_hdr)))
-		mb0 = m_pullup(mb0, sizeof(struct ip6_hdr));
+		mb0 = m_copyup(mb0, sizeof(struct ip6_hdr), 0);
 	if (mb0 == NULL) {
 		free(rte, M_MRTABLE6);
 		MFC6_UNLOCK();
@@ -1511,7 +1511,7 @@ ip6_mdq(struct mf6ctable *mfct, struct mbuf *m, struct ifnet *ifp,
 			if (mm &&
 			    (!M_WRITABLE(mm) ||
 			     mm->m_len < sizeof(struct ip6_hdr)))
-				mm = m_pullup(mm, sizeof(struct ip6_hdr));
+				mm = m_copyup(mm, sizeof(struct ip6_hdr), 0);
 			if (mm == NULL)
 				return (ENOBUFS);
 
@@ -1647,7 +1647,7 @@ phyint_send(struct ip6_hdr *ip6, struct mif6 *mifp, struct mbuf *m)
 	mb_copy = m_copym(m, 0, M_COPYALL, M_NOWAIT);
 	if (mb_copy &&
 	    (!M_WRITABLE(mb_copy) || mb_copy->m_len < sizeof(struct ip6_hdr)))
-		mb_copy = m_pullup(mb_copy, sizeof(struct ip6_hdr));
+		mb_copy = m_copyup(mb_copy, sizeof(struct ip6_hdr), 0);
 	if (mb_copy == NULL) {
 		return;
 	}
diff --git a/sys/netinet6/ip6_output.c b/sys/netinet6/ip6_output.c
index b661f2f45b37..82e82bca6c73 100644
--- a/sys/netinet6/ip6_output.c
+++ b/sys/netinet6/ip6_output.c
@@ -3149,7 +3149,7 @@ ip6_mloopback(struct ifnet *ifp, struct mbuf *m)
 	 */
 	if (!M_WRITABLE(copym) ||
 	    copym->m_len < sizeof(struct ip6_hdr)) {
-		copym = m_pullup(copym, sizeof(struct ip6_hdr));
+		copym = m_copyup(copym, sizeof(struct ip6_hdr), 0);
 		if (copym == NULL)
 			return;
 	}