Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp201629rwi; Wed, 12 Oct 2022 18:38:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7cXwBMmLby5DQHr13mpY7j7djaawALJ/HGSQjUPzNI7VGGi1EBmqOg0S0K1CZhPmhxyLwC X-Received: by 2002:a63:ce43:0:b0:45b:d6ed:6c2 with SMTP id r3-20020a63ce43000000b0045bd6ed06c2mr27793784pgi.406.1665625093233; Wed, 12 Oct 2022 18:38:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665625093; cv=none; d=google.com; s=arc-20160816; b=ibhicJuhODTP1KRj2JoxfQfwlOKg30ldH+FYJKclTlA78SNqCRLO7MjWdtqUEWh+Rb rhemLyrogoVSL7lpWJ+iD4gpoa4s0FBy6WwK4bD9T0EPaws/uRDt3u+OnmpB5i9C6xsw sJ8P9xsl4ko+DUvePpZBt9nZ5DZrfuh7xI8PwmhF+Mh5jPhlMtAweCJmRXhmw94l2KPw Vnwd2GhEx6zoxV8zphhN35jyyo40KKixoA0B7NGycXMRqpsWjlSME9L7q9CWyukdd+/h Qo9+m17kBBc9yAL3UrKqbEJmnE0wkeLtbdIgyMl5ucrZLRhKRcWzRmoCd7GiWRsMbN7b mS0A== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mbeuuKyS1JYr9BJ4A8TldBavJoN2bhxICYGV6ZtSC3g=; b=LsOrgExSzsXwlR1UMZijSA3neEA85/iccNbGeYqSpzGQLrDYXRwpwu6TUB4j1yo0J/ GFwx0riYV8DBPNssywbPQ+Uw/nbZrHdYiFW7l9YqG20wlsw3UFEI2NXW8NunhFyCZ6Dx 1yAh7lsnnAAoBEGZ2fFsOreY+kO/jAFBX9X6qEf0twQo0E88rQSAuj9P+MfORwVtqtwp kBO1gPcRA/H+e4ITMD9Yo3r4wx3P9qb30EDZzyiBI5d4tdGbf59vWfr4I5nex47W2iuu T9Mneby9unWINg7cwK4xvcMRsdCx4I/g1NkTa4LBqnL8yras1p4ueLGlykoBGr80repY axEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Y8/7IYOg"; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q29-20020a635c1d000000b0046ae00c77b4si3034934pgb.850.2022.10.12.18.38.01; Wed, 12 Oct 2022 18:38:13 -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=@kernel.org header.s=k20201202 header.b="Y8/7IYOg"; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229982AbiJMARl (ORCPT + 99 others); Wed, 12 Oct 2022 20:17:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229957AbiJMARW (ORCPT ); Wed, 12 Oct 2022 20:17:22 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 393D0FE91A; Wed, 12 Oct 2022 17:16:47 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 373D06166E; Thu, 13 Oct 2022 00:16:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9FB65C433B5; Thu, 13 Oct 2022 00:16:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665620200; bh=PyVuP224LTfOgKeY7PGhWDcswJIc+RIZ/ujbhn1tRm4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y8/7IYOgf4oJo+BMNcaaV7aT1YoBnrX/zBqNu1zF8maNdCATEgYawfQHXdKMm6SKT HxxMPP9wfIyW8p/6+3r1cx5XpIOrluNOd8lew2KErwBUTetDI02+i05YFMEPK9OZM7 BsPe2BCC89m9Gqt2GmaxS1OmDPAJzB6xtFgGyZRuyJzqfSg8qu6hAcq/ZZoqEL7sJk zl8Oglp3YkjHrqlvBGISt/ip3Oe0EyBvKpr93fQd9Iso2vUuogLJtDCFPIdF2Wiv4A 2DMWi1bU6D1gKsNMobgNYiExqtczdQa1sfRpzlDvqCcbPndYOMBey+QEK15aTbPYL6 ZIhtok+b2BfPg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Wei Yongjun , Michael Hennerich , Sebastian Reichel , Sasha Levin , Michael.Hennerich@analog.com, sre@kernel.org, linux-pm@vger.kernel.org Subject: [PATCH AUTOSEL 6.0 17/67] power: supply: adp5061: fix out-of-bounds read in adp5061_get_chg_type() Date: Wed, 12 Oct 2022 20:14:58 -0400 Message-Id: <20221013001554.1892206-17-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221013001554.1892206-1-sashal@kernel.org> References: <20221013001554.1892206-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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