diff options
author | np <np@FreeBSD.org> | 2016-04-01 01:39:44 +0000 |
---|---|---|
committer | np <np@FreeBSD.org> | 2016-04-01 01:39:44 +0000 |
commit | 3c07b218c4c87b0e1dbf8ce585f7fad4d49f2c09 (patch) | |
tree | 04c531edc9702284c235a1dd73d73c725fa2551c /sys/kern | |
parent | 8dd17d694b5acc40fd8afe42eb42629de9db5cae (diff) | |
download | FreeBSD-src-3c07b218c4c87b0e1dbf8ce585f7fad4d49f2c09.zip FreeBSD-src-3c07b218c4c87b0e1dbf8ce585f7fad4d49f2c09.tar.gz |
MFC r297298:
Plug leak in m_unshare.
m_unshare passes on the source mbuf's flags as-is to m_getcl and this
results in a leak if the flags include M_NOFREE. The fix is to clear
the bits not listed in M_COPYALL before calling m_getcl. M_RDONLY
should probably be filtered out too but that's outside the scope of this
fix.
Add assertions in the zone_mbuf and zone_pack ctors to catch similar
bugs.
Update netmap_get_mbuf to not pass M_NOFREE to m_getcl. It's not clear
what the original code was trying to do but it's likely incorrect.
Updated code is no different functionally but it avoids the newly added
assertions.
Sponsored by: Chelsio Communications
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/kern_mbuf.c | 2 | ||||
-rw-r--r-- | sys/kern/uipc_mbuf.c | 4 |
2 files changed, 4 insertions, 2 deletions
diff --git a/sys/kern/kern_mbuf.c b/sys/kern/kern_mbuf.c index c232a37..7f9f666 100644 --- a/sys/kern/kern_mbuf.c +++ b/sys/kern/kern_mbuf.c @@ -429,6 +429,7 @@ mb_ctor_mbuf(void *mem, int size, void *arg, int how) m = (struct mbuf *)mem; flags = args->flags; + MPASS((flags & M_NOFREE) == 0); error = m_init(m, NULL, size, how, type, flags); @@ -626,6 +627,7 @@ mb_ctor_pack(void *mem, int size, void *arg, int how) args = (struct mb_args *)arg; flags = args->flags; type = args->type; + MPASS((flags & M_NOFREE) == 0); #ifdef INVARIANTS trash_ctor(m->m_ext.ext_buf, MCLBYTES, arg, how); diff --git a/sys/kern/uipc_mbuf.c b/sys/kern/uipc_mbuf.c index 01e4c31..df03928 100644 --- a/sys/kern/uipc_mbuf.c +++ b/sys/kern/uipc_mbuf.c @@ -1989,7 +1989,7 @@ m_unshare(struct mbuf *m0, int how) * don't know how to break up the non-contiguous memory when * doing DMA. */ - n = m_getcl(how, m->m_type, m->m_flags); + n = m_getcl(how, m->m_type, m->m_flags & M_COPYFLAGS); if (n == NULL) { m_freem(m0); return (NULL); @@ -2014,7 +2014,7 @@ m_unshare(struct mbuf *m0, int how) break; off += cc; - n = m_getcl(how, m->m_type, m->m_flags); + n = m_getcl(how, m->m_type, m->m_flags & M_COPYFLAGS); if (n == NULL) { m_freem(mfirst); m_freem(m0); |