From patchwork Mon Oct 24 11:28:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9245 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp461262wru; Mon, 24 Oct 2022 06:43:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5s7K8U0qUdOV838jdc9GDzbPE0PvPmJR9QwEO2Bc6mKHYoABnJVE1H6vBfjhxtFAHrlx0j X-Received: by 2002:a17:907:2cca:b0:78d:ec48:ac29 with SMTP id hg10-20020a1709072cca00b0078dec48ac29mr27499546ejc.114.1666619011030; Mon, 24 Oct 2022 06:43:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666619011; cv=none; d=google.com; s=arc-20160816; b=mRLEWBr8T0ZmPI1Qozn4C01jyASFxsQThNrEyzxRBLoLhigzsFtooGNknjDgeTOhu8 OcZR9hehv+B4FdFJ+D5/1TUAwj7BIgK8SdH6ENW4Sm3Hf+0TK61nsGTg/hD6Ed/23CKY AfJuYHa4mPRWMjY7OUkEa4IAK6PZfAqJAUkFFgwCYtp+/k1KAPlQFTtciqCYatZ2qvzr LT8K9EBi8ynRHfQMgcFoUj3hE+qmgG4+5g9FMKzAyXbiioO6z+R5XZdHOSKI++mkdVMd Bg1R8bpaIL23FLnzr5J3OqVWPL7C5wGpcDS1qjHbQIbOKvgaZNcTMH2gP4hliKEZ1GxY ZbyQ== 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=DKbjlp9COskE0iXo4+lPNi6hAr1Vn7NJ/R34TcZbf3Y=; b=E1cZN2ujv/xrw+1BEmjSI7IbhFHRjYOf26vU+btIB0jeo4nlwa38JvfqZcwTWxVwgH 6G1+JlXsWVCJRaR4Cc3p29R7PXqbBF+CHCnGZOGAw4cONwspJT3fVuP+eOJ6Vf9UT3sS +95/odBcR2/1oWBJqgXCBG1B4MRTPnVpDUvJaJjd0y6u8wUFRKNdw4CUbwZli1ifyG/e qwUD4Op6AVydcm0LNEXScUqaHamf5QWO8cJa6WOSSKnTloTgoMGq6v787hPn8MNiXbgT a8ozFZmL36d20NKzYFfmm3xJvUpAP4ExT8TXylLcEhvdEWSViql6UDLyouM0VukNLKhk fNhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AZVR7fqt; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hp1-20020a1709073e0100b0077b2e822b8fsi25988232ejc.76.2022.10.24.06.43.05; Mon, 24 Oct 2022 06:43:31 -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=AZVR7fqt; 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 S236140AbiJXNih (ORCPT + 99 others); Mon, 24 Oct 2022 09:38:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236244AbiJXNfH (ORCPT ); Mon, 24 Oct 2022 09:35:07 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC123A59B4; Mon, 24 Oct 2022 05:35:36 -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 dfw.source.kernel.org (Postfix) with ESMTPS id A41C761015; Mon, 24 Oct 2022 12:20:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0E3FC433D6; Mon, 24 Oct 2022 12:20:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666614040; bh=th6X64vBFDGBJVQqdl89pcBqJfv9RIx2T1+TgYlgu4M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AZVR7fqtMCc+W4HI30xcLJlCLtXWerU0chXR78Bn2r2q5Xj2Wt9davuYtPukONyoB iAxbPZyRhfj47N7MOTM0tm019+DMQaevHIqjOQRsfTbtdBqJZrOx/v2ShekhnzbQ5A 0mUpFB1A3b48T76tLae1ZBmsuZPfn2IRGyhIjOFg= 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 5.10 109/390] wifi: rtl8xxxu: tighten bounds checking in rtl8xxxu_read_efuse() Date: Mon, 24 Oct 2022 13:28:26 +0200 Message-Id: <20221024113027.352649546@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113022.510008560@linuxfoundation.org> References: <20221024113022.510008560@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747576695618274374?= X-GMAIL-MSGID: =?utf-8?q?1747576695618274374?= 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 0d374a294840..9f646964055d 100644 --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c @@ -1874,13 +1874,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)) { @@ -1891,6 +1884,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);