Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3701054pxb; Mon, 24 Jan 2022 15:46:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJyxyNYZ0u467dstb6xIntzsSxEGHp2dqNSLLYxHfMIxOa2CS6E78bpYsFkuY2bhCGt1vRhv X-Received: by 2002:a17:902:f547:b0:14b:2e12:2618 with SMTP id h7-20020a170902f54700b0014b2e122618mr12354654plf.112.1643067965406; Mon, 24 Jan 2022 15:46:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643067965; cv=none; d=google.com; s=arc-20160816; b=iWxCescc4cSPi2OuQeC6FldNK0hI0gBJ3v39BrYl3I/m7wbb4WR/ZAO/EGZOsEJKNM vHjGzL6BygJ1TqU9tmuKnWmoLMemws2b07lwjqf6KBr1JEEAddai+XyyldRdjnKRMeuN V4q27jQXt1u0zqsFsUN8vreInBXIcABY2f1KG+QvNc7Y2T+4VEepM9lJQbreAlWoDhAg aZdAzIRaB3Dv+Q88ApGUZmm8AcBixlqHVzmayfRBQGfbokr+DZJfiuVTqHnn6m+9EudW GNWXTmWzuupa9aG0Bv4oCcOWw143cMxZ+g33PJSxUhbW1aUDB/Lzc+fmWDBAE60dz+jp 9LJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=J4gT4DGzB3ARhf36OpnKEkPkgl/H7Vdo9OzqMfiWS8U=; b=SBbbjf3EHwpwJ0+qzjI92YKTBr/TKdaXeglx/WUyKDzB+u8RuWVj9JejT8nf8f1X4u RZXsRXRtPg2Ua5cMsM8ViKYmZ/tr9ReTeAnPXkv+EGfXDzg82FUHVtlQfqsJ/k0XNPJ3 bTv4e/7ZWAiKTEA0XJopKLXgd/wQdHQ3WTHY9xCJ1Matp6E1+8pRXRlBnA3TAe/mFWxV +ADMdDkHpLZhzHplqyP/rf5gIY9qFRkKTN/98Ra8GHGG6tlKR9XGF6NfIkYtuLstvlcT 2vR1FXT073afR5Xmfpe7jPPt71W43Gyn7f0tjzwoRHdr8v01kNCIPmnBFF2McFg/3D8X zUTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qkWtSDOn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i4si8497670plb.295.2022.01.24.15.45.52; Mon, 24 Jan 2022 15:46:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qkWtSDOn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2360310AbiAXXg1 (ORCPT + 99 others); Mon, 24 Jan 2022 18:36:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1839879AbiAXWwD (ORCPT ); Mon, 24 Jan 2022 17:52:03 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2951C0EE126; Mon, 24 Jan 2022 13:08:24 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 405BD611C8; Mon, 24 Jan 2022 21:08:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23ED6C340E5; Mon, 24 Jan 2022 21:08:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643058503; bh=JAH7qg2L/G+k79KV4K1U+s1717QvvG9IoCWx99kg8+c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qkWtSDOnGE5Lj1uY3MmlYHfbMFAC2doSsqQGDhgGnxsZEPIX97vukwP0lS1kKkwyi lnzq8UR1lW35sflkVI0goIGsp0gQT5laAW4wK9yC3qjmg2NZQBqUhSRJpeOlcCwb0I 5thGhQpuruVWZijIxDuxOQT14fPPVKF9LcdPz5Wc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lorenzo Bianconi , Felix Fietkau , Sasha Levin Subject: [PATCH 5.16 0311/1039] mt76: fix possible OOB issue in mt76_calculate_default_rate Date: Mon, 24 Jan 2022 19:35:00 +0100 Message-Id: <20220124184135.760432052@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lorenzo Bianconi [ Upstream commit d4f3d1c4d3c2bcce76a96a6562170664b25112f0 ] Cap max offset value to ARRAY_SIZE(mt76_rates) - 1 in mt76_calculate_default_rate routine in order to avoid possible Out Of Bound accesses. Fixes: 33920b2bf0483 ("mt76: add support for setting mcast rate") Signed-off-by: Lorenzo Bianconi Signed-off-by: Felix Fietkau Signed-off-by: Sasha Levin --- drivers/net/wireless/mediatek/mt76/mac80211.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mac80211.c b/drivers/net/wireless/mediatek/mt76/mac80211.c index 62807dc311c19..b0869ff86c49f 100644 --- a/drivers/net/wireless/mediatek/mt76/mac80211.c +++ b/drivers/net/wireless/mediatek/mt76/mac80211.c @@ -1494,7 +1494,6 @@ EXPORT_SYMBOL_GPL(mt76_init_queue); u16 mt76_calculate_default_rate(struct mt76_phy *phy, int rateidx) { int offset = 0; - struct ieee80211_rate *rate; if (phy->chandef.chan->band != NL80211_BAND_2GHZ) offset = 4; @@ -1503,9 +1502,11 @@ u16 mt76_calculate_default_rate(struct mt76_phy *phy, int rateidx) if (rateidx < 0) rateidx = 0; - rate = &mt76_rates[offset + rateidx]; + rateidx += offset; + if (rateidx >= ARRAY_SIZE(mt76_rates)) + rateidx = offset; - return rate->hw_value; + return mt76_rates[rateidx].hw_value; } EXPORT_SYMBOL_GPL(mt76_calculate_default_rate); -- 2.34.1