From nobody Fri Dec 19 10:36:45 2025 Received: from smtp-fw-9106.amazon.com (smtp-fw-9106.amazon.com [207.171.188.206]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8622181AC8 for ; Mon, 2 Sep 2024 16:34:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=207.171.188.206 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725294869; cv=none; b=pKtbY+44KckwTMXa7kEVxC0+dsfkPB7QdLMnyMJWJyZDdS/jYugWbJU2714gVA3p3qSwnOfyV2rNZxc9PiwFz5/WIgwui+MB1ZhhZBFXVnM7e/ayk9OO24Z8YQp9AqblZMVKuXN7hvBXiJSrj2fYBL/ZvhmJ3DgMJNfBxBU+h0A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725294869; c=relaxed/simple; bh=5jFUTRcDwsdgM2AQVIAoOZ1Pjqai13CYe6ZSY5fIPKs=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=JU8Upq2QCsnyJ0MvK8zbmCN7kSBqTguOrVY1QS1NMeN9l/GHZ32UGHCUJsoWB2PBBlIvy9jboi2dW1E28sKKSX7BW+h1S9Eu7S1qMA3P0H5Ry4Jd+LswVbXk68MakXdEQG0spGp5lID2AsIfvdVj7mEoZJhcxiBN4+MHHifCVsc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.de; spf=pass smtp.mailfrom=amazon.de; dkim=pass (1024-bit key) header.d=amazon.de header.i=@amazon.de header.b=RXXeuqAx; arc=none smtp.client-ip=207.171.188.206 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.de header.i=@amazon.de header.b="RXXeuqAx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1725294868; x=1756830868; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=5jFUTRcDwsdgM2AQVIAoOZ1Pjqai13CYe6ZSY5fIPKs=; b=RXXeuqAxq+DT5vYOzGJLrO3CxW5aAgNw4PuZcNfseC2aacBZjNBNYQFt bkT6CT8EI4qMiOIs4ZJqgDR1EnsI3r+lYgdJFOGA8v0tqqEC+DUg04frR A51UdB5cvvZQgqIuYchdhuPBSQ25RpzdjBshX0NX2ipk0UNYKP0MTiSH5 w=; X-IronPort-AV: E=Sophos;i="6.10,196,1719878400"; d="scan'208";a="755830880" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev) ([10.25.36.210]) by smtp-border-fw-9106.sea19.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Sep 2024 16:34:21 +0000 Received: from EX19MTAEUC002.ant.amazon.com [10.0.17.79:34199] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.37.143:2525] with esmtp (Farcaster) id baa764ee-730a-4b0a-8c81-82279a5d2898; Mon, 2 Sep 2024 16:34:19 +0000 (UTC) X-Farcaster-Flow-ID: baa764ee-730a-4b0a-8c81-82279a5d2898 Received: from EX19D007EUA001.ant.amazon.com (10.252.50.133) by EX19MTAEUC002.ant.amazon.com (10.252.51.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Mon, 2 Sep 2024 16:34:19 +0000 Received: from EX19MTAUEA001.ant.amazon.com (10.252.134.203) by EX19D007EUA001.ant.amazon.com (10.252.50.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.35; Mon, 2 Sep 2024 16:34:18 +0000 Received: from dev-dsk-faresx-1b-27755bf1.eu-west-1.amazon.com (10.253.79.181) by mail-relay.amazon.com (10.252.134.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34 via Frontend Transport; Mon, 2 Sep 2024 16:34:17 +0000 From: Fares Mehanna To: CC: , Fares Mehanna , =?UTF-8?q?Jan=20H=20=2E=20Sch=C3=B6nherr?= , "Catalin Marinas" , Will Deacon , "Andrew Morton" , Ryan Roberts , Mark Rutland , , Subject: [PATCH] arm64: trans_pgd: mark PTEs entries as valid to avoid dead kexec() Date: Mon, 2 Sep 2024 16:33:08 +0000 Message-ID: <20240902163309.97113-1-faresx@amazon.de> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The reasons for PTEs in the kernel direct map to be marked invalid are not limited to kfence / debug pagealloc machinery. In particular, memfd_secret() also steals pages with set_direct_map_invalid_noflush(). When building the transitional page tables for kexec from the current kernel's page tables, those pages need to become regular writable pages, otherwise, if the relocation places kexec segments over such pages, a fault will occur during kexec, leading to host going dark during kexec. This patch addresses the kexec issue by marking any PTE as valid if it is not none. While this fixes the kexec crash, it does not address the security concern that if processes owning secret memory are not terminated before kexec, the secret content will be mapped in the new kernel without being scrubbed. Suggested-by: Jan H. Sch=C3=B6nherr Signed-off-by: Fares Mehanna --- arch/arm64/mm/trans_pgd.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/arm64/mm/trans_pgd.c b/arch/arm64/mm/trans_pgd.c index 5139a28130c0..0f7b484cb2ff 100644 --- a/arch/arm64/mm/trans_pgd.c +++ b/arch/arm64/mm/trans_pgd.c @@ -42,14 +42,16 @@ static void _copy_pte(pte_t *dst_ptep, pte_t *src_ptep,= unsigned long addr) * the temporary mappings we use during restore. */ __set_pte(dst_ptep, pte_mkwrite_novma(pte)); - } else if ((debug_pagealloc_enabled() || - is_kfence_address((void *)addr)) && !pte_none(pte)) { + } else if (!pte_none(pte)) { /* * debug_pagealloc will removed the PTE_VALID bit if * the page isn't in use by the resume kernel. It may have * been in use by the original kernel, in which case we need * to put it back in our copy to do the restore. * + * Other cases include kfence / vmalloc / memfd_secret which + * may call `set_direct_map_invalid_noflush()`. + * * Before marking this entry valid, check the pfn should * be mapped. */ --=20 2.40.1 Amazon Web Services Development Center Germany GmbH Krausenstr. 38 10117 Berlin Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B Sitz: Berlin Ust-ID: DE 365 538 597