From owner-p4-projects@FreeBSD.ORG Wed Aug 27 15:38:05 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 03CD5106568B; Wed, 27 Aug 2008 15:38:05 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 88E911065675 for ; Wed, 27 Aug 2008 15:38:04 +0000 (UTC) (envelope-from sam@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 7F5668FC32 for ; Wed, 27 Aug 2008 15:38:04 +0000 (UTC) (envelope-from sam@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.2/8.14.2) with ESMTP id m7RFc4xW001163 for ; Wed, 27 Aug 2008 15:38:04 GMT (envelope-from sam@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.2/8.14.1/Submit) id m7RFc4ks001161 for perforce@freebsd.org; Wed, 27 Aug 2008 15:38:04 GMT (envelope-from sam@freebsd.org) Date: Wed, 27 Aug 2008 15:38:04 GMT Message-Id: <200808271538.m7RFc4ks001161@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to sam@freebsd.org using -f From: Sam Leffler To: Perforce Change Reviews Cc: Subject: PERFORCE change 148622 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Aug 2008 15:38:05 -0000 http://perforce.freebsd.org/chv.cgi?CH=148622 Change 148622 by sam@sam_ebb on 2008/08/27 15:37:44 Fix mic calculation when final data is entirely in a trailing mbuf; it's unclear if this can happen on freebsd but does appear on netbsd. Identified by Matthias Drochner who came up with an initial change that we then revised together. Reviewed by: thompsa, sephe, avatar Affected files ... .. //depot/projects/vap/sys/net80211/ieee80211_crypto_tkip.c#15 edit Differences ... ==== //depot/projects/vap/sys/net80211/ieee80211_crypto_tkip.c#15 (text+ko) ==== @@ -910,7 +910,17 @@ data += sizeof(uint32_t), space -= sizeof(uint32_t); data_len -= sizeof(uint32_t); } - if (data_len < sizeof(uint32_t)) + /* + * NB: when space is zero we make one more trip around + * the loop to advance to the next mbuf where there is + * data. This handles the case where there are 4*n + * bytes in an mbuf followed by <4 bytes in a later mbuf. + * By making an extra trip we'll drop out of the loop + * with m pointing at the mbuf with 3 bytes and space + * set as required by the remainder handling below. + */ + if (data_len == 0 || + (data_len < sizeof(uint32_t) && space != 0)) break; m = m->m_next; if (m == NULL) { @@ -957,6 +967,14 @@ space = m->m_len; } } + /* + * Catch degenerate cases like mbuf[4*n+1 bytes] followed by + * mbuf[2 bytes]. I don't believe these should happen; if they + * do then we'll need more involved logic. + */ + KASSERT(data_len <= space, + ("not enough data, data_len %u space %u\n", data_len, space)); + /* Last block and padding (0x5a, 4..7 x 0) */ switch (data_len) { case 0: