From patchwork Tue Jul 28 10:05:00 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roel Kluin X-Patchwork-Id: 37689 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n6SA2aPI006798 for ; Tue, 28 Jul 2009 10:02:36 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751931AbZG1KCR (ORCPT ); Tue, 28 Jul 2009 06:02:17 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751890AbZG1KCR (ORCPT ); Tue, 28 Jul 2009 06:02:17 -0400 Received: from ey-out-2122.google.com ([74.125.78.27]:13945 "EHLO ey-out-2122.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751106AbZG1KCQ (ORCPT ); Tue, 28 Jul 2009 06:02:16 -0400 Received: by ey-out-2122.google.com with SMTP id 9so980925eyd.37 for ; Tue, 28 Jul 2009 03:02:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:cc:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=TExTl/Nu86m9s6rvIgIrP97+DVEYQsBjLDrt6j6Bg1o=; b=rxw1xzGGZKqpYaKZW1+BRXW08iWuMpVy5ZHoLhTg/mynQR1BajE94UfDflmu45MtHk cqCRSC9rSCLftvyWfWQbLlCrwQARsUZCieyqtkbuFuXSBHDg/s0m4f1nzBnNXX1ST3bv rsSR6WRvLYF5nkAsUWjg7rJXkP7Jt4tnFzuwE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; b=qCsd+dQRQOTU8wny+l4f6YP9dwDtsLay+Ogr0Xbwcf/3u2KO0iYV0zTteujOuH3Nvz SPpkjcj2Mn19jwvN0pNR7rJiOLz0LrpC9V5aABFik3l1etCid+BTlXbe1g9Xq12Dwyxv 2TVi84g2SGKb6LZIF1AKncD0cEBL/X2Iq4U6k= Received: by 10.210.36.10 with SMTP id j10mr9630555ebj.21.1248775335116; Tue, 28 Jul 2009 03:02:15 -0700 (PDT) Received: from zoinx.mars (d133062.upc-d.chello.nl [213.46.133.62]) by mx.google.com with ESMTPS id 7sm2123767eyb.32.2009.07.28.03.02.12 (version=SSLv3 cipher=RC4-MD5); Tue, 28 Jul 2009 03:02:13 -0700 (PDT) Message-ID: <4A6ECD4C.2040101@gmail.com> Date: Tue, 28 Jul 2009 12:05:00 +0200 From: Roel Kluin User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1b3pre) Gecko/20090513 Fedora/3.0-2.3.beta2.fc11 Thunderbird/3.0b2 MIME-Version: 1.0 To: Holger Schurig CC: dcbw@redhat.com, libertas-dev@lists.infradead.org, linux-wireless@vger.kernel.org, Andrew Morton Subject: Re: [PATCH] libertas: Read buffer overflow References: <4A6EB00D.5010401@gmail.com> <200907281019.56855.hs4233@mail.mn-solutions.de> In-Reply-To: <200907281019.56855.hs4233@mail.mn-solutions.de> Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Several arrays were read before checking whether the index was within bounds. ARRAY_SIZE() should be used to determine the size of arrays. rates->rates has an arraysize of 1, so calling get_common_rates() with a rates_size of MAX_RATES (14) was causing reads out of bounds. tmp_size can increment at most to (ARRAY_SIZE(lbs_bg_rates) - 1) * (*rates_size - 1), so that should be the number of elements of tmp[]. A goto can be eliminated: ret was already set upon its declaration. Signed-off-by: Roel Kluin --- Op 28-07-09 10:19, Holger Schurig schreef: >> - size_t num_card_rates = sizeof(lbs_bg_rates); >> + size_t num_card_rates = ARRAY_SIZE(lbs_bg_rates); > > Hmm, not sure about this. First I don't know if we need a > variable for this at all. Can't you simply use ARRAY_SIZE() > whenever it's needed? Of course. Please note the additional changes. -- To unsubscribe from this list: send the line "unsubscribe linux-wireless" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/net/wireless/libertas/assoc.c b/drivers/net/wireless/libertas/assoc.c index b9b3741..d699737 100644 --- a/drivers/net/wireless/libertas/assoc.c +++ b/drivers/net/wireless/libertas/assoc.c @@ -1,6 +1,7 @@ /* Copyright (C) 2006, Red Hat, Inc. */ #include +#include #include #include #include @@ -43,21 +44,21 @@ static int get_common_rates(struct lbs_private *priv, u16 *rates_size) { u8 *card_rates = lbs_bg_rates; - size_t num_card_rates = sizeof(lbs_bg_rates); int ret = 0, i, j; - u8 tmp[30]; + u8 tmp[(ARRAY_SIZE(lbs_bg_rates) - 1) * (*rates_size - 1)]; size_t tmp_size = 0; /* For each rate in card_rates that exists in rate1, copy to tmp */ - for (i = 0; card_rates[i] && (i < num_card_rates); i++) { - for (j = 0; rates[j] && (j < *rates_size); j++) { + for (i = 0; i < ARRAY_SIZE(lbs_bg_rates) && card_rates[i]; i++) { + for (j = 0; j < *rates_size && rates[j]; j++) { if (rates[j] == card_rates[i]) tmp[tmp_size++] = card_rates[i]; } } lbs_deb_hex(LBS_DEB_JOIN, "AP rates ", rates, *rates_size); - lbs_deb_hex(LBS_DEB_JOIN, "card rates ", card_rates, num_card_rates); + lbs_deb_hex(LBS_DEB_JOIN, "card rates ", card_rates, + ARRAY_SIZE(lbs_bg_rates)); lbs_deb_hex(LBS_DEB_JOIN, "common rates", tmp, tmp_size); lbs_deb_join("TX data rate 0x%02x\n", priv->cur_rate); @@ -69,10 +70,7 @@ static int get_common_rates(struct lbs_private *priv, lbs_pr_alert("Previously set fixed data rate %#x isn't " "compatible with the network.\n", priv->cur_rate); ret = -1; - goto done; } - ret = 0; - done: memset(rates, 0, *rates_size); *rates_size = min_t(int, tmp_size, *rates_size); @@ -322,7 +320,7 @@ static int lbs_associate(struct lbs_private *priv, rates = (struct mrvl_ie_rates_param_set *) pos; rates->header.type = cpu_to_le16(TLV_TYPE_RATES); memcpy(&rates->rates, &bss->rates, MAX_RATES); - tmplen = MAX_RATES; + tmplen = min_t(u16, ARRAY_SIZE(rates->rates), MAX_RATES); if (get_common_rates(priv, rates->rates, &tmplen)) { ret = -1; goto done; @@ -598,7 +596,7 @@ static int lbs_adhoc_join(struct lbs_private *priv, /* Copy Data rates from the rates recorded in scan response */ memset(cmd.bss.rates, 0, sizeof(cmd.bss.rates)); - ratesize = min_t(u16, sizeof(cmd.bss.rates), MAX_RATES); + ratesize = min_t(u16, ARRAY_SIZE(cmd.bss.rates), MAX_RATES); memcpy(cmd.bss.rates, bss->rates, ratesize); if (get_common_rates(priv, cmd.bss.rates, &ratesize)) { lbs_deb_join("ADHOC_JOIN: get_common_rates returned error.\n");