From 132581aa5da4201ded263433f1d1207d67edfe8b Mon Sep 17 00:00:00 2001 From: Adrian Chadd Date: Sat, 8 Dec 2012 09:48:03 +0000 Subject: [PATCH] Fix a use-after-free bug in the Atheros fast-frames support. Tested: * AR5212 AP, AR5413 STA, iperf TCP STA->AP, destroyed and/or shutdown the STA vap during active iperf TCP traffic. PR: kern/174273 MFC after: 1 week --- sys/net80211/ieee80211_superg.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sys/net80211/ieee80211_superg.c b/sys/net80211/ieee80211_superg.c index a061929d47a4..bb208a72af5d 100644 --- a/sys/net80211/ieee80211_superg.c +++ b/sys/net80211/ieee80211_superg.c @@ -784,7 +784,7 @@ ieee80211_ff_node_cleanup(struct ieee80211_node *ni) struct ieee80211com *ic = ni->ni_ic; struct ieee80211_superg *sg = ic->ic_superg; struct ieee80211_tx_ampdu *tap; - struct mbuf *m, *head; + struct mbuf *m, *next_m, *head; int tid; IEEE80211_LOCK(ic); @@ -803,9 +803,16 @@ ieee80211_ff_node_cleanup(struct ieee80211_node *ni) } IEEE80211_UNLOCK(ic); - for (m = head; m != NULL; m = m->m_nextpkt) { + /* + * Free mbufs, taking care to not dereference the mbuf after + * we free it (hence grabbing m_nextpkt before we free it.) + */ + m = head; + while (m != NULL) { + next_m = m->m_nextpkt; m_freem(m); ieee80211_free_node(ni); + m = next_m; } }