Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp6744508rwi; Mon, 24 Oct 2022 05:41:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4JrG8W/rRlP7A2EFMWmt5CVixr4q6AE8DLBd6KlkCfXe4omLw4GbMceHyPsq9ZTCtq6wrl X-Received: by 2002:a17:903:2285:b0:185:44df:d916 with SMTP id b5-20020a170903228500b0018544dfd916mr33272247plh.120.1666615289808; Mon, 24 Oct 2022 05:41:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666615289; cv=none; d=google.com; s=arc-20160816; b=tWUK3cfwbZcAMZLdNttOQUF9/APgViqFkU77wGcW530ReZOKxtF+XQ52QXI1v3xfUJ 9n6SRr1GvHKjg3C8IUMVullbKw62FXQ05i1JL7Z/66I5VpoCqssJ1m1Z36OuRpB8eNwB /Hcm6s9zT9UCI/J2V73VddzyXpfZiUGt+6J3JjtWdYyvmkHnlbJnMgog5RhnSoQYZqmU q7G5Tavytt5UrB4GUQkNQWX9yAHYQ31R9Khh0NwmkKFr9qmxjlbp3FdPFj8vQ2Uot7Yx I79Zslfcyo0JH3ekHdzJiAWQiPQvR94FbkZXQaNi6GB0lOtAzRybdOlKFHnlHzoA2xSF 9n7g== 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=DR7MtDbi0kG92JDp7zcID920Q3LKMSKywWl2Z84UB6M=; b=mUVneENc87FD3XBSFi/iIcn3KKkopV/YXfY7bUbidZBmcCTFARQuF2VxhD0ng11C1i R+fZunKBFSE5GugI//E/O7X/RwAnQm0P/CpXceytLaNpeQaErlVxURlsq5kg6uxstHeP CBPt8frYNIsbnjjdOBkUiImkxDUM7J7quJ0LA67CTdsCbsD5Wk1N6jg/DWBlAbXtrTdz /+A+OqCeemgIGsaiS+eXIVI3EsXlu9tGm6NjpiPbvUer4Sje7dsQKhMLTxl/DIIzSiYu zPwVdThEeDKx21mUuVqYJxKbZQ564ZQrmJW21/+UV9rYsX06AnimbL3tmOv555vNWzzR ZRDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RIoaaeJv; 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 cj7-20020a056a00298700b0053b9c18617esi30668028pfb.300.2022.10.24.05.41.18; Mon, 24 Oct 2022 05:41:29 -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=RIoaaeJv; 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 S232560AbiJXMDF (ORCPT + 99 others); Mon, 24 Oct 2022 08:03:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232797AbiJXL7y (ORCPT ); Mon, 24 Oct 2022 07:59:54 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEA6D7C32C; Mon, 24 Oct 2022 04:48:56 -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 90D4A61218; Mon, 24 Oct 2022 11:48:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4EFDC433C1; Mon, 24 Oct 2022 11:48:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612136; bh=imA00XoB1QibGoVcRmf2HbsfpTiVfj/6N8ZW4ewYQOc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RIoaaeJvQm8+wEVC0A64vux79lGAFWdYbk19XdVRNqZWSTjedhP+BzH3rRO2F+MKr ODeNn95JzJLzRmEfRXhw4WoJebRoJmQor7FVSsHAE9MvAndyoM2N25VoF+zVKztlqV cNFy1dKE2Vf+4AeQDLBK/gOxZoBWXK9EA9TES44E= 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.14 084/210] wifi: rtl8xxxu: tighten bounds checking in rtl8xxxu_read_efuse() Date: Mon, 24 Oct 2022 13:30:01 +0200 Message-Id: <20221024112959.780851591@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112956.797777597@linuxfoundation.org> References: <20221024112956.797777597@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.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 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 5cf61710ae2f..5588518daa96 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); -- 2.35.1