Received: by 10.213.65.68 with SMTP id h4csp2110041imn; Sun, 8 Apr 2018 19:59:02 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+OBdtCLpvBrVXDNcZYmaLWCqLkDLYzJXAFIQuti3iNc6xR0QmE+KHB8vK/Qusz1+mol5f2 X-Received: by 10.98.174.23 with SMTP id q23mr27940169pff.103.1523242742473; Sun, 08 Apr 2018 19:59:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523242742; cv=none; d=google.com; s=arc-20160816; b=esjbtybaJ1pLYgukN3x4byAJRIWVIL/NtuesgOFSnd8GAypgzCXM1YQelCRBcSt2vk COFQJWFOoOo5jInaqUPyujKx5PhwRRHnfOuOA/m8r0PksEOokv6LrhqvZbleGLwU0K7n f4fY/t7Ftd2vbUz31sSrTnhrrEJh5zTX8aHKdroZR0Sh9WSLziMEMEXHnMRGIHJy2/qZ W9h5aGRWT1HUKxkoUuOqzEz8lHZVmi7+MBv691K2tkT68mhvnXvqpIW/VnMXOS6dqvRh Wv4VXl80Fe469SYszM4V6MASE7ku81PUjF3nxW49R5lSfyFvkOlUdM9E9ShWouBQTKch nxVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=QMHXuAOShMENbz7jC+PGZtdQY926rd1CBzcOZI14zKA=; b=L4Or1whJC/K0oqUihXSxDRMweosWNNux4M7qVaohOqJS94uKceCxbxhUF03Crqn5rv bffP3Vzh9k2WjiPAFp2ojU7SnCrKEeX6ha1lf0TIWnX1xBMibH2yISC1aFaBbUObIliH UYwyDH6Sv/VmlPl6zhsuNfK4aPUGpnOweUmLLhSCoJXDpnCEnS9b7eh3KvtNdVZgSMCN W8XYUaPav+Tt3W36YK9ULFzRN/ky2h3VEgcEdgsBRqxyFP+ok4tNOeAtEbwU61JAY8RI u82BlUlHhMCjjIJcCYWrFc46yKXwjalPLch0Xsdt3eP1Msh3RNZI4x2ix+Jd9WLY6XCg h1mA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=jTRjVRrS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j8-v6si15205992plk.506.2018.04.08.19.58.25; Sun, 08 Apr 2018 19:59:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=jTRjVRrS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755401AbeDICxR (ORCPT + 98 others); Sun, 8 Apr 2018 22:53:17 -0400 Received: from mail-by2nam01on0099.outbound.protection.outlook.com ([104.47.34.99]:2811 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755331AbeDIA02 (ORCPT ); Sun, 8 Apr 2018 20:26:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=QMHXuAOShMENbz7jC+PGZtdQY926rd1CBzcOZI14zKA=; b=jTRjVRrSaOpD4aFIJpwLGOrJmAk/UMoeyFnm3q5+4FiujNmsb3aSMvtX2y44FqY91+Hzr8DZEQTMJwoCUs0CmBHBnxUxyj4lTDrGDfnqTPIoIdzU/xuqbkMVHmL5sx5Cd/abgQawIqFWp/Caw/QZzgcwoXE8Xa9QNfvbgQNlQ9M= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1015.namprd21.prod.outlook.com (52.132.133.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:26:25 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:26:25 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Nicholas Piggin , Michael Ellerman , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 157/161] powerpc/powernv: IMC fix out of bounds memory access at shutdown Thread-Topic: [PATCH AUTOSEL for 4.14 157/161] powerpc/powernv: IMC fix out of bounds memory access at shutdown Thread-Index: AQHTz5jIiUndb9MpO0K2qhDML+3ZKA== Date: Mon, 9 Apr 2018 00:22:03 +0000 Message-ID: <20180409001936.162706-157-alexander.levin@microsoft.com> References: <20180409001936.162706-1-alexander.levin@microsoft.com> In-Reply-To: <20180409001936.162706-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB1015;7:xZ8JkghLDgPDPMMbCZxyokMwJZR94i24hvk2c5jKYkQaoq5bfTfmBx9IsKgzpLEhyt4VdXAcMMri7CB20J1LnwNe17K7t3uTstJ0kqWeNW+uNgpXXrDvAusPo7+6G0CUEhOPjzPgPlaueYDFr8BtK0mJEZNWp/dD0HxULOMYk46oV2vTngruqqI/pprbBkIpX6xjpN4G+uD/GMtArMRVyl6fMh1U12WglDHO/XNwWfbddYTb1KWdh91NfOg4NkBM;20:s6tSAeMt+2KOG52yHAYT1euuo2bec8W3rFyZ1wUCPw4oBRfZYfZjhMw21eShduCj+hddGn1HvfC4w7wn//5uNOGXMv1aXdr1egg7Hl0DVCubHoSttuZU2pOWLTuGCMRx81dv/VoccDxtQwqt4EYbYE6eXITcghI57GpTnMQSI/A= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 5e7c7364-86e1-409e-12be-08d59db087b3 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB1015; x-ms-traffictypediagnostic: DM5PR2101MB1015: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(209352067349851)(85827821059158); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(3231221)(944501327)(52105095)(3002001)(93006095)(93001095)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123560045)(20161123564045)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM5PR2101MB1015;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1015; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(396003)(39860400002)(39380400002)(376002)(346002)(366004)(189003)(199004)(53936002)(4326008)(478600001)(72206003)(3280700002)(2616005)(14454004)(305945005)(5250100002)(3660700001)(2501003)(2900100001)(54906003)(110136005)(86362001)(1076002)(107886003)(6506007)(36756003)(446003)(68736007)(6512007)(7736002)(486006)(2906002)(5660300001)(6436002)(3846002)(86612001)(6486002)(66066001)(11346002)(575784001)(476003)(6666003)(59450400001)(26005)(10090500001)(316002)(22452003)(8676002)(81156014)(81166006)(6116002)(105586002)(99286004)(186003)(106356001)(76176011)(39060400002)(25786009)(97736004)(10290500003)(102836004)(8936002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1015;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: WmOY0PHMJtRgO6heUA0PqVzNiReZ21bsCnHYSqWRr6SM5CJHvYU1tt8YMswTHiBdI1vYcx1T4s+fOOMcKBx3I+0/dIejMdESiYuwilS9pVJ+8IJwpceENIek7P4Zbx8LA10N/uavSeu4qpgkDglociPG30vHJ+d3LLUPZWIcSlu2OqaMJ6AogLMzSV9dAsk0bnZBfeY/6WgDUQXIijoZSsNwiu6AtiEUE1p2rFB2wn3cZ/IwgV+pMR+9gTqCr4o6pg09WJFb3Pxp3vER17MaHQ+c/FjDiswbTcFyKl1e9JoCmp5pUP1w2YeU5gAKOZww+rCrxIyim9SaWCmEqypfO/iobigWAH5ZjO+ankpi3HeTZr3tmDh5a5kkSd+KTU1FqlwndlSqh8ydjFsIfdl9peaQpIdTTQYBUhEuTwrtghQ= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5e7c7364-86e1-409e-12be-08d59db087b3 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:22:03.1748 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1015 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nicholas Piggin [ Upstream commit e7bde88cdb4f0e432398a7d29ca2a15d2c18952a ] The OPAL IMC driver's shutdown handler disables nest PMU counters by walking nodes and taking the first CPU out of their cpumask, which is used to index into the paca (get_hard_smp_processor_id()). This does not always do the right thing, and in particular for CPU-less nodes it returns NR_CPUS and that overruns the paca and dereferences random memory. Fix it by being more careful about checking returned CPU, and only using online CPUs. It's not clear this shutdown code makes sense after commit 885dcd709b ("powerpc/perf: Add nest IMC PMU support"), but this should not make things worse Currently the bug causes us to call OPAL with a junk CPU number. A separate patch in development to change the way pacas are allocated escalates this bug into a crash: Unable to handle kernel paging request for data at address 0x2a21af1eeb00= 0076 Faulting instruction address: 0xc0000000000a5468 Oops: Kernel access of bad area, sig: 11 [#1] ... NIP opal_imc_counters_shutdown+0x148/0x1d0 LR opal_imc_counters_shutdown+0x134/0x1d0 Call Trace: opal_imc_counters_shutdown+0x134/0x1d0 (unreliable) platform_drv_shutdown+0x44/0x60 device_shutdown+0x1f8/0x350 kernel_restart_prepare+0x54/0x70 kernel_restart+0x28/0xc0 SyS_reboot+0x1d0/0x2c0 system_call+0x58/0x6c Signed-off-by: Nicholas Piggin Signed-off-by: Michael Ellerman Signed-off-by: Sasha Levin --- arch/powerpc/platforms/powernv/opal-imc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/platforms/powernv/opal-imc.c b/arch/powerpc/platf= orms/powernv/opal-imc.c index b150f4deaccf..6914b289c86b 100644 --- a/arch/powerpc/platforms/powernv/opal-imc.c +++ b/arch/powerpc/platforms/powernv/opal-imc.c @@ -126,9 +126,11 @@ static void disable_nest_pmu_counters(void) const struct cpumask *l_cpumask; =20 get_online_cpus(); - for_each_online_node(nid) { + for_each_node_with_cpus(nid) { l_cpumask =3D cpumask_of_node(nid); - cpu =3D cpumask_first(l_cpumask); + cpu =3D cpumask_first_and(l_cpumask, cpu_online_mask); + if (cpu >=3D nr_cpu_ids) + continue; opal_imc_counters_stop(OPAL_IMC_COUNTERS_NEST, get_hard_smp_processor_id(cpu)); } --=20 2.15.1