Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1999771imm; Thu, 24 May 2018 04:17:19 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpBOEjYCGEFqKLAePDWuDTCV59W5vt7iTHDCvbpZiNoGjGyGlScXc0Fb+IHi0tjeDGJOVVa X-Received: by 2002:a17:902:294a:: with SMTP id g68-v6mr6991949plb.110.1527160639668; Thu, 24 May 2018 04:17:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527160639; cv=none; d=google.com; s=arc-20160816; b=jPgsuSTAUjGn0qefh3i8X9VIG9NUcs1ABPEpbJbWXTt/xhhuKQMKGjFlvLAA5nRM3O dgY0kMlpcmreoLWd5TSdVI9Xt0llwSXdDAtKGvX2C6x2Rv5ju7ezF7Ux2MYxi9X7QqNF DPpx8uHlXCImzxWK6vuJt4+8O/ZwYr03yA26t7h04gnJOiKLki5R1Xutrr44YwM7W+n/ 1ZZI4SKMPgP3tnHEECmUfAB8by55s76fma5jeACvvF/TVn3AYUMfth8+pBl9G9pHSwr0 UFv0dU71nDU8+KTfrLdQ/wFacriizVQvVnMGnkeQX9SWNwoAVAoLXxV+9qOsaGgyH1RG GKRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=DaM3Zb8mlTt1S+URjBDVF+OYNS2PaJIxkau20JpjYcs=; b=nyYD/BnPI8ji1PT4475nqvooqAwFB1Ja79b2iNO36uIM56PXIACsq15PaN7hpuclDF eKc7KcXlU2ZXs4+bMED2KE13ColttX4UJFWjEGeFMdecXup7y1fgMtpkhvg69MJIqryK JgrOOpkdWQi6MDk354Cv9TUgwxlczC19Zbpi0AFrOFvx8K9fugeiugWwxf2nPpvQFfKd G/ue4Qn4ndjnwHGSeLBwSONA/p4NeUhgC7mQv1m91qWe6Xr4EeTBnUhwitWAn6UcQ6ak wxqT7zTnUU4Ln+lcdHVKKXti9xGbgasfVnLpUxK8U9OhecULf8jzRGXVWdg7b1Tr8nSW ENfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CXtfKLAO; 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 70-v6si21996539pfu.274.2018.05.24.04.17.05; Thu, 24 May 2018 04:17:19 -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=CXtfKLAO; 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 S1032958AbeEXLQe (ORCPT + 99 others); Thu, 24 May 2018 07:16:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:59956 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S968042AbeEXJxc (ORCPT ); Thu, 24 May 2018 05:53:32 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (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 1738A20892; Thu, 24 May 2018 09:53:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155611; bh=JPuGBNUbF5ZNfftcO+V+AAU4OVucnYe7Wn7sq3fhWsE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CXtfKLAODhmVbIYRSOnrA6HiJRN+Us4K77fFmWs4ehD91NX6UIRForswnPo5W/QRP hvTJb+aAzo1i1i237HDXgB6fHIOHAA5KsR+96eCxfFelTSNlZvCJvbjb1Yv6e1ZUeP 9HmNFKwyxYLtOun6Aa6bsDWSZJ2+ni8Q+gXES5Ks= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot , Tetsuo Handa , Thomas Gleixner , Baoquan He , thomas.lendacky@amd.com, prudo@linux.vnet.ibm.com, Huang Ying , syzkaller-bugs@googlegroups.com, takahiro.akashi@linaro.org, "H. Peter Anvin" , akpm@linux-foundation.org, dyoung@redhat.com, kirill.shutemov@linux.intel.com Subject: [PATCH 4.14 053/165] x86/kexec: Avoid double free_page() upon do_kexec_load() failure Date: Thu, 24 May 2018 11:37:39 +0200 Message-Id: <20180524093624.166953658@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093621.979359379@linuxfoundation.org> References: <20180524093621.979359379@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tetsuo Handa commit a466ef76b815b86748d9870ef2a430af7b39c710 upstream. >From ff82bedd3e12f0d3353282054ae48c3bd8c72012 Mon Sep 17 00:00:00 2001 From: Tetsuo Handa Date: Wed, 9 May 2018 12:12:39 +0900 Subject: [PATCH 4.14 053/165] x86/kexec: Avoid double free_page() upon do_kexec_load() failure syzbot is reporting crashes after memory allocation failure inside do_kexec_load() [1]. This is because free_transition_pgtable() is called by both init_transition_pgtable() and machine_kexec_cleanup() when memory allocation failed inside init_transition_pgtable(). Regarding 32bit code, machine_kexec_free_page_tables() is called by both machine_kexec_alloc_page_tables() and machine_kexec_cleanup() when memory allocation failed inside machine_kexec_alloc_page_tables(). Fix this by leaving the error handling to machine_kexec_cleanup() (and optionally setting NULL after free_page()). [1] https://syzkaller.appspot.com/bug?id=91e52396168cf2bdd572fe1e1bc0bc645c1c6b40 Fixes: f5deb79679af6eb4 ("x86: kexec: Use one page table in x86_64 machine_kexec") Fixes: 92be3d6bdf2cb349 ("kexec/i386: allocate page table pages dynamically") Reported-by: syzbot Signed-off-by: Tetsuo Handa Signed-off-by: Thomas Gleixner Acked-by: Baoquan He Cc: thomas.lendacky@amd.com Cc: prudo@linux.vnet.ibm.com Cc: Huang Ying Cc: syzkaller-bugs@googlegroups.com Cc: takahiro.akashi@linaro.org Cc: H. Peter Anvin Cc: akpm@linux-foundation.org Cc: dyoung@redhat.com Cc: kirill.shutemov@linux.intel.com Link: https://lkml.kernel.org/r/201805091942.DGG12448.tMFVFSJFQOOLHO@I-love.SAKURA.ne.jp Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/machine_kexec_32.c | 6 +++++- arch/x86/kernel/machine_kexec_64.c | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) --- a/arch/x86/kernel/machine_kexec_32.c +++ b/arch/x86/kernel/machine_kexec_32.c @@ -57,12 +57,17 @@ static void load_segments(void) static void machine_kexec_free_page_tables(struct kimage *image) { free_page((unsigned long)image->arch.pgd); + image->arch.pgd = NULL; #ifdef CONFIG_X86_PAE free_page((unsigned long)image->arch.pmd0); + image->arch.pmd0 = NULL; free_page((unsigned long)image->arch.pmd1); + image->arch.pmd1 = NULL; #endif free_page((unsigned long)image->arch.pte0); + image->arch.pte0 = NULL; free_page((unsigned long)image->arch.pte1); + image->arch.pte1 = NULL; } static int machine_kexec_alloc_page_tables(struct kimage *image) @@ -79,7 +84,6 @@ static int machine_kexec_alloc_page_tabl !image->arch.pmd0 || !image->arch.pmd1 || #endif !image->arch.pte0 || !image->arch.pte1) { - machine_kexec_free_page_tables(image); return -ENOMEM; } return 0; --- a/arch/x86/kernel/machine_kexec_64.c +++ b/arch/x86/kernel/machine_kexec_64.c @@ -38,9 +38,13 @@ static struct kexec_file_ops *kexec_file static void free_transition_pgtable(struct kimage *image) { free_page((unsigned long)image->arch.p4d); + image->arch.p4d = NULL; free_page((unsigned long)image->arch.pud); + image->arch.pud = NULL; free_page((unsigned long)image->arch.pmd); + image->arch.pmd = NULL; free_page((unsigned long)image->arch.pte); + image->arch.pte = NULL; } static int init_transition_pgtable(struct kimage *image, pgd_t *pgd) @@ -90,7 +94,6 @@ static int init_transition_pgtable(struc set_pte(pte, pfn_pte(paddr >> PAGE_SHIFT, PAGE_KERNEL_EXEC_NOENC)); return 0; err: - free_transition_pgtable(image); return result; }