From patchwork Sat Oct 22 07:21:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7298 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1093008wrr; Sat, 22 Oct 2022 00:55:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6tlup+TT3GyE7HjUBj8LCQpmpJ/yaQTXbVD1qdm4IO+2CuHZsW02ZZ7Wk8iidxKNXZ7nyC X-Received: by 2002:a17:90b:224d:b0:20d:8828:3051 with SMTP id hk13-20020a17090b224d00b0020d88283051mr26091250pjb.89.1666425345049; Sat, 22 Oct 2022 00:55:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666425345; cv=none; d=google.com; s=arc-20160816; b=W7HcHmH23lWHaDV5cgdC7rcd4r0PhiwSzi5C87nnt6oNM8kjVQGqHUaG8ZYSd5kyni P834Iib6Yi4X9QR9xs/YtlVDEQUPCTac/n5F3DU+cU6DOr8j1symlVZigJxJMk1mHNQz sJGEptk+tgpXwFjDq/90+idcbzKZ/k112WW8sjOV+ESe1qy2plqOpOpKlfoOvQ90k3qj 8egOX5eFGb5PJSx9kB5p2W4StL2/ldN6UTTOrcntVXSR2PM8NJ591j7oKcR+hDcIaHi/ VG5F2Fhf+lphplOxLeajzvolp7ZMe/U08lub/YPsJ+hasywGGdvwRtf9Z9Ka5FTPR5RX tzFA== 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=iiMouDlbmyNjYMDJcDEbqrUbAUGRBRgdVaZ/MwiRD3I=; b=M6CSizTpBGLRzxrZPkYl60VpbEE+MIOL/6xHIE5NbEJZfhnpA2icB/sjTRSJMR/hTx mA+sFH0Tk8vigzSzY09UAusq1X1WY2dsogScCdExblVA49mGgdm6VuktsgmtjmXNE2Ts rhSs0Jx3VW+PdBvxyRvkeU8A65uWM8R0W8ls8nzahpDTV1Yh5/8cbPOrN7b1OdGCmI9V aCNqV6mFaQ6v9DPcCGOnI0FZt/+05m1uvC1utsW59cgTh701jomlIZsgI1DV5mMOH9+A wHYKs7ch+vzFFVsl10UOuiBxeFzjmT5DajO2OZXhsMqxI9scWEankgZGYGLd74ApunC3 04NA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="F/gN75wp"; 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 p24-20020a170902b09800b0016d2f548842si24032538plr.105.2022.10.22.00.55.31; Sat, 22 Oct 2022 00:55:45 -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="F/gN75wp"; 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 S231883AbiJVHzM (ORCPT + 99 others); Sat, 22 Oct 2022 03:55:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231985AbiJVHv7 (ORCPT ); Sat, 22 Oct 2022 03:51:59 -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 29B87AC28F; Sat, 22 Oct 2022 00:46:34 -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 3F08760B27; Sat, 22 Oct 2022 07:44:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B30EC433C1; Sat, 22 Oct 2022 07:44:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424657; bh=9vXiCE0BvIwGv1vGlOobuOURIED+4AIDnWGgCQuShT8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F/gN75wpAD6xAqLasLfbitG1V6UnwqmJyx6E0dg7k/xh9BG1LnCLhwMIn8a07dFyy nLdoU6LS/Gv3FeZbeZ+n//EICKcXbtOcZYDbtDD9MdOjgu5IkHIMV+QYGTzNy6kA9G NBlaghs0rx3bg0CleGrE+TR7fhisI52KoCFQJZL0= 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.19 226/717] wifi: rtl8xxxu: tighten bounds checking in rtl8xxxu_read_efuse() Date: Sat, 22 Oct 2022 09:21:45 +0200 Message-Id: <20221022072455.101563057@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 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?1747373622983169936?= X-GMAIL-MSGID: =?utf-8?q?1747373622983169936?= 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 8b2ca9e8eac6..7f09359a238f 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);