From patchwork Mon Oct 24 11:29:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8968 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp437078wru; Mon, 24 Oct 2022 05:58:51 -0700 (PDT) X-Google-Smtp-Source: AMsMyM493uB2Vzn8R+ZMhHZaftY9XC7TmRWtxXdP8eH/wIWmwGHjBko9scLNI6RnT10It/2wTQ3e X-Received: by 2002:a17:903:1211:b0:178:a692:b1e3 with SMTP id l17-20020a170903121100b00178a692b1e3mr34431838plh.48.1666616331075; Mon, 24 Oct 2022 05:58:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666616331; cv=none; d=google.com; s=arc-20160816; b=R5Stqx0llzf+FUX2PECfvWBsc14j+1UhnGkfzszKueo+e2LEy9DVWBs1nja7dHYszi nywrK1WoPYhoxIgTSVcJPUbNO3a1LXJvpCGOxjvYupbSLKeuydEc13HlRlcGua367vOo kE8AVE1kGKOdihfWCP8W1T/i8iw8cITf+hDWHYU52nBlVpPdSGyPcS2FXCh0hymp2kv9 CZLAvvQ3uU3KosxWOcAR+CF21/esjbtMHnhequGxQmIP9mUuZaloRpVBDHigy2BAEpkp +CNpB9h99DyBwfGTQukkqq7i+GcJl5dQsnO42a1Cdc19g/fo+9yu/azNyN69jlBkquXp j1zg== 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=Qj0lAfOHOZ+/lqqF0a54WBy1Klx/sYbjtdwHo0GO9I4=; b=pM0ttyAmDbyFcH2RS3p5vlfbi8Qfr/KqqpkEMev6iiWoe3P43y9bPNqPaNmo0dsAVP /A82yGNQWEMdd5RR5hmgMJE9XfyVqecC5Sx2POFUrJ3fLOllPPi3xYkBbTWKo67whJVj I/AOMqVnTtYU5fR5EQI9r2/IuYRF/5s+00b5w+zDCGaIjnahb2HH9Vvp1maXUcc1kZw8 zZEWn60cpYwqj2jnjVawyhW5rwKbcfp+7ixCMNVhIpvqXdmC/XlGzo0TOQ4UduL2Yvii asItlC/2mmZ69RcQm2EExLCqBa66vax51GfWqs4PmGMhpfxid51wxjbDskmYEl2OcADn Xojg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Qu8mdS//"; 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 h4-20020a056a00230400b0056bc14f1cd2si4352237pfh.10.2022.10.24.05.58.36; Mon, 24 Oct 2022 05:58:51 -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="Qu8mdS//"; 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 S234883AbiJXM6U (ORCPT + 99 others); Mon, 24 Oct 2022 08:58:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234855AbiJXM53 (ORCPT ); Mon, 24 Oct 2022 08:57:29 -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 65AEA97D4D; Mon, 24 Oct 2022 05:16:54 -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 9EF0E612B2; Mon, 24 Oct 2022 11:57:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B371BC433D6; Mon, 24 Oct 2022 11:57:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612672; bh=z6WHpchUL7v1QNUs+Lx3TStTDhBohf0Lipf4W3Q1V8s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qu8mdS//86KlM4pK8BT8KoF5XXS6+TB2UBnaVpdTTzuKrlkvJ2XDR929Y+fNVcgNs bmcsDDRTLaNkPSnSR6G2JYjPrrvr0o4zKkHxTZVopxw3zp2KY/3vzbZzfLLXyxY0A2 ogPRZR5ZJCnRDN37WJ4S7Aq3W7uQbzCYEz7wExXc= 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 4.19 075/229] wifi: rtl8xxxu: tighten bounds checking in rtl8xxxu_read_efuse() Date: Mon, 24 Oct 2022 13:29:54 +0200 Message-Id: <20221024113001.502996260@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112959.085534368@linuxfoundation.org> References: <20221024112959.085534368@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?1747573885649953066?= X-GMAIL-MSGID: =?utf-8?q?1747573885649953066?= 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 b80cff96dea1..dd345ed1a717 100644 --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c @@ -1879,13 +1879,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)) { @@ -1896,6 +1889,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);