Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp7114762rwi; Mon, 24 Oct 2022 10:01:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5+eDQpBsrqcCNZNTWq616UAxB5ywb4MFSi0BkO8ueVcyv0bfkwdkiT/3Q5/JKJkcbtuG2q X-Received: by 2002:a17:906:fe45:b0:788:15a5:7495 with SMTP id wz5-20020a170906fe4500b0078815a57495mr28919467ejb.633.1666630864187; Mon, 24 Oct 2022 10:01:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666630864; cv=none; d=google.com; s=arc-20160816; b=zP2dprXgkaJ4NAYXEfTWzN+II0tsa5G0T3JviVHnChRbseHF6h46sbM8sHBOjpWHhF ikP1fDAPTyH+M9tROf/SBwqOrSSXbzWJPgf3HNPevL7p2HJsyrfAUkm5rkPr5FdW8BT1 kHFzPVkcwS4CeWo6nriH1ylHr09+z0j5RcBHrrJjNdn/zikr8OEqp3XYNq5fHOMtZ/mC fB28bfnPNeepGOEte9/nCMUJhI3ARK7620ku+mzRaXgPluD7TRiYY32I/TiKr/eev80a t2Pg2MecqxDA/pKP5Ls33hPtK74KnjWiC0PQcMyNZCmWmbU8JvT4wfx8rGN3cUj02Tb5 jGvA== 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=H7/P9iODaKC4Rx7yhrYbvBxQwBMbLB5+b17qzc6SIJw=; b=GVhlKoZ+NbfrjDgwXnnD1jFLE6eKUeRaoov19fOQOJfOQZIDUKahoN4fbp4XG9cU7q IEureC51JVKI355YEx7rtuXAy8qo/w/i0yNlZYT2ZWreRbaBS79Sumltd3lm4N50tu0w X3zBPjpR26jHxCU9UqgvLWN0l4MACNOqw62QmFhJWFRT9PePKwERQhsGXzAtmXLWCFYG dGBdZ1LryJNNxGlWGt2bvnn7iO6vOZN3MKRkJQ7aExd09+SjTz3SspSOONXsx4nF6Irs yd9ZuUlRCKQnnxALeDviuGLYANSXNAkGCrpbJtzQlgILkdDGvf0C/xzaoEqDEo4paeKh 4zQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=R9T2TNYE; 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 tl25-20020a170907c31900b007309eb6dcbfsi213907ejc.372.2022.10.24.10.00.32; Mon, 24 Oct 2022 10:01: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=R9T2TNYE; 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 S231186AbiJXQxP (ORCPT + 99 others); Mon, 24 Oct 2022 12:53:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235335AbiJXQtZ (ORCPT ); Mon, 24 Oct 2022 12:49:25 -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 B48CD65B7; Mon, 24 Oct 2022 08:32:28 -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 CBCA9B81203; Mon, 24 Oct 2022 12:03:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D226C433D6; Mon, 24 Oct 2022 12:03:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613027; bh=ksRKJY5TQUMx/Q1CSvNcnmyPvkMbckLSJ11m16BwXMg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R9T2TNYEwUG4oLRdtWJadhBzfUFM2bwc+RgqNV9OEH/GPRyJhJZl3nsD3CqjWL33p ZVU3f93G2iY6EPSRkXPjRfFNOAvGZS5cZg0qxptXAKbVwMY9drbhSpTn0i3ha3fBKp ptzXbSN5Qyd4bV3gWr46OBPCbDF967t/MZe1FRic= 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 4.19 210/229] power: supply: adp5061: fix out-of-bounds read in adp5061_get_chg_type() Date: Mon, 24 Oct 2022 13:32:09 +0200 Message-Id: <20221024113005.989970320@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112959.085534368@linuxfoundation.org> References: <20221024112959.085534368@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 939fd3d8fb1a..1ad044330599 100644 --- a/drivers/power/supply/adp5061.c +++ b/drivers/power/supply/adp5061.c @@ -428,11 +428,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