Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp468733yba; Wed, 15 May 2019 04:39:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqyOvDyiTq3DcH70JYB6q9crdGNvJkpNLp17J9d6z/S9ekBaDe9KLEZShMVTBpRt+O2fIuTH X-Received: by 2002:a63:5d3:: with SMTP id 202mr42303525pgf.363.1557920396064; Wed, 15 May 2019 04:39:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557920396; cv=none; d=google.com; s=arc-20160816; b=h+8hFvIn+LkSa9q/H2caMjesQ6P8HWpAXSUUg/wxu7/P2WfZxulRal59QbcsOtLByy V0+Ek2ByhFumL84ltpP/Nzb/F0/XITwEjKfqoJxLzIgr/Psh/3CvPJFAnVrsxxArGsXO qiXFcz8V0PrVrQQYA0nm5yH4x1qaeWqPsgPNeHB3qjQYZoZQLcBVIxuHAn7f5H0loA0v hEVVJN3REcxDQyYq8iBISJXbWUfsGC+ZWf5ue/huzAGDoKz4NMYMdDrqOEd/xMk1LjEM w4W/fQHImaDW+BwFL/EN+bHDmRveqEKEMGCzWDaKSvVk17vjKUMMZOZ3vpNzvsOcbO6Y H7zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=H/Dp9MJGOb64KdNlXy0Q5MTE1vPAd5xoObgWWeWAzBY=; b=mL1jAXGwYiUbjeYc5yK96tcP/ZrTpEWYFREEd2e/P6WbeMcGfcH3B27MmHHYTn56FP e6HYc22ZNdYW3pQ4PdQJOnmiwDrb4UP/g1Khk06DctYDLHUCdIKLuJ+QM+DxGdiiBuju x7R0qQAlOohitem4lLTTW/I1opwdhA7Np5BUjYIN2U1b3FwxGZfkP1oGMfgYXtoPtbqH wYiCSbVPq/HlbVyVQC4JoRU2O4GCdi3B7J0rHfbaKFe7XK5Oxcgzclfobhjg4eXGJAuc dSPQSXCJhbIt1KxCAgTLZwFi2OAvpvdx974ZeNgCvhdqvgbCK/+kC5xprJKm8CApVxbA HDuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FTZMYykB; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j14si1794510pfh.232.2019.05.15.04.39.41; Wed, 15 May 2019 04:39:56 -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=@kernel.org header.s=default header.b=FTZMYykB; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729954AbfEOLcD (ORCPT + 99 others); Wed, 15 May 2019 07:32:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:43824 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732586AbfEOLcB (ORCPT ); Wed, 15 May 2019 07:32:01 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 6EDD5206BF; Wed, 15 May 2019 11:32:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557919920; bh=iiIYaC/w5QturTMJQoyrPh/5aTn9LhWQ1IssuHWRieg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FTZMYykBNKLZzpVxlsvIkAiQoWttloZ9GfpmTTqTvceu0pWJlvkexsX3ZSZzmq+jp 4mAsFksVEDoziM3xZRyzuUK+1UsOw7KPxKYdygmviLxGk6C5Dppon+nM/j7WHYn3Bj NRMuEZAw5+55PFN896tRa1Sj4xQrFft6BLynuqUs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Rick Lindsley , Michael Ellerman Subject: [PATCH 5.0 130/137] powerpc/book3s/64: check for NULL pointer in pgd_alloc() Date: Wed, 15 May 2019 12:56:51 +0200 Message-Id: <20190515090703.319734991@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190515090651.633556783@linuxfoundation.org> References: <20190515090651.633556783@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rick Lindsley commit f39356261c265a0689d7ee568132d516e8b6cecc upstream. When the memset code was added to pgd_alloc(), it failed to consider that kmem_cache_alloc() can return NULL. It's uncommon, but not impossible under heavy memory contention. Example oops: Unable to handle kernel paging request for data at address 0x00000000 Faulting instruction address: 0xc0000000000a4000 Oops: Kernel access of bad area, sig: 11 [#1] LE SMP NR_CPUS=2048 NUMA pSeries CPU: 70 PID: 48471 Comm: entrypoint.sh Kdump: loaded Not tainted 4.14.0-115.6.1.el7a.ppc64le #1 task: c000000334a00000 task.stack: c000000331c00000 NIP: c0000000000a4000 LR: c00000000012f43c CTR: 0000000000000020 REGS: c000000331c039c0 TRAP: 0300 Not tainted (4.14.0-115.6.1.el7a.ppc64le) MSR: 800000010280b033 CR: 44022840 XER: 20040000 CFAR: c000000000008874 DAR: 0000000000000000 DSISR: 42000000 SOFTE: 1 ... NIP [c0000000000a4000] memset+0x68/0x104 LR [c00000000012f43c] mm_init+0x27c/0x2f0 Call Trace: mm_init+0x260/0x2f0 (unreliable) copy_mm+0x11c/0x638 copy_process.isra.28.part.29+0x6fc/0x1080 _do_fork+0xdc/0x4c0 ppc_clone+0x8/0xc Instruction dump: 409e000c b0860000 38c60002 409d000c 90860000 38c60004 78a0d183 78a506a0 7c0903a6 41820034 60000000 60420000 f8860008 f8860010 f8860018 Fixes: fc5c2f4a55a2 ("powerpc/mm/hash64: Zero PGD pages on allocation") Cc: stable@vger.kernel.org # v4.16+ Signed-off-by: Rick Lindsley Signed-off-by: Michael Ellerman Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/include/asm/book3s/64/pgalloc.h | 3 +++ 1 file changed, 3 insertions(+) --- a/arch/powerpc/include/asm/book3s/64/pgalloc.h +++ b/arch/powerpc/include/asm/book3s/64/pgalloc.h @@ -81,6 +81,9 @@ static inline pgd_t *pgd_alloc(struct mm pgd = kmem_cache_alloc(PGT_CACHE(PGD_INDEX_SIZE), pgtable_gfp_flags(mm, GFP_KERNEL)); + if (unlikely(!pgd)) + return pgd; + /* * Don't scan the PGD for pointers, it contains references to PUDs but * those references are not full pointers and so can't be recognised by