From patchwork Mon Oct 24 11:32:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 10210 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp642438wru; Mon, 24 Oct 2022 13:38:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7pEKrckfGG2pBZMi7VRgvRJPAmbUM46vTT1E+WCWuC01lPjHV/weTAuboCGtrz+a4rXMjf X-Received: by 2002:a17:902:da8b:b0:185:5723:5834 with SMTP id j11-20020a170902da8b00b0018557235834mr36115646plx.49.1666643908933; Mon, 24 Oct 2022 13:38:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666643908; cv=none; d=google.com; s=arc-20160816; b=mpCX7j/BGD9E9IVmvS5k2HTQQhITCcRe9/aEYN1YrE2rn3//6fadEkBER+ECULvA+o yHAxqjr6qY7fyVgvB8UE91wFZ7fqePCO166wh0aH/aHReWniC9vPprIsOXlQ8hI0UiOh LFEvzms4UetdQB0jiBgIEkNOQyVUaLBcGcjKl/rqmszqISfTvFVlzyhnCzQnFD1yLMt7 jxB61dNBDSug5YT30TK0vvsHv2oOFfAlLjXp3WFvdvx508S4gJ9C/+bm7Lx69vpDhWe6 pgIDPm1KitdIWY1yA7QJdn7Pm8KUApIZz6++vy6SCUbxDkndBE7izrZUG2irS43eEj2/ 4iTg== 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=TKHqc9ZLLrUx8+9DBnLFIAM0Clf2OztnfDWE4+pvhnRJfddtCl11jowBk0HL1UFEn9 a4hwaxi8F/0ioMOEscJ4siNi2THSN2rIkjGazhdRp9P5sXuHU6mMyTXcjJ9RF9zF454a hvR06yHK4XiiW2NDgEBddy1XUSV33Z10HbsOxSSVzvwe9BBP2vwSkF1myhuZx3Pr5tVT WMqDhY/Gqsxw33zRfO96vyXTbK7/RAsa/gFQ4M1JzIpEJ7OO0WnlGAVJssEOFQnNthFL 7RESIhKkMMMuXd2E86EE6ElYw7xy8NO8n7mr5IUXteCgbBCMFDj+OdGM36knCDHhWLYX wZyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ntChBk9W; 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 z13-20020a170903018d00b00186b9b292bcsi719338plg.2.2022.10.24.13.38.16; Mon, 24 Oct 2022 13:38:28 -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=ntChBk9W; 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 S234489AbiJXUgx (ORCPT + 99 others); Mon, 24 Oct 2022 16:36:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233946AbiJXUg0 (ORCPT ); Mon, 24 Oct 2022 16:36:26 -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 E324C4E85F; Mon, 24 Oct 2022 11:48: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 DC420B81609; Mon, 24 Oct 2022 12:14:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F939C433D6; Mon, 24 Oct 2022 12:14:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613687; bh=PyVuP224LTfOgKeY7PGhWDcswJIc+RIZ/ujbhn1tRm4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ntChBk9Wsm0sS2l8gIZc3CWz83wQmyOLz9tDPjq0ET3aDQwhB5tuaNsGxf5WF4kqx Jv9F3tnTtcVLyJoxwS2UMxCjzCQGWXBLaR7gC6wWjjNO/2BtNvLVEIGIbwzhO/BTEK lIchwTGG6j5+RigJmpw6en7671fxl/4THzoEMY44= 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.4 232/255] power: supply: adp5061: fix out-of-bounds read in adp5061_get_chg_type() Date: Mon, 24 Oct 2022 13:32:22 +0200 Message-Id: <20221024113010.884290799@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113002.471093005@linuxfoundation.org> References: <20221024113002.471093005@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?1747602803130873897?= X-GMAIL-MSGID: =?utf-8?q?1747602803130873897?= 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; }