Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp7436643rwi; Mon, 24 Oct 2022 14:47:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5so5AFCLylzx4iJq3cipQInoaFU1fnhp3lhzh98HI7Kgkf/4zXMJjVpa7wMWu3oRT3NBp4 X-Received: by 2002:a17:907:2be9:b0:7a1:11a9:1334 with SMTP id gv41-20020a1709072be900b007a111a91334mr1380774ejc.131.1666648024492; Mon, 24 Oct 2022 14:47:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666648024; cv=none; d=google.com; s=arc-20160816; b=tzL7raHSG0hBobEhDBCEzIOzH/8uB9J/BqLNJhLeBYgElJ4EzJ8SqDRj/qpMvWjMbg VDqeH3LT6LRQMrzjEovdPKYbjdR78/w5pyPT4X74OfpakGanW1wCr7JJpp86RMQd5uwk Zu4+2MMrSX5yrwNW68iOD6loeZaajTC2Ypo2MuxROOHNpo3abUOAHGsvL2FibH79h0Y+ Qsyze+Xv9hAnA6VYDZDcE6shjCg7IQ9Pzrw9+wZVAA6uG3BbTAF5I9WQtpOQ+LfpkNid bBn2+EPI213G6ruJe9fUsr+PKJApJz4EE1IxO6RWutIr4DvRY6NHsyPvdg9HASceXLk6 9N6A== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bf19-20020a0564021a5300b004595af54eacsi738900edb.226.2022.10.24.14.46.39; Mon, 24 Oct 2022 14:47:04 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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; } -- 2.35.1