Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1226900rwi; Wed, 19 Oct 2022 08:06:20 -0700 (PDT) X-Google-Smtp-Source: AMsMyM70ITtegpVmWoRlYnjt/aq0YjgAsB7LSs4yvpupaD679RnYUkSGd92mC2Wv+Lih6+9mwlA3 X-Received: by 2002:a05:6402:2712:b0:45d:de37:f828 with SMTP id y18-20020a056402271200b0045dde37f828mr7416204edd.317.1666191978999; Wed, 19 Oct 2022 08:06:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666191978; cv=none; d=google.com; s=arc-20160816; b=fSWh8b11MxapoHAlavU42l683zLGfM1XqQ3XMCAPlVpF5Jnbd7WXRYSUc/YspFo2T+ l+DnrWw45O+pYeZ3HcaPuLJxOip683lWeJPsllHZXHxWTUCkwh0OiC5Fo4QLgcG7kBKx go9fore1cpUft41DKCtR46S8JVBYCOJwOR5QeDMU0H2gImH6H9s2XZcyWM8zIIcudYPa fXJC3aUZz/NxC90dQNyxft3HmkLB8tfDLNsY8P+RTh8cSSvhw88/Z0zZh4cPuo2ro61u y7pJhTcv3BiHNSPc7jLa0S9P+yFrrG7l0J6LGoOtroWzd3Eato8kjtNpSlNUHJFk/mMb YmHg== 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=Ja5R+JcRPBtQWmflWTU+HMKgpSYjCmZV2qLlUqz+mak=; b=PGvSBjCwC+G92XmKBpg63QXUhepUAwVoRYwb6wSFWv5FD58XNf19rFD9NVyZmEA8r3 YLs6EA5Qvr5Ie0TYypE6e4m3LRCK2hv9SpvdrKv80vE/FZKYsB93UHx+KcNqH7Au3ajo 5eLNPRUsALoKa5ZZ9TnTXWrh1tvh/VBq8t+mMHd20wcC9bNcNSORiYp4z9SR032xdN04 maYmGCIRbjI/7uYZGaUR8sCPsL/bsxAGdsvvWGLMCuCrgnC46WLgJzMYRZ+kPVeMp+6F TR1mlPDosdudGQRLvYlNYpgKLyATJS4Y1dBgqzZZKdu04vHvYqy5nsYtbZln1ZuUrSJf QW7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bi3QvWxO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dm10-20020a170907948a00b00783204942e5si579251ejc.885.2022.10.19.08.05.17; Wed, 19 Oct 2022 08:06:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bi3QvWxO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S233792AbiJSN5O (ORCPT + 99 others); Wed, 19 Oct 2022 09:57:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233773AbiJSNw7 (ORCPT ); Wed, 19 Oct 2022 09:52:59 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C7251C20B6; Wed, 19 Oct 2022 06:36:24 -0700 (PDT) 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 ams.source.kernel.org (Postfix) with ESMTPS id DCE78B82320; Wed, 19 Oct 2022 08:50:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 59563C433D7; Wed, 19 Oct 2022 08:50:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666169402; bh=r3WVB8imRi0X/O5bSGPHZ7EyG3mO2MBxj8rd2X0UboY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bi3QvWxOnzNq3PzTj6++M845WU/HqYe32aDDxz+8SIXUmwAupJ7wImWOP/a47nt9z oiZ0NJ/rCXtrt6JszoIdAk0neq4YmkKzzL18nkp51U6Ak1zh3T1FHBfQlEwMr1EmIl iFX+opY2P+6DLnV+btMtTv3MRwyrnFlZqVzEhWlA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Jes Sorensen , Kalle Valo , Sasha Levin Subject: [PATCH 6.0 262/862] wifi: rtl8xxxu: tighten bounds checking in rtl8xxxu_read_efuse() Date: Wed, 19 Oct 2022 10:25:49 +0200 Message-Id: <20221019083301.614732469@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dan Carpenter [ Upstream commit 620d5eaeb9059636864bda83ca1c68c20ede34a5 ] There some bounds checking to ensure that "map_addr" is not out of bounds before the start of the loop. But the checking needs to be done as we iterate through the loop because "map_addr" gets larger as we iterate. Fixes: 26f1fad29ad9 ("New driver: rtl8xxxu (mac80211)") Signed-off-by: Dan Carpenter Acked-by: Jes Sorensen Signed-off-by: Kalle Valo Link: https://lore.kernel.org/r/Yv8eGLdBslLAk3Ct@kili Signed-off-by: Sasha Levin --- .../net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c index c66f0726b253..f3a107f19cf5 100644 --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c @@ -1878,13 +1878,6 @@ static int rtl8xxxu_read_efuse(struct rtl8xxxu_priv *priv) /* We have 8 bits to indicate validity */ map_addr = offset * 8; - if (map_addr >= EFUSE_MAP_LEN) { - dev_warn(dev, "%s: Illegal map_addr (%04x), " - "efuse corrupt!\n", - __func__, map_addr); - ret = -EINVAL; - goto exit; - } for (i = 0; i < EFUSE_MAX_WORD_UNIT; i++) { /* Check word enable condition in the section */ if (word_mask & BIT(i)) { @@ -1895,6 +1888,13 @@ static int rtl8xxxu_read_efuse(struct rtl8xxxu_priv *priv) ret = rtl8xxxu_read_efuse8(priv, efuse_addr++, &val8); if (ret) goto exit; + if (map_addr >= EFUSE_MAP_LEN - 1) { + dev_warn(dev, "%s: Illegal map_addr (%04x), " + "efuse corrupt!\n", + __func__, map_addr); + ret = -EINVAL; + goto exit; + } priv->efuse_wifi.raw[map_addr++] = val8; ret = rtl8xxxu_read_efuse8(priv, efuse_addr++, &val8); -- 2.35.1