From patchwork Wed Jul 25 15:48:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 10544233 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A72E01822 for ; Wed, 25 Jul 2018 15:48:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 938182A562 for ; Wed, 25 Jul 2018 15:48:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 84DEC2A572; Wed, 25 Jul 2018 15:48:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1789D2A570 for ; Wed, 25 Jul 2018 15:48:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C7A0E6B000A; Wed, 25 Jul 2018 11:48:23 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B31216B026A; Wed, 25 Jul 2018 11:48:23 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9FA336B026D; Wed, 25 Jul 2018 11:48:23 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by kanga.kvack.org (Postfix) with ESMTP id 3F6EF6B000A for ; Wed, 25 Jul 2018 11:48:23 -0400 (EDT) Received: by mail-ed1-f69.google.com with SMTP id r9-v6so3276194edh.14 for ; Wed, 25 Jul 2018 08:48:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=TajgHOneCvhrI3d9Y/ncht+jMZd+KF8cRr7CIcYW0zo=; b=UJHydq4/r3TCwpAlzy9O/PkJQPNBFbxYMybwp1Lk6oxeD6DLJCf2mQfPeduqu6kFqI 0LC0UCImLEVdKtDC21vMIuOB/Bw16CQTXsXIM8c5aZaYIA4m4Q4URmKITqZLjEccAvjq 9KpSOESAH5Kfh2N15PBeQcCEP/Iind4hTHES3IK/wnDsP+GcnChjd4Lh4foqav972aG2 M4xxiCuIUUCZXqYjYuyMfD5uAEO+GSUpsVqnKBnT3Wd7R/i/xM0mBGdroLflZPJH4M6O 6stUxgYU0YJnsGnpqGnSyHfR9RU9uAwVX/aGluKNu5MJEKRmpthY+1M6NQUhvTQcS/Yo IRow== X-Gm-Message-State: AOUpUlFhwysFYIlhKqCXQ1Ox2vrFHV7K5T+nUK8SKZ9nHiRhIhoHefya 0w04oLxsS0XIITY4EgPqnKa6Go+HC+0efWDKVNvvd+01KbqgTvdM6BI4G1eMfOoJAm/vULe1Afa GoEXTCfjg065zXubCV7FEXPQjofthBMrPKnXiZpFdkHsa2WzIHe9lbo/RTAFTm8XYlQ== X-Received: by 2002:a50:f18c:: with SMTP id x12-v6mr24076961edl.59.1532533702817; Wed, 25 Jul 2018 08:48:22 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcz3UhH9Ofy0FmmmifLWftKhFXVWHENl+SZmh6h/N74gkW0+JHE2bMTykbUxPkrKesK8nBA X-Received: by 2002:a50:f18c:: with SMTP id x12-v6mr24076922edl.59.1532533702118; Wed, 25 Jul 2018 08:48:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532533702; cv=none; d=google.com; s=arc-20160816; b=otHgXV3/e7jFqovJfC3uzPGVjQCrFdU6JbFqqJ+ldB9Vut92LSE0IBEESOat4oLS38 GHfRGu1XaNwRWT2MPAQRnpRR2YOt3giisP5F5eJdv1N93Cc6zqSEXsUenlAJFDkb4QlD H0N+vd6ivtoBt0P38H6sEYtatKcdxk/MT4E7fTBTTsSDn+FtfUALMaFcktEOLdKBP7ja 7sUs5bGkA0rTuxTnH66cSaaI/g+nQGAsT32AVB/ZKE8c+8O8oOjbl6VqwgGva1E0gp8d IKQ0dxcTW3jaaD+POY/RikogMVRS1jqe6uYFQLIewrzyeFhk+qB83sOaL0GWaRCCxaXE 0dkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=TajgHOneCvhrI3d9Y/ncht+jMZd+KF8cRr7CIcYW0zo=; b=eti+bQt7jXhaaIQ1yznofERvVNnmZSGhcUyDQdbxllgGy/PKOAA+mFY+4oSODJGZRp 9jknO2sGAnrj3Ahld0u/fNYoUTKaiPRIqPLCejcUwNeeJIDKu/CDenT1RSE2ZJ2JZnvo a4Rt1lI7CazZsWxpuPBqPDdcfByYW6y/ug1G9fhfUEC3iWnrKxxv0Km4t4jwlZsYyz3q fynUkvvjFtA1aegF+ZGzGKyAhYeUtZITUiTVyj5Bgouh1zrg3x2uN3IvhsShuj3GViiW iX7dw8BU/dCIvx19Ft5SdLz/hxrxShOClKOdKmRLcH3otYIUdjFGwtV4POrPZP7v/ao/ nbYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@8bytes.org header.s=mail-1 header.b=jWvJ76oN; spf=pass (google.com: domain of joro@8bytes.org designates 81.169.241.247 as permitted sender) smtp.mailfrom=joro@8bytes.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: from theia.8bytes.org (8bytes.org. [81.169.241.247]) by mx.google.com with ESMTPS id f20-v6si4976447eda.234.2018.07.25.08.48.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Jul 2018 08:48:22 -0700 (PDT) Received-SPF: pass (google.com: domain of joro@8bytes.org designates 81.169.241.247 as permitted sender) client-ip=81.169.241.247; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@8bytes.org header.s=mail-1 header.b=jWvJ76oN; spf=pass (google.com: domain of joro@8bytes.org designates 81.169.241.247 as permitted sender) smtp.mailfrom=joro@8bytes.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: by theia.8bytes.org (Postfix, from userid 1000) id D9F372DF; Wed, 25 Jul 2018 17:48:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=8bytes.org; s=mail-1; t=1532533699; bh=7uyJQGX9MH9cxdB/eSz9dqZtNfQZQYIzfaEbxYSk570=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jWvJ76oNSjsoIEonhak0wCu79+mD3+lH8iEegZ2evNmKO+cqf2NAIgHNfcKAMaf/a MwEA8Nmk4a36mKs1n/PTDVMNm2lbnbqUzO8yVgmf5QPOFm/saH6ykWhxrPA1/ua4rQ jcfBBfX4noPHzUHxiqVdpkXt3zjYVsmYMFnvcPNkVJbkqpPIDyC98hRITyAH2mvxhX Dz8rmMkMDrQGy2YlBi05whtLt7MmvrCzvXCkNig/FKr5J0XFZ6B8xWjhcAFraBcj9l 9QaqO1QXQT/Ghrq9msDwWKdx4gjaCnXVe+LKKXJ3G2xG+JjaZmiVNAdnEC2ReocCF4 0xZCnx2vRRXpw== From: Joerg Roedel To: Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" Cc: x86@kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Linus Torvalds , Andy Lutomirski , Dave Hansen , Josh Poimboeuf , Juergen Gross , Peter Zijlstra , Borislav Petkov , Jiri Kosina , Boris Ostrovsky , Brian Gerst , David Laight , Denys Vlasenko , Eduardo Valentin , Greg KH , Will Deacon , aliguori@amazon.com, daniel.gruss@iaik.tugraz.at, hughd@google.com, keescook@google.com, Andrea Arcangeli , Waiman Long , Pavel Machek , "David H . Gutteridge" , jroedel@suse.de, Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Namhyung Kim , joro@8bytes.org Subject: [PATCH 3/3] x86/kexec: Allocate 8k PGDs for PTI Date: Wed, 25 Jul 2018 17:48:03 +0200 Message-Id: <1532533683-5988-4-git-send-email-joro@8bytes.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1532533683-5988-1-git-send-email-joro@8bytes.org> References: <1532533683-5988-1-git-send-email-joro@8bytes.org> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Joerg Roedel Fuzzing the PTI-x86-32 code with trinity showed unhandled kernel paging request oops-messages that looked a lot like silent data corruption. Lot's of debugging and testing lead to the kexec-32bit code, which is still allocating 4k PGDs when PTI is enabled. But since it uses native_set_pud() to build the page-table, it will unevitably call into __pti_set_user_pgtbl(), which writes beyond the allocated 4k page. Use PGD_ALLOCATION_ORDER to allocate PGDs in the kexec code to fix the issue. Signed-off-by: Joerg Roedel --- arch/x86/kernel/machine_kexec_32.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c index d1ab07e..5409c28 100644 --- a/arch/x86/kernel/machine_kexec_32.c +++ b/arch/x86/kernel/machine_kexec_32.c @@ -56,7 +56,7 @@ static void load_segments(void) static void machine_kexec_free_page_tables(struct kimage *image) { - free_page((unsigned long)image->arch.pgd); + free_pages((unsigned long)image->arch.pgd, PGD_ALLOCATION_ORDER); image->arch.pgd = NULL; #ifdef CONFIG_X86_PAE free_page((unsigned long)image->arch.pmd0); @@ -72,7 +72,8 @@ static void machine_kexec_free_page_tables(struct kimage *image) static int machine_kexec_alloc_page_tables(struct kimage *image) { - image->arch.pgd = (pgd_t *)get_zeroed_page(GFP_KERNEL); + image->arch.pgd = (pgd_t *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, + PGD_ALLOCATION_ORDER); #ifdef CONFIG_X86_PAE image->arch.pmd0 = (pmd_t *)get_zeroed_page(GFP_KERNEL); image->arch.pmd1 = (pmd_t *)get_zeroed_page(GFP_KERNEL);