From patchwork Fri Jan 24 09:32:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 232881 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=-9.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, 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 4E85BC2D0DB for ; Fri, 24 Jan 2020 11:34:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 251EE21734 for ; Fri, 24 Jan 2020 11:34:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579865674; bh=csRWAztyFgtKu6hrVl88CS566rdxacTIQKhsD+jkpHU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=0tX5Kf45H5CWWp+I35xi43oKwXhzuMfBjrNrNw+rakFcEDZIjZl2X1FIGaQv12D3+ YD4Zj0ekwi/Y9Xi12dWXgAaYJRkjfc5/xsdGeT9T0yZb4GTTV35TXlhOLeARlhCses 2lU5Egp8rJSsG2e+9bl7/NAgTGMHyyy4PGk0fItI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404411AbgAXLec (ORCPT ); Fri, 24 Jan 2020 06:34:32 -0500 Received: from mail.kernel.org ([198.145.29.99]:54404 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390190AbgAXLec (ORCPT ); Fri, 24 Jan 2020 06:34:32 -0500 Received: from localhost (ip-213-127-102-57.ip.prioritytelecom.net [213.127.102.57]) (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 D0BD6214DB; Fri, 24 Jan 2020 11:34:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579865671; bh=csRWAztyFgtKu6hrVl88CS566rdxacTIQKhsD+jkpHU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YRzX2G7tzCC5+mfXhHg9ygP4OpFyZmRaOoa3JWDSscVgoeRkL6MwlW41JBtoncvBY T/L4x01G1GPsFZYzlmWVkzRoV0x44sVe/AiQD2UjO3Jtotz8YfqVjRM+AIAFS+185g tPqlrJA1IPsutn87BhLd8cdcsgoE5AUL8aKVrFiA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, James Morse , Pavel Tatashin , Will Deacon , Sasha Levin Subject: [PATCH 4.19 608/639] arm64: hibernate: check pgd table allocation Date: Fri, 24 Jan 2020 10:32:58 +0100 Message-Id: <20200124093205.638785890@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200124093047.008739095@linuxfoundation.org> References: <20200124093047.008739095@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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 9859e1178e6be..dbeeeffdb9c9e 100644 --- a/arch/arm64/kernel/hibernate.c +++ b/arch/arm64/kernel/hibernate.c @@ -202,6 +202,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; @@ -216,7 +217,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) {