From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 7D014390609; Sat, 12 Sep 2026 19:58:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789243090; cv=none; b=GbS/QGhiq6+axtsMLMUPNEb8wzakUBHDj1cYHm6bsUjcbC/0snFhbLuWOSEe482PaXObiPenrNcLrgSuC+d6qsxFw6JkGYidDd7YVG6ZfZKKqp0nOhxUcs9tcIuvrCRYhCRXdBevQaAoQG1Ul9BUlJRowSUNT3w4GrXRBHePsx8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789243090; c=relaxed/simple; bh=ELmqa1jqPi90U/TRdeuZQ0ppF2n/1xtu2mvnlKru4AM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZELh7fsTtOarOTn3VwS0QgnwCsffq/cvUcNeyKM1vN0brwp2W/lgJ8NMPmdbWuYvIFl7qKsV1+qpeY6Hn6liNM5++nvslCF8/BkUVwLE3MPs9xxKHeY4rd5oC7nulW0ykbi0KqA5k+GM6N0xpy9h94wnhNj0MOMk0U+3qfI9u4c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=bwvG2Rw0; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="bwvG2Rw0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6EFD1F000FF; Sat, 12 Sep 2026 19:58:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789243089; bh=i4Dpv30vh5nPCHEm+PA7TWFaPEt6byVNpdGwgJqDNZI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=bwvG2Rw00lvr6I3cYuQ1rQhjGB6GEhuHzZr+oszc8Sa1P1/uNNmEtMwBFDC5rB1HB uIguHUVsXSAaThIPJz06Doijn0D41YKIZtea4r1HPBALEb89fq367NmC1l9N76eHYY K9utJTB2m4SCo6MuyNBmEAaoVBIK4ZLon61n6UhE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ada Couprie Diaz , Vladimir Murzin , Jinjie Ruan , Will Deacon , Sasha Levin Subject: [PATCH 5.10 632/798] arm64: hibernate: mask DAIF before restoring hibernated kernel Date: Sat, 12 Sep 2026 09:04:20 +0200 Message-ID: <20260912065531.609362479@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065516.948645775@linuxfoundation.org> References: <20260912065516.948645775@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ada Couprie Diaz [ Upstream commit 684bde100117931f4c51c644a95f42f2dab041bc ] The arm64 hibernate code manages the exception masking in an unsound way, leading to potential crashes and/or warnings during resume. When a hibernation image is saved in `swsusp_arch_suspend()`, all DAIF exceptions are masked (by virtue of `local_daif_save()`), and the suspended image is saved assuming that all DAIF exceptions will remain masked when the image is restored. When a hibernation image is resumed by `swsusp_arch_resume()`, only interrupts are masked (by virtue of `local_irq_disable()` in `resume_target_kernel()`). When pseudo-NMI is enabled the DAIF.IF bits will be clear, and regardless of pseudo-NMI the DAIF.DA bits will be clear. This means that there are two problems: (1) It is possible to take Debug, SError, or pseudo-NMI exceptions during the resume process. This is unsafe, as during the resume process both the old ane new kernels will tranisently be in an inconsistent state, and swsusp_arch_suspend_exit() won't retain an executable mapping of any exception vectors. Any exception taken here will be fatal and silent. (2) When re-entering the resumed kernel, some DAIF bits will be clear unexpectedly. This permits Debug, SError, or pseudo-NMI exceptions to be taken for a short period while the resumed kernel is not yet in a consistent state. This is detected by CONFIG_ARM64_DEBUG_PRIORITY_MASKING. Avoid these issues by masking all DAIF exceptions during resume. Fixes: 82869ac57b5d ("arm64: kernel: Add support for hibernate/suspend-to-disk") Signed-off-by: Ada Couprie Diaz Signed-off-by: Vladimir Murzin Reviewed-by: Jinjie Ruan Signed-off-by: Will Deacon Signed-off-by: Sasha Levin --- arch/arm64/kernel/hibernate.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arch/arm64/kernel/hibernate.c b/arch/arm64/kernel/hibernate.c index 42003774d261d..3787c123bbd1d 100644 --- a/arch/arm64/kernel/hibernate.c +++ b/arch/arm64/kernel/hibernate.c @@ -706,9 +706,21 @@ int swsusp_arch_resume(void) __hyp_set_vectors(el2_vectors); } + /* + * It is necessary to mask all DAIF exceptions here as: + * + * - The copy of swsusp_arch_suspend_exit() in the hibernation + * text cannot handle taking any exceptions. + * + * - The suspended kernel masked all DAIF exceptions in + * swsusp_arch_resume(), and expects to be re-entered in the + * same state : with all DAIF exceptions masked. + */ + local_daif_save(); hibernate_exit(virt_to_phys(tmp_pg_dir), resume_hdr.ttbr1_el1, resume_hdr.reenter_kernel, restore_pblist, resume_hdr.__hyp_stub_vectors, virt_to_phys(zero_page)); + unreachable(); return 0; } -- 2.53.0