diff options
author | silby <silby@FreeBSD.org> | 2003-10-19 22:33:41 +0000 |
---|---|---|
committer | silby <silby@FreeBSD.org> | 2003-10-19 22:33:41 +0000 |
commit | 4add8d9302f95e90df2c7b01613648b4f8c2a8a7 (patch) | |
tree | 380a9f5bd024e0fdbc9f53870898d9246166b4c0 /sys | |
parent | 9f420bf43d995bad7e87dd407faafcddbe12d343 (diff) | |
download | FreeBSD-src-4add8d9302f95e90df2c7b01613648b4f8c2a8a7.zip FreeBSD-src-4add8d9302f95e90df2c7b01613648b4f8c2a8a7.tar.gz |
Add a new macro M_ASSERTVALID which ensures that the mbuf in question
is non-free. (More checks can/should be added in the future.)
Use M_ASSERTVALID in BPF_MTAP so that we catch when freed mbufs are
passed in, even if no bpf listeners are active.
Inspired by a bug in if_dc caught by Kenjiro Cho.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/net/bpf.h | 1 | ||||
-rw-r--r-- | sys/sys/mbuf.h | 7 |
2 files changed, 8 insertions, 0 deletions
diff --git a/sys/net/bpf.h b/sys/net/bpf.h index 6d3e800..a5942ae 100644 --- a/sys/net/bpf.h +++ b/sys/net/bpf.h @@ -366,6 +366,7 @@ u_int bpf_filter(const struct bpf_insn *, u_char *, u_int, u_int); bpf_tap((_ifp)->if_bpf, (_pkt), (_pktlen)); \ } while (0) #define BPF_MTAP(_ifp,_m) do { \ + M_ASSERTVALID(_m); \ if ((_ifp)->if_bpf) \ bpf_mtap((_ifp)->if_bpf, (_m)); \ } while (0) diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h index abdd662..6fa1ef7 100644 --- a/sys/sys/mbuf.h +++ b/sys/sys/mbuf.h @@ -340,6 +340,13 @@ struct mbstat { ("%s: no mbuf packet header!", __func__)) /* + * Ensure that the supplied mbuf is a valid, non-free mbuf. + */ +#define M_ASSERTVALID(m) \ + KASSERT((((struct mbuf *)m)->m_flags & M_FREELIST) == 0, \ + ("%s: attempted use of a free mbuf!", __func__)) + +/* * Set the m_data pointer of a newly-allocated mbuf (m_get/MGET) to place * an object of the specified size at the end of the mbuf, longword aligned. */ |