Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2632985pxa; Mon, 17 Aug 2020 15:00:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy13vlpSdAXu+hZLvTkfmzSwK708bW2nGgDiW65O4L9i8SHKsMQoCj80rF4jIY5KGqWz8Ey X-Received: by 2002:a17:906:ad99:: with SMTP id la25mr16404083ejb.63.1597701645117; Mon, 17 Aug 2020 15:00:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597701645; cv=none; d=google.com; s=arc-20160816; b=IwZBZHymsHlsSus3BQvro0Nv7OHXmECe7wO9Jk6svd9qaTksgzaFXrbfXAik/zIUgP iu+o4B44z8HddlG05AyNIfQ5YJ18r0zyJe+DKAim+k6qzGG8g3zXaUQKAatKg3KwBFed 4BmrdYZhGzZRy9ZFsK4gX7S2FfPJgtfPBXQ6c3Q98AlajXOtm9jGjfrzqkpUGQj5LdSz 09nDXkAVwI8XWVzMstNPxEjz9K2iotTvLra2OVxS5M30jZXEOKDBDA7XllidjUEv3fCk wihCBk5u2vUE0FtIGGZZZRc9ZbZP/Y3Tr29KMw3n46bcr6WXxi01CzACtKCFNb/2tuib UkAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ywKu0So6rA27tUGW0Xlwa0v98iY1ScRmxBOqMozm1uo=; b=nYY2HYyvkoOUhbQwHhZ4Y0dTtt2Wo3Beca7lGNrEn3zVX3zk3Ft+QT54H6iLyUs4BB 9Q0K6TajpVun7UOiDotCwtpLV0Bi97I4VDYZ8cA+09BZhKmwvsbXeoh1nbvHhcGK9zcH YMk11JnoX6O4bKN5nBcab029fL1sakc7OJ+7yjDKXPkHDnH3+UXxmxItOnWv0O2aLNLs Z4IZ04fxp55RcdS/64tiCtuqOE8J3B1/j+pXQQROCh3N36CIJlWUoy44XVJHMdxVh0bi nGML4ITS/VLaP6p7JCLNS0s79yukfMQ3m2iEuef8WnZsIjimcMjTHSFoLGW6Qnb0/iJG YzvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mpFDB9a0; 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=fail (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 v6si10065973ede.29.2020.08.17.15.00.21; Mon, 17 Aug 2020 15:00:45 -0700 (PDT) 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=@kernel.org header.s=default header.b=mpFDB9a0; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730515AbgHQPgr (ORCPT + 99 others); Mon, 17 Aug 2020 11:36:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:53520 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730241AbgHQPay (ORCPT ); Mon, 17 Aug 2020 11:30:54 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6CD3423B41; Mon, 17 Aug 2020 15:30:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597678254; bh=FxuRQYNDNmFiRNu306TerMqt9Xc35aX8v98qTFSR68s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mpFDB9a0oj60uqWgeP84Du+3Leg2tBntm8Zke5FKWz/Vz3+2t8GhAE7+PZfG0W/ZB IIBSk7RwD+eGd7yseorXOH5L3zyDIxwp6zYKQ/q/gK4yFLiopEhdopl+m4Ew07vOh0 mzAWt/OXhzHtBlPv0XJWuLI3fbGs+w3z53ySW9MM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Felix Fietkau , Sasha Levin Subject: [PATCH 5.8 270/464] mt76: mt7915: potential array overflow in mt7915_mcu_tx_rate_report() Date: Mon, 17 Aug 2020 17:13:43 +0200 Message-Id: <20200817143846.713668196@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143833.737102804@linuxfoundation.org> References: <20200817143833.737102804@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dan Carpenter [ Upstream commit eb744e5df86cf7e377d0acc4e686101b0fd9663a ] Smatch complains that "wcidx" value comes from the network and thus cannot be trusted. In this case, it actually seems to come from the firmware. If your wireless firmware is malicious then probably no amount of carefulness can protect you. On the other hand, these days we still try to check the firmware as much as possible. Verifying that the index is within bounds will silence a static checker warning. And it's harmless and a good exercise in kernel hardening. So I suggest that we do add a bounds check. Fixes: e57b7901469f ("mt76: add mac80211 driver for MT7915 PCIe-based chipsets") Signed-off-by: Dan Carpenter Signed-off-by: Felix Fietkau Signed-off-by: Sasha Levin --- .../net/wireless/mediatek/mt76/mt7915/mcu.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c index c8c12c740c1a0..8fb8255650a7e 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c @@ -505,15 +505,22 @@ static void mt7915_mcu_tx_rate_report(struct mt7915_dev *dev, struct sk_buff *skb) { struct mt7915_mcu_ra_info *ra = (struct mt7915_mcu_ra_info *)skb->data; - u16 wcidx = le16_to_cpu(ra->wlan_idx); - struct mt76_wcid *wcid = rcu_dereference(dev->mt76.wcid[wcidx]); - struct mt7915_sta *msta = container_of(wcid, struct mt7915_sta, wcid); - struct mt7915_sta_stats *stats = &msta->stats; - struct mt76_phy *mphy = &dev->mphy; struct rate_info rate = {}, prob_rate = {}; + u16 probe = le16_to_cpu(ra->prob_up_rate); u16 attempts = le16_to_cpu(ra->attempts); u16 curr = le16_to_cpu(ra->curr_rate); - u16 probe = le16_to_cpu(ra->prob_up_rate); + u16 wcidx = le16_to_cpu(ra->wlan_idx); + struct mt76_phy *mphy = &dev->mphy; + struct mt7915_sta_stats *stats; + struct mt7915_sta *msta; + struct mt76_wcid *wcid; + + if (wcidx >= MT76_N_WCIDS) + return; + + wcid = rcu_dereference(dev->mt76.wcid[wcidx]); + msta = container_of(wcid, struct mt7915_sta, wcid); + stats = &msta->stats; if (msta->wcid.ext_phy && dev->mt76.phy2) mphy = dev->mt76.phy2; -- 2.25.1