From patchwork Tue Jul 28 08:00:13 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roel Kluin X-Patchwork-Id: 37682 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 n6S7vUdn022237 for ; Tue, 28 Jul 2009 07:57:30 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751992AbZG1H51 (ORCPT ); Tue, 28 Jul 2009 03:57:27 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752023AbZG1H51 (ORCPT ); Tue, 28 Jul 2009 03:57:27 -0400 Received: from mail-ew0-f226.google.com ([209.85.219.226]:39012 "EHLO mail-ew0-f226.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751665AbZG1H51 (ORCPT ); Tue, 28 Jul 2009 03:57:27 -0400 Received: by mail-ew0-f226.google.com with SMTP id 26so3767834ewy.37 for ; Tue, 28 Jul 2009 00:57:27 -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:subject:content-type :content-transfer-encoding; bh=YJEWJdQWmHoGDHOOL84FCjdbvqpUpfcBCjAcK3/ygUw=; b=Kc5J4wJq3XbedhJsMTQrsDS2fS/ulJsPvTCr0tFJq7PYpe8JaMh6hDSQN1zHA3hD49 HfXw5l0zZL0t43WEv+IgamcFAU7rCD7efV1SAZsHOgVv6DO4XWPsT5ewxLQliYSNeKA7 z6pvLsOCQA8gy1/8XzuuEx1hDV41EYrq5FK9E= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; b=SsZ+iQu4zn/z40OPzSsLRdbGaCW4YxWDtvHtZm059l0otktDcTrLKg0XtL9+M2LEcB eNlB16CR07FHtfXxRQhIBcQuBXRtnFT3kug0qTwEERREBSESwM4Uce8ZBU01a2amTl3h DM+cYlDO2yL7Eb88cpvWcHomJgaaud6Vs7GiY= Received: by 10.210.43.10 with SMTP id q10mr5879345ebq.23.1248767847533; Tue, 28 Jul 2009 00:57:27 -0700 (PDT) Received: from zoinx.mars (d133062.upc-d.chello.nl [213.46.133.62]) by mx.google.com with ESMTPS id 10sm1988068eyz.51.2009.07.28.00.57.26 (version=SSLv3 cipher=RC4-MD5); Tue, 28 Jul 2009 00:57:27 -0700 (PDT) Message-ID: <4A6EB00D.5010401@gmail.com> Date: Tue, 28 Jul 2009 10:00:13 +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: dcbw@redhat.com, libertas-dev@lists.infradead.org, linux-wireless@vger.kernel.org, Andrew Morton Subject: [PATCH] libertas: Read buffer overflow 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. Since ratesize is at most MAX_RATES, tmp_size can increment at most to MAX_RATES * ARRAY_SIZE(lbs_bg_rates), so that should be the number of elements of tmp[]. Signed-off-by: Roel Kluin --- Please review. "); -- 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..7dfbb0c 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,14 +44,14 @@ 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); + size_t num_card_rates = ARRAY_SIZE(lbs_bg_rates); int ret = 0, i, j; - u8 tmp[30]; + u8 tmp[MAX_RATES * ARRAY_SIZE(lbs_bg_rates)]; 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 < num_card_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]; } @@ -322,7 +323,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 +599,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.