From patchwork Sat Oct 22 07:29:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7685 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1108969wrr; Sat, 22 Oct 2022 01:46:46 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4SZ8K3+fRVP5m0sqav5JK6d5XpC+qcwl6KLxseGKLKAySZ4E+SIMxEPa2EiO+6UDpr2yXP X-Received: by 2002:a17:907:2ceb:b0:78d:b765:c50d with SMTP id hz11-20020a1709072ceb00b0078db765c50dmr19095815ejc.73.1666428405910; Sat, 22 Oct 2022 01:46:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666428405; cv=none; d=google.com; s=arc-20160816; b=gxRG7PUdWhA/8NnbbGlqv+FLWVD8M+XT3Hedck3gl1v1Ivc8TEPm1CJPzpr9eija2l TPtqwbi/vgNb2Hh/vIkVYLw8kO+I6jeiduQUPModsteufca+4XZNjmVFsvzdbJWDmA0V WF2VNejuNoDoamTx2oie5rBQ9eDmldG6HTIixa+TOxd9ssT8fG2fuwrv7qFbF56YqNiE csdhMU4v8WUJ1DAjb7ygvwravSaYtgOjSl51MVApuY6NKhUbJmeyX2jjUtbLxOFqWQYz IzyrqHJaUUg2bTV7IK+HaGS+zTNvUhRXhwr4kPXNYBfTb7FigrfIYMPtHwMdVLy/V6Aa CSAA== 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=Ien8M8CGorerIlw8I261tTwiPsa+Zh1b2I3iDmsiO97UElGQaTXnXr5VWuVkmxdzyU 5U24r87bSq+N2n5iKNLB0bBEebFCAydf/RE/dcqPs+QknLMZEopi8+dSkmQIf0fwjmK9 J7sK0e2sF69CEBnxAQB7mcnrHJedfRLtxSDfyhyBRwHkag6TK6ImOCjf88EbB4HTTayJ rp4cZC1esh+3YzNif5ffpByswfcvcesxMiiPVnjfxNmzfCVg+BUz1aqTVl+xPGhhZhKx nwnG/wlrWkKCbv7n+qK5mEZu6Al2FZqRpNP/7OniKsesbjJpIJThAm9d0JGU94TOPhUV dDBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aHxEysoY; 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 g11-20020a056402320b00b004613ae68ca0si4425585eda.442.2022.10.22.01.46.20; Sat, 22 Oct 2022 01:46: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=aHxEysoY; 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 S231854AbiJVIp2 (ORCPT + 99 others); Sat, 22 Oct 2022 04:45:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234490AbiJVInL (ORCPT ); Sat, 22 Oct 2022 04:43:11 -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 2AC732E96B6; Sat, 22 Oct 2022 01:07:09 -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 7C1B8B82E39; Sat, 22 Oct 2022 08:05:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8A34C433D6; Sat, 22 Oct 2022 08:05:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666425931; bh=PyVuP224LTfOgKeY7PGhWDcswJIc+RIZ/ujbhn1tRm4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aHxEysoYtx0YQgZ3g7DWu0/1W0TUiTLFXBipaNMQF/3h4HPltWp1Co3LnBQ7e2gp/ cCajn5bopvErNy3Ulaqipww46kJyKpdQttyZXgPaXuLh8q4Lp0lc+Gkgf2PeyK0aKv 2sYbRGW4pN/XV+IwC9MwTfEdeurhL5MjwGe4ONzM= 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.19 663/717] power: supply: adp5061: fix out-of-bounds read in adp5061_get_chg_type() Date: Sat, 22 Oct 2022 09:29:02 +0200 Message-Id: <20221022072527.715316714@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?1747376832481127222?= X-GMAIL-MSGID: =?utf-8?q?1747376832481127222?= 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; }