From patchwork Mon Oct 24 11:33:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9815 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp555027wru; Mon, 24 Oct 2022 09:58:47 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7viFBO74Iu4TbE3VEuKJkg4jIkDwQxEwIs4HwJTpRs/dtb9wdvImYlioDrPV9s7v6HR5z1 X-Received: by 2002:a17:90b:1b07:b0:20d:571c:1d3d with SMTP id nu7-20020a17090b1b0700b0020d571c1d3dmr40109892pjb.192.1666630727353; Mon, 24 Oct 2022 09:58:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666630727; cv=none; d=google.com; s=arc-20160816; b=fJd0lpUvf2vtSBe/rsCGUY3MntY+j5MTQo7us174frIMPZtlv59tlHJ9GpkEfizsIk GdjXBLtpbVzBE7mVZY2leAMhQe/zQ/eIvWYWu9rb2WuX/ZcuxBruk5L+tgcyJCNHdK8+ 0/k1+frmZngQmio1fL4YmnktGunFuxpNXkRiucO5DXbaruaA6E3UnoU0A+sfUrz+ZvE9 z/WnSYVHYHFIoO1yYvxqStPaCcBbyc7LmxHVNlN2W1qB9tLE5rh4Rr83Xjl0eRYXRAo8 y70ERG2qN4O+18vcC1nzgp5Q6vc06odwZS0eGEAGHJt0OzqcGE9iJihwGO96YzED6Tyj 60Vw== 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=mbeuuKyS1JYr9BJ4A8TldBavJoN2bhxICYGV6ZtSC3g=; b=Y2cStGDy28Tl4eht7bwjvrLZ2V9t5nFv9T+jcdXNynJXCWUoRdnMZj4gF0I4TxOVC1 SPemtYYKIwUyi7euEssgZNHgKsZ2th4VS6a8Dp+/lZYr+T02BT4fQLZyJhgmJ/AqJU4j 7xakiF72Cs9Pqs0udd1cTA8I+IMVyYqdF+vBoBuOzIrU7rL/2Wf9dnNgPmlbPT/QEENZ I1uS9kzLe3+HQr+Nu0P7IVO2M8Rz5UJWJyfDm+iTCvdqqmTjO1PBEUkgMhiY4Fr5Y29r Ow12EU2MxYAafmVp/0fyAr2Shfqo6UzQ6czcbD30vrjeEv6b4IMZHavPTwFVcHCcwTIf J8Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="R0XxB9/6"; 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 q33-20020a635061000000b0046b1da8c356si35908847pgl.619.2022.10.24.09.58.29; Mon, 24 Oct 2022 09:58:47 -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="R0XxB9/6"; 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 S232396AbiJXQwf (ORCPT + 99 others); Mon, 24 Oct 2022 12:52:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235238AbiJXQtQ (ORCPT ); Mon, 24 Oct 2022 12:49:16 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6248C50A8; Mon, 24 Oct 2022 08:32:12 -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 A32C4B819F9; Mon, 24 Oct 2022 12:54:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EDA3DC433D6; Mon, 24 Oct 2022 12:54:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666616062; bh=PyVuP224LTfOgKeY7PGhWDcswJIc+RIZ/ujbhn1tRm4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R0XxB9/6b5Kqfh56lVP3/+KbrVthUSC35wuu0fcO6jcBeJZb8LM/xFfrhO76i5UVv sc+SPDFr5n9TNUd6KTemErvLLFRIA4Pw9fNtFHlRWZ3my4gvvuFHzK7tdSDA7QzwfP H8Sl2/0uBw7D4EjbIcPBdprLbFdlzOO6zvaWIA+o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wei Yongjun , Michael Hennerich , Sebastian Reichel , Sasha Levin Subject: [PATCH 5.15 486/530] power: supply: adp5061: fix out-of-bounds read in adp5061_get_chg_type() Date: Mon, 24 Oct 2022 13:33:50 +0200 Message-Id: <20221024113107.048814548@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113044.976326639@linuxfoundation.org> References: <20221024113044.976326639@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?1747588981602189964?= X-GMAIL-MSGID: =?utf-8?q?1747588981602189964?= From: Wei Yongjun [ Upstream commit 9d47e01b9d807808224347935562f7043a358054 ] ADP5061_CHG_STATUS_1_CHG_STATUS is masked with 0x07, which means a length of 8, but adp5061_chg_type array size is 4, may end up reading 4 elements beyond the end of the adp5061_chg_type[] array. Signed-off-by: Wei Yongjun Acked-by: Michael Hennerich Signed-off-by: Sebastian Reichel Signed-off-by: Sasha Levin --- drivers/power/supply/adp5061.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/power/supply/adp5061.c b/drivers/power/supply/adp5061.c index 003557043ab3..daee1161c305 100644 --- a/drivers/power/supply/adp5061.c +++ b/drivers/power/supply/adp5061.c @@ -427,11 +427,11 @@ static int adp5061_get_chg_type(struct adp5061_state *st, if (ret < 0) return ret; - chg_type = adp5061_chg_type[ADP5061_CHG_STATUS_1_CHG_STATUS(status1)]; - if (chg_type > ADP5061_CHG_FAST_CV) + chg_type = ADP5061_CHG_STATUS_1_CHG_STATUS(status1); + if (chg_type >= ARRAY_SIZE(adp5061_chg_type)) val->intval = POWER_SUPPLY_STATUS_UNKNOWN; else - val->intval = chg_type; + val->intval = adp5061_chg_type[chg_type]; return ret; }