From nobody Fri Dec 19 16:01:35 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 54D5AC04A95 for ; Sat, 22 Oct 2022 07:55:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231898AbiJVHzQ (ORCPT ); Sat, 22 Oct 2022 03:55:16 -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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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/driver= s/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) =20 /* We have 8 bits to indicate validity */ map_addr =3D offset * 8; - if (map_addr >=3D EFUSE_MAP_LEN) { - dev_warn(dev, "%s: Illegal map_addr (%04x), " - "efuse corrupt!\n", - __func__, map_addr); - ret =3D -EINVAL; - goto exit; - } for (i =3D 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 =3D rtl8xxxu_read_efuse8(priv, efuse_addr++, &val8); if (ret) goto exit; + if (map_addr >=3D EFUSE_MAP_LEN - 1) { + dev_warn(dev, "%s: Illegal map_addr (%04x), " + "efuse corrupt!\n", + __func__, map_addr); + ret =3D -EINVAL; + goto exit; + } priv->efuse_wifi.raw[map_addr++] =3D val8; =20 ret =3D rtl8xxxu_read_efuse8(priv, efuse_addr++, &val8); --=20 2.35.1