From patchwork Mon Oct 24 11:32:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9597 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp529206wru; Mon, 24 Oct 2022 09:03:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4mQfMNOUVXZZayF6SA4p31wTfA84JJp3ERw8gFdvRaG5VkMsA6LO+qBueOpHjPL4lDg2if X-Received: by 2002:a65:6bd3:0:b0:42b:9117:b9d1 with SMTP id e19-20020a656bd3000000b0042b9117b9d1mr28613695pgw.238.1666627398152; Mon, 24 Oct 2022 09:03:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666627398; cv=none; d=google.com; s=arc-20160816; b=KD5qrCTfTndEtQb3GAWl96EIhoLDm/jBVN95Iht0ErxvmSzpiJoJVW4+sjd3FyyQxe UoVuCk/ljYHKR6iEoPz/Oi8Dg3SDz+7A9GkeXGt/cYeVqs4LifM7f5684YSgh/hBcnNh FVTXRTVAcQyJRITjNKzxh4S9kdnO0El73Nkyj/rm0kKDMsGZa6T/7EeK4P9kc8le7bjN mmtLATlP3GhLdkQgf3OKbUET/XcKC7PVatdw3Trn6VbzdgY6CqD7q13x6fTUstvALrbB F+XYFJlTA2dKITj9vussXZMSgJ9QcN+0ToAh6OPZzat8G++fwuWsP0SWQ7aGcJhHLW0/ tADQ== 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=QZg/ud0PR4HhIKufE3DtO9Ps8OikgAh8HSKmBubdDFUdYdqpdwHgzEB4KANq0F6YUv FBIcsBdhC1qnV42WqgxbpO1+l64bkNFnwzgqteLM2/hASH2+PTUgCtMo8g56AjcQSM3R LfHRx6MnB8BPdE0YBzJYSP46lIqF+qd1rr8NhnhNTEWoNRLAL2kwa+xtRB61NlEfqs3l 93JfWsVT13QhMkSpG3Q8fnVYKAmgqPlwPd3rv3uV1tCafhc/udNLEbMwLpD7Q0yWvasC IldUeWR5WOtcwxl1EucQXv6ZUWBqPUbEwboECNyC2DsUrx4SejfJU5hjr6oAOi0uxUz2 NBkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sN5VldWl; 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 s1-20020a17090ae68100b00211f23d6f49si9305603pjy.15.2022.10.24.09.03.03; Mon, 24 Oct 2022 09:03:18 -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=sN5VldWl; 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 S232561AbiJXQBv (ORCPT + 99 others); Mon, 24 Oct 2022 12:01:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232799AbiJXP7W (ORCPT ); Mon, 24 Oct 2022 11:59:22 -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 1076A40BD0; Mon, 24 Oct 2022 07:54:51 -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 29EF2B8136F; Mon, 24 Oct 2022 12:31:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 855CEC433C1; Mon, 24 Oct 2022 12:31:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666614693; bh=PyVuP224LTfOgKeY7PGhWDcswJIc+RIZ/ujbhn1tRm4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sN5VldWlkDacHmzuuKaQzuJGcOX1ydcNZy5fBzODSZVNfHD8/kFMC8/W05MRoAZJJ yyQljQBfay8OeZAotdi5Tgr8RUzlAEj9t/Lvd8qPTMIobwXoZLkrqI+X4efCl3+cjZ MmoZVa9xhKBFsOTX3jvef5WugWVTPDK+6d1oZWuU= 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.10 359/390] power: supply: adp5061: fix out-of-bounds read in adp5061_get_chg_type() Date: Mon, 24 Oct 2022 13:32:36 +0200 Message-Id: <20221024113038.282171909@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113022.510008560@linuxfoundation.org> References: <20221024113022.510008560@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?1747585490971032593?= X-GMAIL-MSGID: =?utf-8?q?1747585490971032593?= 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; }