From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE837CA9EA1 for ; Fri, 18 Oct 2019 09:51:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 93A5A222C5 for ; Fri, 18 Oct 2019 09:51:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ajfJ/X3X" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392484AbfJRJvt (ORCPT ); Fri, 18 Oct 2019 05:51:49 -0400 Received: from mail-vs1-f67.google.com ([209.85.217.67]:35496 "EHLO mail-vs1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728971AbfJRJvt (ORCPT ); Fri, 18 Oct 2019 05:51:49 -0400 Received: by mail-vs1-f67.google.com with SMTP id s7so3635277vsl.2 for ; Fri, 18 Oct 2019 02:51:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=knD6IYh1XTlD/ibBcWNI8K/BimIHANG2UXS26q595lM=; b=ajfJ/X3Xn9ixrvBV5r5b5vdMwo992Y4/lgGjzTZi7bhDn1x3Sb8Meb6nx9MEBrDluM wrhnsG55M0SzjMG4AsohoOtMMJJoL9p6nTpAtsmnQLjNOoZsheONg2DowRT1K493JMbS AcPCbyAW2qjy+PAii2wOQsKFZdkcGbOW3ImYp8HBYWnkDEEqeYubSNKfXGMw+g8MMdgO spHUtMIvhhodOch4AZKB1PpBRQ4Z7rOfrmx1Sml7fiQlIgxA/TpCTFSY6Tvk64HXG41m kQ5PHiNOkVNqKevQXoTaUDcyOW8JcDP2dgYULeJFd9y3SuLWc6fu6WFxljo+kb0wboJl 7aYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=knD6IYh1XTlD/ibBcWNI8K/BimIHANG2UXS26q595lM=; b=HBr+uMTqvqDGblulyoVinxAqeAOPysZ/klaTxSmZ0jnBleRq9HIr8/RWv1I/oQqKZt 7N/s+41zvEPxSgbArvGKZr+uxXYhtub8rqrTS+1Dl1Mgaf4inlL0SZVMUfDAAU7T6Rrq ULRXNiOu0GAExMfQOnv1nlqMxxIZdj8zhNK3SvOfxVqOVVM3zis5eNKJyCzwVs8LB5MY s+/bNmLkBTpwnDJSFa2YmhZe0hcADUD33jLclswvHybiGJnnmRcH1wyNJPQDJgTDrXtq Qh5Kvg6zCCttksZzvn/NXHwPTitYaIZpqfcRex0YmRTcTy8D/JX3chjXe/IqzaKeeBJ9 gJOg== X-Gm-Message-State: APjAAAWROWk8U0/TecMy1e8UuGy0lqTexVV0I18bVfNFID7Elw30vwr7 a2NaWmfNLJyCUCROGli6qcXmwdPQStTfdDPcleopeg== X-Google-Smtp-Source: APXvYqxFUTnsVUqOPYGTlBe0WnXNlxQEuh5mYZupJcL1UOwQvgkbBN4IMB7XRxQVNzi9OdZCe0CRpSW7L61xE1ZxYCo= X-Received: by 2002:a67:ebc2:: with SMTP id y2mr4847513vso.191.1571392308109; Fri, 18 Oct 2019 02:51:48 -0700 (PDT) MIME-Version: 1.0 References: <20191010113937.15962-1-ulf.hansson@linaro.org> <20191010113937.15962-2-ulf.hansson@linaro.org> <20191018093839.GB25918@e121166-lin.cambridge.arm.com> In-Reply-To: <20191018093839.GB25918@e121166-lin.cambridge.arm.com> From: Ulf Hansson Date: Fri, 18 Oct 2019 11:51:11 +0200 Message-ID: Subject: Re: [PATCH 01/13] cpuidle: psci: Fix potential access to unmapped memory To: Lorenzo Pieralisi Cc: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Mark Rutland , Lina Iyer , Linux PM , Rob Herring , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Kevin Hilman , Linux ARM , linux-arm-msm Content-Type: text/plain; charset="UTF-8" Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org On Fri, 18 Oct 2019 at 11:38, Lorenzo Pieralisi wrote: > > On Thu, Oct 10, 2019 at 01:39:25PM +0200, Ulf Hansson wrote: > > When the WFI state have been selected, the in-parameter idx to > > psci_enter_idle_state() is zero. In this case, we must not index the state > > array as "state[idx - 1]", as it means accessing data outside the array. > > Fix the bug by pre-checking if idx is zero. > > > > Fixes: 9ffeb6d08c3a ("PSCI: cpuidle: Refactor CPU suspend power_state parameter handling") > > Signed-off-by: Ulf Hansson > > --- > > drivers/cpuidle/cpuidle-psci.c | 6 +++--- > > 1 file changed, 3 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c > > index f3c1a2396f98..2e91c8d6c211 100644 > > --- a/drivers/cpuidle/cpuidle-psci.c > > +++ b/drivers/cpuidle/cpuidle-psci.c > > @@ -27,10 +27,10 @@ static DEFINE_PER_CPU_READ_MOSTLY(u32 *, psci_power_state); > > static int psci_enter_idle_state(struct cpuidle_device *dev, > > struct cpuidle_driver *drv, int idx) > > { > > - u32 *state = __this_cpu_read(psci_power_state); > > + u32 *states = __this_cpu_read(psci_power_state); > > + u32 state = idx ? states[idx - 1] : 0; > > > > - return CPU_PM_CPU_IDLE_ENTER_PARAM(psci_cpu_suspend_enter, > > - idx, state[idx - 1]); > > + return CPU_PM_CPU_IDLE_ENTER_PARAM(psci_cpu_suspend_enter, idx, state); > > Technically we don't dereference that array entry but I agree this > is ugly and potentially broken. No sure understand the non-deference part. If the governor selects WFI, the idx will be 0 - and thus we end up using state[-1], doesn't that dereference an invalid address, no? > > My preference is aligning it with ACPI code and allocate one more > entry in the psci_power_state array (useless for wfi, agreed but > at least we remove this (-1) handling from the code). I can do that, but sounds like a slightly bigger change. Are you fine if I do that on top, so we can get this sent as fix for v5.4-rc[n]? Kind regards Uffe