From patchwork Mon Oct 24 11:32:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9825 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp555239wru; Mon, 24 Oct 2022 09:59:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4cv/bNldr5eqx9m0J4HtZnx/quHD74vVvmRCx47UgtZt2U5vxt6c+VG3CZ/mn0xW9FZC9z X-Received: by 2002:a17:906:8a46:b0:7a0:b8ee:ac06 with SMTP id gx6-20020a1709068a4600b007a0b8eeac06mr11496899ejc.42.1666630762297; Mon, 24 Oct 2022 09:59:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666630762; cv=none; d=google.com; s=arc-20160816; b=iROVdDkfsfUeC32I190rgrSlT56QiIXmPR7AKDGNxhtCt0Z1FN7jyJq71255Nyvuwa prlSVSS0aOlaDGRHrqpJTcihtR0sWFOPleZrk1+wGe9eCMoHEqL2yiYY5dKyPhfnV1yr UvT+UJmmmUIMRgz9Y4kBVpOvIruLg3+0c0ztQ1vTfWGtHguQkCa0B2CgrKD/7i4YfSBB iQr7n2GigT2bvMREPnuLIShtK7Y2RAzkTheow1g4As92iU9I5kczhXjXLaSsrN/jji/u 5BWOub0KgjCS8MiFi2HWcoEKPHNwP9Pylf8hoWW8whDKbHEDv4aOK/p2s37uGhQM+J7Q wQkg== 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 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.09.58.53; Mon, 24 Oct 2022 09:59:22 -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 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?1747589017975327620?= X-GMAIL-MSGID: =?utf-8?q?1747589017975327620?= 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; }