Received: by 10.213.65.68 with SMTP id h4csp2136144imn; Sun, 8 Apr 2018 20:37:25 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/xM2vi35M2JUneX5LLY2KDTmdS5Ipdx0zG4I0md7UKe8jTBEDTNscHJVGma4m4O0yEcgaa X-Received: by 10.98.182.8 with SMTP id j8mr22327006pff.115.1523245045126; Sun, 08 Apr 2018 20:37:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523245045; cv=none; d=google.com; s=arc-20160816; b=jvkCDI7VH6UTRbUSZ+hbIHZfzWvf1TOqN9XZFolpNrCGqaEUsTvQXIff2kMOEV7epC +AfRC8oexH50onZlED2kqWRHxlXUdW+X0Z+0qUADOtq5ceQrj7I7hMBLN3Ixkn3XSIug AkOsbVKZp6c48O6QI3QEGtrhlZ9DQ/M1YA+59FeJvdE3f4DDqtICnY1q/DxGP75B+H5e Ir/f10/47lFtLCqOPHDPcP6yPhXdafbnoMVXrBo4hXKoomiVz93ykC+mWWKb2/+2Nhks wC0/frKEBS0pIIAZI+UeU1S5Lc6Mm7rlwA9s3Z3h2oDwdLkGQ1wh2QZcLzXrwWXtQK/t mQNg== 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=vYgbATmCGzxzKKTJo2/E/zI+alH3p5l+TgQfZcD7WAQ=; b=boaFtzVC4Zbc3d4rbQnLtSdFNnyit4W8nQwlTq0GYGd+lzjRxpm0Vkw7+/BBavA5u5 6E+pL41j7NKSe6gjIUfayNfglnPPp0KohCxXRn7/H0NcCJ1acqQ321HK171pkt/xnuOM GKv+HCPBmL18JGk4FhN/J92T+vjy84kqomCJhCV0neP5C+slj14EGw9F53LBhJRm93if 1qcoIg2J7cx+I7g3vqfvo+8dnN7OGXhaNCSAsJKEXbAZI/rppXzYqtgpjDbmhi445BIu N8seKCZLIO3kUH5fmbAZtRxrW+cy6VCVpNDSJdsHOGZZm8sNi0+xAmfMMvBQtAW4bfDI /otw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=oAbvbDIu; 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 n20si10844299pgc.508.2018.04.08.20.36.48; Sun, 08 Apr 2018 20:37:25 -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=oAbvbDIu; 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 S1754482AbeDIDbw (ORCPT + 99 others); Sun, 8 Apr 2018 23:31:52 -0400 Received: from mail-sn1nam02on0123.outbound.protection.outlook.com ([104.47.36.123]:35872 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754521AbeDIAVx (ORCPT ); Sun, 8 Apr 2018 20:21:53 -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=vYgbATmCGzxzKKTJo2/E/zI+alH3p5l+TgQfZcD7WAQ=; b=oAbvbDIu6BNvSKRQ3MsH9mWBm+eiINo7PcqnFNyf5BmIcUnLYHZvoPnD+c8MBpfLFA8SQxgPNiYR4F7WKB4TlwfK7iIgT12v6jUW0Wj7up/0Ps9Wva9KKgx4Zf7wp0Nggg1zNNUQt5DK1V59L3X0ERh82Y0J0r7IdutNpbbmFNc= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0936.namprd21.prod.outlook.com (52.132.131.166) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.3; Mon, 9 Apr 2018 00:21:51 +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:21:51 +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.15 185/189] powerpc/powernv: IMC fix out of bounds memory access at shutdown Thread-Topic: [PATCH AUTOSEL for 4.15 185/189] powerpc/powernv: IMC fix out of bounds memory access at shutdown Thread-Index: AQHTz5hkrDQC9LZq3U+hUCJ2OTPYAA== Date: Mon, 9 Apr 2018 00:19:14 +0000 Message-ID: <20180409001637.162453-185-alexander.levin@microsoft.com> References: <20180409001637.162453-1-alexander.levin@microsoft.com> In-Reply-To: <20180409001637.162453-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;DM5PR2101MB0936;7:w+UTS5edFrkIuPs1qJgd0OtwT/gT8cybfbCLtTwtKJSSo5lX3FvPisoezO3WJ82gD955Z7hyW6f4BZ0cxnYVtXKEP5zBicmKXaj8AbCgEtgHVyXURo5gMhK6C3bNBlTwPunxCnuk3op1OVi6F+c9AKARUKrygW0aSsLmfiQefhwBYRbMt2wBXIAH+nHYhcGzYRaROVJWrQVYeiqunY/op5B+KgpvlcdXUwd8hV/6eASUuL+hA+gOap5eGdQ0MiKN;20:jJrHbVVPyE9F7gKE6Wo7RaSO87wU3B6PM8sq+ouIqBzbyH/ZeCAk2prmYhREITsLCOPg/6p+ZoS22asn19nlgwl5Si6c51j1QcE/j0CUwF2L5/Ims1/3IPoldfWfkrdEdY8+6eN+bnTX0bDFAVXBFP/N2AzWFF5zjT3+yeZxKLU= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: b36ab66e-e7f5-40f0-effa-08d59dafe417 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0936; x-ms-traffictypediagnostic: DM5PR2101MB0936: 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)(5005006)(8121501046)(93006095)(93001095)(3231221)(944501327)(52105095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123560045)(20161123564045)(20161123562045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM5PR2101MB0936;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0936; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(39380400002)(39860400002)(396003)(376002)(366004)(199004)(189003)(3660700001)(36756003)(2501003)(76176011)(10290500003)(2616005)(5250100002)(3280700002)(478600001)(1076002)(72206003)(6436002)(53936002)(486006)(476003)(4326008)(6486002)(107886003)(5660300001)(54906003)(110136005)(102836004)(2906002)(6116002)(575784001)(3846002)(86612001)(81156014)(81166006)(6666003)(8936002)(305945005)(8676002)(2900100001)(6506007)(68736007)(14454004)(106356001)(105586002)(25786009)(6512007)(86362001)(99286004)(446003)(59450400001)(10090500001)(11346002)(39060400002)(316002)(26005)(7736002)(66066001)(186003)(22452003)(97736004)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0936;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: F3MzrRs5F9BZiBjUn7kK2tKLEXS2qZZ9Fbm5nxAsXHd1HJdfYDjJWqg/HwTbt5RTfny1Kxo3WyKxPU2zGgVT5HEXRXGmKM5y8tiW+tDyhB0rnbEtSxrCloeJXQaFRSYWGRgVdaxxWc95+7osm1R/AaK7XQARRrGQRF9We5/Q4fMjobgmhtrsy04Ryd2cwcKTCdE6kkSxfzMV+TFCN+f5xo+9i9/P5BrlnljbrzPBYd3o47brfMAREgTnb7Qc5lUavpsH5pQ9T6SPbVazT4WvKKayguZMCa6QKxJQRKHDeDxrpD4LVSNcNsCYOKhdlms6u0zPywYcRW9ifFFQg/QN9ALcYX+O2xQuHYZ4FKtjw8ufYIPPkgUFgBBkF/AtZ93RZ0l5PblVuRGRSoVfjFaR+G3GqzqC456dm4ZF9i6EJJw= 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: b36ab66e-e7f5-40f0-effa-08d59dafe417 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:19:14.8924 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0936 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 465ea105b771..5f27854b57aa 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