aboutsummaryrefslogtreecommitdiff
path: root/sys/pci/if_mn.c
diff options
context:
space:
mode:
authorBosko Milekic <bmilekic@FreeBSD.org>2000-12-15 21:06:55 +0000
committerBosko Milekic <bmilekic@FreeBSD.org>2000-12-15 21:06:55 +0000
commit38d66a0de39b91049ba6c72a53aca55d1a714543 (patch)
tree99fa2dc6b1e2ba1ebf1272580bb4b59a6a0b89f2 /sys/pci/if_mn.c
parentaea5b8ffe15a2f970d3427e7bf3f77f77cf8003b (diff)
downloadsrc-38d66a0de39b91049ba6c72a53aca55d1a714543.tar.gz
src-38d66a0de39b91049ba6c72a53aca55d1a714543.zip
Make sure to check if MGET(HDR) returned NULL, even when called with M_WAIT.
This fixes the possibility of a NULL pointer dereference in the case where there are no mbufs or mbuf clusters left. Approved by: phk
Notes
Notes: svn path=/head/; revision=70068
Diffstat (limited to 'sys/pci/if_mn.c')
-rw-r--r--sys/pci/if_mn.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/sys/pci/if_mn.c b/sys/pci/if_mn.c
index 04ba311b4a15..43ac4891f517 100644
--- a/sys/pci/if_mn.c
+++ b/sys/pci/if_mn.c
@@ -606,6 +606,8 @@ ngmn_connect(hook_p hook)
/* XXX: we actually send a 1 byte packet */
dp = mn_alloc_desc();
MGETHDR(m, M_WAIT, MT_DATA);
+ if (m == NULL)
+ return ENOBUFS;
m->m_pkthdr.len = 0;
dp->m = m;
dp->flags = 0xc0000000 + (1 << 16);
@@ -619,8 +621,18 @@ ngmn_connect(hook_p hook)
/* Setup a receive chain with 5 + NTS descriptors */
dp = mn_alloc_desc();
+ m = NULL;
MGETHDR(m, M_WAIT, MT_DATA);
+ if (m == NULL) {
+ mn_free_desc(dp);
+ return (ENOBUFS);
+ }
MCLGET(m, M_WAIT);
+ if ((m->m_flags & M_EXT) == 0) {
+ mn_free_desc(dp);
+ m_freem(m);
+ return (ENOBUFS);
+ }
dp->m = m;
dp->data = vtophys(m->m_data);
dp->flags = 0x40000000;
@@ -632,8 +644,19 @@ ngmn_connect(hook_p hook)
for (i = 0; i < (nts + 10); i++) {
dp2 = dp;
dp = mn_alloc_desc();
+ m = NULL;
MGETHDR(m, M_WAIT, MT_DATA);
+ if (m == NULL) {
+ mn_free_desc(dp);
+ m_freem(m);
+ return (ENOBUFS);
+ }
MCLGET(m, M_WAIT);
+ if ((m->m_flags & M_EXT) == 0) {
+ mn_free_desc(dp);
+ m_freem(m);
+ return (ENOBUFS);
+ }
dp->m = m;
dp->data = vtophys(m->m_data);
dp->flags = 0x00000000;
@@ -1063,12 +1086,13 @@ mn_rx_intr(struct softc *sc, u_int32_t vector)
MGETHDR(m, M_DONTWAIT, MT_DATA);
if (m == NULL) {
mn_free_desc(dp);
- return;
+ return; /* ENOBUFS */
}
MCLGET(m, M_DONTWAIT);
if((m->m_flags & M_EXT) == 0) {
mn_free_desc(dp);
- return;
+ m_freem(m);
+ return; /* ENOBUFS */
}
}
dp->m = m;