From owner-svn-src-all@freebsd.org Sat May 28 18:49:18 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8C7D1B4ED92; Sat, 28 May 2016 18:49:18 +0000 (UTC) (envelope-from avos@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 43C9F1DA1; Sat, 28 May 2016 18:49:18 +0000 (UTC) (envelope-from avos@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u4SInHvu042430; Sat, 28 May 2016 18:49:17 GMT (envelope-from avos@FreeBSD.org) Received: (from avos@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4SInHqo042429; Sat, 28 May 2016 18:49:17 GMT (envelope-from avos@FreeBSD.org) Message-Id: <201605281849.u4SInHqo042429@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: avos set sender to avos@FreeBSD.org using -f From: Andriy Voskoboinyk Date: Sat, 28 May 2016 18:49:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r300910 - head/sys/net80211 X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 May 2016 18:49:18 -0000 Author: avos Date: Sat May 28 18:49:17 2016 New Revision: 300910 URL: https://svnweb.freebsd.org/changeset/base/300910 Log: net80211: fix use-after-free in frame defragmentation procedure. - Assign frame sequence/fragment number before frame concatenation; otherwise, frame header pointer (wh) will be invalid. - Move this code block upper and eliminate duplicate 'lwh = mtod()' assignment. Tested with wpi(4) (transmitter) (STA mode) and urtwn(4) (receiver) (HOSTAP mode). Modified: head/sys/net80211/ieee80211_input.c Modified: head/sys/net80211/ieee80211_input.c ============================================================================== --- head/sys/net80211/ieee80211_input.c Sat May 28 18:47:25 2016 (r300909) +++ head/sys/net80211/ieee80211_input.c Sat May 28 18:49:17 2016 (r300910) @@ -227,9 +227,16 @@ ieee80211_defrag(struct ieee80211_node * lwh = mtod(mfrag, struct ieee80211_frame *); last_rxseq = le16toh(*(uint16_t *)lwh->i_seq); /* NB: check seq # and frag together */ - if (rxseq != last_rxseq+1 || - !IEEE80211_ADDR_EQ(wh->i_addr1, lwh->i_addr1) || - !IEEE80211_ADDR_EQ(wh->i_addr2, lwh->i_addr2)) { + if (rxseq == last_rxseq+1 && + IEEE80211_ADDR_EQ(wh->i_addr1, lwh->i_addr1) && + IEEE80211_ADDR_EQ(wh->i_addr2, lwh->i_addr2)) { + /* XXX clear MORE_FRAG bit? */ + /* track last seqnum and fragno */ + *(uint16_t *) lwh->i_seq = *(uint16_t *) wh->i_seq; + + m_adj(m, hdrspace); /* strip header */ + m_catpkt(mfrag, m); /* concatenate */ + } else { /* * Unrelated fragment or no space for it, * clear current fragments. @@ -247,12 +254,6 @@ ieee80211_defrag(struct ieee80211_node * return NULL; } mfrag = m; - } else { /* concatenate */ - m_adj(m, hdrspace); /* strip header */ - m_catpkt(mfrag, m); - /* track last seqnum and fragno */ - lwh = mtod(mfrag, struct ieee80211_frame *); - *(uint16_t *) lwh->i_seq = *(uint16_t *) wh->i_seq; } if (more_frag) { /* more to come, save */ ni->ni_rxfragstamp = ticks;