From patchwork Wed Oct 9 18:16:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 175632 Delivered-To: patches@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp1111102ill; Wed, 9 Oct 2019 11:16:41 -0700 (PDT) X-Received: by 2002:a19:ad0c:: with SMTP id t12mr2983878lfc.149.1570645001884; Wed, 09 Oct 2019 11:16:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570645001; cv=none; d=google.com; s=arc-20160816; b=UqeiGJprsInu+7ap+PYOngrSCt5QQkP+YukzLfdCesbOKWZKYaGx2s+oQcl2BVusKx zfwe+pANQWOp75oSu/gngcrFBEuieY83zZMqovs7YklBYps0JHYyxJr8RaWTWZJxqa3k nA8rNQ5vxT6t6ZyM2DBlZS7JPxz+V2khQsWC958xs41pd4lQCCB7+iUL9v03kTdvXNJu HPEaoe2URpeq1MgqYEDBjE63QPUO8dP7eyc8HEKQe1p7j/cY1buLbrXc0fKBAsybZC6/ BTlk0Vrwv+6MMH0vHsqFKptOHvAoA6rx1mgpgjuC3yscefFfhzL54eEa4RTPvpT/JN0m j5eQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature; bh=s32JeDhVlasQJ6pytWlkQPUAMG4/wlRqEgRTpBOYoJM=; b=BSS8ArIPmygE/tONegTWN5pZ0bFrnHNpjEILCLp2aR6UnZ0hygrOboagNRrmtR0BbV iG0UgD7RTnojd6fgA87wPwRQLfhsK7o+IkEfGi2AeP9pWbTQ8/YOZ/zP6p4fcckUI3Uc 02LVfsOHSEeLgVkxHN2uGI7OkrHEybMggoBvGlIoin6sltAPOk3bO9iTU3BVhzTKOE+3 V8PYaP2kF7z3y9HjeSXObtv7q+S0GSBcqkBoLCeCA/Y25H6rBdfPhhIi2WXvt3rRoeC8 19Dp4ZSjS+WPI6q/X8N4M0rHEep9LJBuyvK/fJoTlxARaHB6QiDiojZPHIGM0/aazWoq c2JA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kGFD5Gdl; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id d20sor1873986ljo.18.2019.10.09.11.16.41 for (Google Transport Security); Wed, 09 Oct 2019 11:16:41 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kGFD5Gdl; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=s32JeDhVlasQJ6pytWlkQPUAMG4/wlRqEgRTpBOYoJM=; b=kGFD5Gdl4C8u9owfyNXhb2acQFuwDz+UXa/i0LTXZTEcbdMmh0AjkXF0QMhR+4cMoh XaLzPoP1P9yHpEWRBwQBtxXnN9/OoTnLCaNOvyselGfJG30lA1mfvooZOW4ZcjVHWrda hA34NlpqWban8B3XKZZXTGS6T5NYkgN+ZkUQ90+oRbUPFmCvppGke60q85I1LuUq2ZLM jot3NVT9dEvLTcnxRjL0rU2KxNMl0LKvpMUBLSbvwIrbXyuRPJ4QE1qPIuen7jElm7PU mklEqTwyGxyq/oqf9xoEoHm4rZViyl7vX90D1BDXoi7PyD0LxYxm7V2z90duFy/go7r9 SHtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=s32JeDhVlasQJ6pytWlkQPUAMG4/wlRqEgRTpBOYoJM=; b=LQsFlb0O66dgTyjEtVb7WT2t1Y+xvKWf6FEBS1dG44aukJSgFiT7mft7BHyrEp0an2 8RmIw6kvFtA91eRc5AJVy+50hBO4meNq/kI3qgQBQyG5lBXBkwRkyqaF/ym1Dhs9Tt3g zLJNm3oijpGzdA1R2EqWK5JxasABFxWl6OJ1EeWnPfzatwHtxsz/sDfnsu44RDM4ck/G uEG5rvLYruo6wX/FVspvzM9/N6klG9jCBJEDY1yjlAOe743v8DlgPb77FmG8U/n1M4v+ AWsX0r3aprTgM4It1ZD95vaIb6iDkQI5XafTwvzsY6VggaI/9HpCKSyDMppxhV4jnmCu DgVg== X-Gm-Message-State: APjAAAXmGHenwAQcFdHw8C2cFNZtM7Hz22LakMPEw8JidF1dOQLyvn25 L1BfJ4IY3h6j1tbdlVdzHmAgC1dV X-Google-Smtp-Source: APXvYqypJOmbC04F3ddNDxg3qFWuyfnh+IG/HcNE3wdr5Kwiz9gCv6E8h7Kf7XglrnbPMWUreNn2hw== X-Received: by 2002:a2e:3003:: with SMTP id w3mr3313997ljw.208.1570645001423; Wed, 09 Oct 2019 11:16:41 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id c21sm638710lff.61.2019.10.09.11.16.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2019 11:16:40 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , linux-pm@vger.kernel.org Cc: Lina Iyer , Ulf Hansson , linux-arm-kernel@lists.infradead.org Subject: [PATCH] cpuidle: psci: Fix potential access to unmapped memory Date: Wed, 9 Oct 2019 20:16:29 +0200 Message-Id: <20191009181629.12447-1-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 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(-) -- 2.17.1 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); } static struct cpuidle_driver psci_idle_driver __initdata = {