Module Name: src Committed By: knakahara Date: Wed Apr 20 08:50:44 UTC 2016
Modified Files: src/sys/kern: uipc_mbuf.c src/sys/sys: mbuf.h Log Message: Add init function for mbuf. some functions use mbuf as stack variable instead of allocating by m_get(). They should use this function(s) to prevent access to uninitialized fields. Currently, the mbuf stack allocating functions are the following. + sys/dev/ic/bwi.c - bwi_rxeof() - bwi_encap() + sys/dev/ic/dp8390.c - dp8390_ipkdb_send() + sys/dev/pci/if_txp.c - txp_download_fw_section() + sys/dev/ppbus/if_plip.c - lptap() + sys/net/bpf.c - _pf_mtap2() - _pf_mtap_af() - _pf_mtap_sl_out() + sys/netisdn/i4b_ipr.c - ipr_rx_data_rdy() - ipr_tx_queue_empty() Reviewed by kre@n.o and christos@n.o, thanks. To generate a diff of this commit: cvs rdiff -u -r1.163 -r1.164 src/sys/kern/uipc_mbuf.c cvs rdiff -u -r1.159 -r1.160 src/sys/sys/mbuf.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/uipc_mbuf.c diff -u src/sys/kern/uipc_mbuf.c:1.163 src/sys/kern/uipc_mbuf.c:1.164 --- src/sys/kern/uipc_mbuf.c:1.163 Mon Aug 24 22:21:26 2015 +++ src/sys/kern/uipc_mbuf.c Wed Apr 20 08:50:43 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_mbuf.c,v 1.163 2015/08/24 22:21:26 pooka Exp $ */ +/* $NetBSD: uipc_mbuf.c,v 1.164 2016/04/20 08:50:43 knakahara Exp $ */ /*- * Copyright (c) 1999, 2001 The NetBSD Foundation, Inc. @@ -62,7 +62,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.163 2015/08/24 22:21:26 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.164 2016/04/20 08:50:43 knakahara Exp $"); #ifdef _KERNEL_OPT #include "opt_mbuftrace.h" @@ -583,14 +583,8 @@ m_get(int nowait, int type) return NULL; mbstat_type_add(type, 1); - mowner_init(m, type); - m->m_ext_ref = m; - m->m_type = type; - m->m_len = 0; - m->m_next = NULL; - m->m_nextpkt = NULL; - m->m_data = m->m_dat; - m->m_flags = 0; + + m_hdr_init(m, type, NULL, m->m_dat, 0); return m; } @@ -604,13 +598,7 @@ m_gethdr(int nowait, int type) if (m == NULL) return NULL; - m->m_data = m->m_pktdat; - m->m_flags = M_PKTHDR; - m->m_pkthdr.rcvif = NULL; - m->m_pkthdr.len = 0; - m->m_pkthdr.csum_flags = 0; - m->m_pkthdr.csum_data = 0; - SLIST_INIT(&m->m_pkthdr.tags); + m_pkthdr_init(m); return m; } Index: src/sys/sys/mbuf.h diff -u src/sys/sys/mbuf.h:1.159 src/sys/sys/mbuf.h:1.160 --- src/sys/sys/mbuf.h:1.159 Tue Oct 13 21:28:34 2015 +++ src/sys/sys/mbuf.h Wed Apr 20 08:50:43 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: mbuf.h,v 1.159 2015/10/13 21:28:34 rjs Exp $ */ +/* $NetBSD: mbuf.h,v 1.160 2016/04/20 08:50:43 knakahara Exp $ */ /*- * Copyright (c) 1996, 1997, 1999, 2001, 2007 The NetBSD Foundation, Inc. @@ -934,6 +934,38 @@ m_length(const struct mbuf *m) return pktlen; } +static __inline void +m_hdr_init(struct mbuf *m, short type, struct mbuf *next, char *data, int len) +{ + + KASSERT(m != NULL); + + mowner_init(m, type); + m->m_ext_ref = m; /* default */ + m->m_type = type; + m->m_len = len; + m->m_next = next; + m->m_nextpkt = NULL; /* default */ + m->m_data = data; + m->m_flags = 0; /* default */ +} + +static __inline void +m_pkthdr_init(struct mbuf *m) +{ + + KASSERT(m != NULL); + + m->m_data = m->m_pktdat; + m->m_flags = M_PKTHDR; + + m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.len = 0; + m->m_pkthdr.csum_flags = 0; + m->m_pkthdr.csum_data = 0; + SLIST_INIT(&m->m_pkthdr.tags); +} + void m_print(const struct mbuf *, const char *, void (*)(const char *, ...) __printflike(1, 2));