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=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 48D00CA9EB9 for ; Sat, 26 Oct 2019 13:33:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 15AFD2070B for ; Sat, 26 Oct 2019 13:33:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572096792; bh=5Lhv8LT6o/uLMEwxxa+2kMua+r7tRmSPQC1uJcqa5Mg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=v9EmYwmqyDLwHa3RVP+k95aBcP/pqcxKXZr6uhEKlDjpf326rjYW9L+fbXsSqqfkL JVfDQzGUCzDThUFndZnk5q5nufohsmQ0s4TfPxpSzUrc9HhjfwwlPWLOdo6zemXTfe G5+PquPeJqdxQ4fdpj6bUISGEx580Yu/VWhQvmx8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728461AbfJZNdK (ORCPT ); Sat, 26 Oct 2019 09:33:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:39802 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727709AbfJZNSK (ORCPT ); Sat, 26 Oct 2019 09:18:10 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0A635214DA; Sat, 26 Oct 2019 13:18:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572095889; bh=5Lhv8LT6o/uLMEwxxa+2kMua+r7tRmSPQC1uJcqa5Mg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zam3vE9VO7X13x60nL+snqv+Ro5LdjKPSR69CQCewXCw2Sw9wPdEbc2et5LrkQp/m bRlUUBhPe+gavvKqSxAgiAbDpECINRjiVAfK9g6KlwNo5T3gjH3LWK03V4COwBFGlK Q8bdabkpaDyq9QRxgYjVXZpDZXfUGXkysB56oCV4= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Pavel Tatashin , James Morse , Will Deacon , Sasha Levin Subject: [PATCH AUTOSEL 5.3 72/99] arm64: hibernate: check pgd table allocation Date: Sat, 26 Oct 2019 09:15:33 -0400 Message-Id: <20191026131600.2507-72-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191026131600.2507-1-sashal@kernel.org> References: <20191026131600.2507-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pavel Tatashin [ Upstream commit 8c551f919a73c1dfa690a70a691be1da394145e8 ] There is a bug in create_safe_exec_page(), when page table is allocated it is not checked that table is allocated successfully: But it is dereferenced in: pgd_none(READ_ONCE(*pgdp)). Check that allocation was successful. Fixes: 82869ac57b5d ("arm64: kernel: Add support for hibernate/suspend-to-disk") Reviewed-by: James Morse Signed-off-by: Pavel Tatashin Signed-off-by: Will Deacon Signed-off-by: Sasha Levin --- arch/arm64/kernel/hibernate.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/hibernate.c b/arch/arm64/kernel/hibernate.c index 9341fcc6e809b..dcbe2f1c8b2e2 100644 --- a/arch/arm64/kernel/hibernate.c +++ b/arch/arm64/kernel/hibernate.c @@ -201,6 +201,7 @@ static int create_safe_exec_page(void *src_start, size_t length, gfp_t mask) { int rc = 0; + pgd_t *trans_pgd; pgd_t *pgdp; pud_t *pudp; pmd_t *pmdp; @@ -215,7 +216,13 @@ static int create_safe_exec_page(void *src_start, size_t length, memcpy((void *)dst, src_start, length); __flush_icache_range(dst, dst + length); - pgdp = pgd_offset_raw(allocator(mask), dst_addr); + trans_pgd = allocator(mask); + if (!trans_pgd) { + rc = -ENOMEM; + goto out; + } + + pgdp = pgd_offset_raw(trans_pgd, dst_addr); if (pgd_none(READ_ONCE(*pgdp))) { pudp = allocator(mask); if (!pudp) { -- 2.20.1