From patchwork Wed Oct 19 08:25:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 5568 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp350541wrs; Wed, 19 Oct 2022 07:13:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM710p0vJsZDiF+zg5NE7a+RE2D8zb7A18iYHiUsGD18aQdqHc5uy5pCIR1F/KPSR91hA7qp X-Received: by 2002:a63:2a86:0:b0:46a:eaba:f1f3 with SMTP id q128-20020a632a86000000b0046aeabaf1f3mr7332556pgq.79.1666188834582; Wed, 19 Oct 2022 07:13:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666188834; cv=none; d=google.com; s=arc-20160816; b=aOxiSFIYSNpjGONj1ncHGd+KbvElU4jX21fApzLr1v/VcogNjfl6aPrywHNpr4bYRv N8kbW31bm76dq5p8NVJVLgURauQYWsYFIRhe+qKEEcm7M8KIlv6qU/uYhX/LkOCYsc3d CV6kx1I6x6EVCT7LC/ZBHTdUipDxWlgato+fzJdUpg6JMSvBhLPwaZYAwym8o8Kjalx2 wQdiQpxtT/SWzNTqcfjiOv9SZTv2gOiqCemfYSC3PCZrGD2QJgFcOXLuoztTtZhXOjYw 7jnlLQwQHP9S3nl7GS6hQGCiFCYzVLZKLb8jMIFHRBHGNfkCkA7pDt4mO/9upEvEzuU3 bx/w== 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=Ja5R+JcRPBtQWmflWTU+HMKgpSYjCmZV2qLlUqz+mak=; b=PGvSBjCwC+G92XmKBpg63QXUhepUAwVoRYwb6wSFWv5FD58XNf19rFD9NVyZmEA8r3 YLs6EA5Qvr5Ie0TYypE6e4m3LRCK2hv9SpvdrKv80vE/FZKYsB93UHx+KcNqH7Au3ajo 5eLNPRUsALoKa5ZZ9TnTXWrh1tvh/VBq8t+mMHd20wcC9bNcNSORiYp4z9SR032xdN04 maYmGCIRbjI/7uYZGaUR8sCPsL/bsxAGdsvvWGLMCuCrgnC46WLgJzMYRZ+kPVeMp+6F TR1mlPDosdudGQRLvYlNYpgKLyATJS4Y1dBgqzZZKdu04vHvYqy5nsYtbZln1ZuUrSJf QW7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bi3QvWxO; 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 ds5-20020a056a004ac500b00562dd22d708si16426557pfb.189.2022.10.19.07.13.30; Wed, 19 Oct 2022 07:13:54 -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=bi3QvWxO; 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 S233792AbiJSN5O (ORCPT + 99 others); Wed, 19 Oct 2022 09:57:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233773AbiJSNw7 (ORCPT ); Wed, 19 Oct 2022 09:52:59 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C7251C20B6; Wed, 19 Oct 2022 06:36:24 -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 ams.source.kernel.org (Postfix) with ESMTPS id DCE78B82320; Wed, 19 Oct 2022 08:50:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 59563C433D7; Wed, 19 Oct 2022 08:50:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666169402; bh=r3WVB8imRi0X/O5bSGPHZ7EyG3mO2MBxj8rd2X0UboY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bi3QvWxOnzNq3PzTj6++M845WU/HqYe32aDDxz+8SIXUmwAupJ7wImWOP/a47nt9z oiZ0NJ/rCXtrt6JszoIdAk0neq4YmkKzzL18nkp51U6Ak1zh3T1FHBfQlEwMr1EmIl iFX+opY2P+6DLnV+btMtTv3MRwyrnFlZqVzEhWlA= 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 6.0 262/862] wifi: rtl8xxxu: tighten bounds checking in rtl8xxxu_read_efuse() Date: Wed, 19 Oct 2022 10:25:49 +0200 Message-Id: <20221019083301.614732469@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 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?1747125623155963221?= X-GMAIL-MSGID: =?utf-8?q?1747125623155963221?= 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 c66f0726b253..f3a107f19cf5 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);