Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp840069pxu; Mon, 23 Nov 2020 05:37:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJzKuHNiZAo0dI2Sb376QiOjaxmV7hNE/NrmWArhNMHFvIyjN5sazjTqT47grQHegfJ7hFLI X-Received: by 2002:a17:906:3153:: with SMTP id e19mr17937176eje.17.1606138630712; Mon, 23 Nov 2020 05:37:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606138630; cv=none; d=google.com; s=arc-20160816; b=aK1eFcNteoiA0fCJq9QXH6B1gbGGoUy3btBrdl5TdcAzvg6b3TlMNa7zsSAanTp6Yk 9pNlXvEiUQDhmXA67sgKKAdJZnhL9/L4r2dyC4rhmeL2C1RZHs09ytNVT8NyYbK+xIG7 /gmaWPkEuEFcDuYO3nixdkfn5+7QtwO/AIXdvMmAaV9UV/2sQs/zH8kQTR93GBOqWXQU q4RkISlvJGospXFm9PZzVxVnH2oD+b82CbSmAG+LEp9pF+jO7nyINbl7kGtLazfJ7v99 xG0tqmKbPUS/CPGlGUxugCEGrEHyc/+nkqZLjD/6DuKW6grd1lIELsC4JO099WKpQZbN 3Htw== 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=Dotxu9ta4LrPc1IAdoD/DvcWoeGzxtnh3Il00uIgb48=; b=UagAF44CHaE0++v4MUqdtShUtR7mJQNFy6KNjWjxCIeqGWig8XB+6+mHZUC1o0gAb/ rRaVo2okvBPI0U8rzcBPtueEAJynzVDCXPCtIKe95+iaZNbYmC0Fdl69xOdN96JF8WxP Sqn5gquRyESSrhqIbVjyGBev1GMck71iUHWaTVzmG9JmKwPI5aqKc6K4IoJNYt9gwXv7 hA6R/y52/g+4mYV22LBbLHZ3MZkAUqMZc/NzXUFfrh4uEPrl5Cv/SJXDp0sXEsEN2iLC EiTokt8eSJXFyPdRwJygrysInI1ZR8VWQ8Il7bL0pvUVIN1gbX0DTqWqm1zT8DSooORq 0Gng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Wo4CIZQF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h11si7001610edn.539.2020.11.23.05.36.46; Mon, 23 Nov 2020 05:37:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Wo4CIZQF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1730035AbgKWMZn (ORCPT + 99 others); Mon, 23 Nov 2020 07:25:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:35148 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729995AbgKWMZ2 (ORCPT ); Mon, 23 Nov 2020 07:25:28 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D49112076E; Mon, 23 Nov 2020 12:25:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606134326; bh=93VrMVYKxpRP0ORf3ecOd7y7hC7tY7W+PyTw58cxmMg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wo4CIZQF9VZiz0zjH+6mNoTGbWT4Q0z03ryhxVb8RtzTk+fbdWI+9rxRCVBr3uxfT Eo528dwvxkviRSwAerq/6u+yhR5axyW8rguagVg0+9ImnVNR8A//CbmMS62s2uYWhO ISOgspe8qOvu7hR32Tc9Pf+XRpojbXM5CjBeyyQI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Naresh Kamboju , Arnd Bergmann , Nishanth Menon , Mark Brown , Sasha Levin Subject: [PATCH 4.9 31/47] regulator: ti-abb: Fix array out of bound read access on the first transition Date: Mon, 23 Nov 2020 13:22:17 +0100 Message-Id: <20201123121807.058405502@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201123121805.530891002@linuxfoundation.org> References: <20201123121805.530891002@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nishanth Menon [ Upstream commit 2ba546ebe0ce2af47833d8912ced9b4a579f13cb ] At the start of driver initialization, we do not know what bias setting the bootloader has configured the system for and we only know for certain the very first time we do a transition. However, since the initial value of the comparison index is -EINVAL, this negative value results in an array out of bound access on the very first transition. Since we don't know what the setting is, we just set the bias configuration as there is nothing to compare against. This prevents the array out of bound access. NOTE: Even though we could use a more relaxed check of "< 0" the only valid values(ignoring cosmic ray induced bitflips) are -EINVAL, 0+. Fixes: 40b1936efebd ("regulator: Introduce TI Adaptive Body Bias(ABB) on-chip LDO driver") Link: https://lore.kernel.org/linux-mm/CA+G9fYuk4imvhyCN7D7T6PMDH6oNp6HDCRiTUKMQ6QXXjBa4ag@mail.gmail.com/ Reported-by: Naresh Kamboju Reviewed-by: Arnd Bergmann Signed-off-by: Nishanth Menon Link: https://lore.kernel.org/r/20201118145009.10492-1-nm@ti.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/regulator/ti-abb-regulator.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/regulator/ti-abb-regulator.c b/drivers/regulator/ti-abb-regulator.c index 6d17357b3a248..5f5f63eb8c762 100644 --- a/drivers/regulator/ti-abb-regulator.c +++ b/drivers/regulator/ti-abb-regulator.c @@ -342,8 +342,17 @@ static int ti_abb_set_voltage_sel(struct regulator_dev *rdev, unsigned sel) return ret; } - /* If data is exactly the same, then just update index, no change */ info = &abb->info[sel]; + /* + * When Linux kernel is starting up, we are'nt sure of the + * Bias configuration that bootloader has configured. + * So, we get to know the actual setting the first time + * we are asked to transition. + */ + if (abb->current_info_idx == -EINVAL) + goto just_set_abb; + + /* If data is exactly the same, then just update index, no change */ oinfo = &abb->info[abb->current_info_idx]; if (!memcmp(info, oinfo, sizeof(*info))) { dev_dbg(dev, "%s: Same data new idx=%d, old idx=%d\n", __func__, @@ -351,6 +360,7 @@ static int ti_abb_set_voltage_sel(struct regulator_dev *rdev, unsigned sel) goto out; } +just_set_abb: ret = ti_abb_set_opp(rdev, abb, info); out: -- 2.27.0