From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793214808; b=5pdrxvDqx86XlDA+mS9q5f71dhPRLaewWMdBtxALaH3XuNNkCL+RtEljkIfA85o0fEHo GU2IoyTVysVBsKmftbKQ1tcCxZ49I0W5Keb5zrJLzBlbCrAuo/vQyhe7HAElwYKMNcDRu hoMUm8BwF6DCpbrQoFVNrctteeSB8zdn7csS2KGdFuO3kUgIApScPboDIX5r8VnLFerNE NlTd2JASOJ3gNDBc+PU6b/FdDVm1W5mPzfqCCi/LaSCotxEUqgv80NjN7zXQxQvB0ifDy OEurtqoZ13DVh2Tk3Jukw2sriQeeYCD6YL8w5ZB+rYZBp4fX4h4xN19GRXMLEf4L3nQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793214808; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=pqDQXdboVbu9YezszE39zNPWCCsMkzs02zo1n/IoTgw=; b=Bi8Sv2bjGRA3MZuqEGV/TJ1+tDWj+YNz/a5uCNIc1wWdLV46wA4iF2P0jT9gh+skpooz swGWM7lcVSOzyxyTDUGGZ5DPfj1eFNf5JlGtZrtzoUiYBnPgmvoqL6umQN2gVUQtuhAWo mULJUpTDoIRNcED+h2GR08G8vaI0rOdDIoQN35k2nBV2kPxYan4hQtX81Mn/zuTHt4RQm dNPwCsF9gQkqDjqc8cIVPZ+/FNYqCrksS7HnkVJP407no7yX/dVQNXwdh99PNle42ZdLf ChpNxMHooHbV4wC+S/AZXijSBrHMDKCUf/oLWIrxIJu68B1sOZ+Fg+5Lelc/pW2sDbw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=zpksx5BM; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BEB9F606A31C; Wed, 28 Oct 2026 19:13:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=zpksx5BM Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB5F41F031E2; Wed, 28 Oct 2026 19:13:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1793214807; bh=pqDQXdboVbu9YezszE39zNPWCCsMkzs02zo1n/IoTgw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=zpksx5BMH4hOx7WoXaYAJC94SOPtTuZaH9HUXWJ9KPgJcJTCvZs/QE+1XM7oCrCX1 V8ChKewwkn5J1BhclHpRZGJf4xqWFjbCNIK4UqmUZ3NpueeyZ0vdxiVRGxzzRkjY82 LkuLpJF7FDtZ2uYZGboPE/BheMTOj4GQwt3z5Eyc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Harshit Mogalapalli , Mimi Zohar , Alexander Graf , Ard Biesheuvel , Borislav Betkov , guoweikang , Henry Willard , "H. Peter Anvin" , Ingo Molnar , Jiri Bohac , Joel Granados , Jonathan McDowell , Mike Rapoport , Paul Webb , Sohil Mehta , Sourabh Jain , Thomas Gleinxer , Yifei Liu , Baoquan He , Andrew Morton , Sasha Levin Subject: [PATCH 6.1 0987/1887] ima: verify the previous kernels IMA buffer lies in addressable RAM Date: Wed, 28 Oct 2026 17:51:23 +0100 Message-ID: <20261028170521.871825335@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261028170459.200466217@linuxfoundation.org> References: <20261028170459.200466217@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Harshit Mogalapalli [ Upstream commit 10d1c75ed4382a8e79874379caa2ead8952734f9 ] Patch series "Address page fault in ima_restore_measurement_list()", v3. When the second-stage kernel is booted via kexec with a limiting command line such as "mem=" we observe a pafe fault that happens. BUG: unable to handle page fault for address: ffff97793ff47000 RIP: ima_restore_measurement_list+0xdc/0x45a #PF: error_code(0x0000) not-present page This happens on x86_64 only, as this is already fixed in aarch64 in commit: cbf9c4b9617b ("of: check previous kernel's ima-kexec-buffer against memory bounds") This patch (of 3): When the second-stage kernel is booted with a limiting command line (e.g. "mem="), the IMA measurement buffer handed over from the previous kernel may fall outside the addressable RAM of the new kernel. Accessing such a buffer can fault during early restore. Introduce a small generic helper, ima_validate_range(), which verifies that a physical [start, end] range for the previous-kernel IMA buffer lies within addressable memory: - On x86, use pfn_range_is_mapped(). - On OF based architectures, use page_is_ram(). Link: https://lkml.kernel.org/r/20251231061609.907170-1-harshit.m.mogalapalli@oracle.com Link: https://lkml.kernel.org/r/20251231061609.907170-2-harshit.m.mogalapalli@oracle.com Signed-off-by: Harshit Mogalapalli Reviewed-by: Mimi Zohar Cc: Alexander Graf Cc: Ard Biesheuvel Cc: Borislav Betkov Cc: guoweikang Cc: Henry Willard Cc: "H. Peter Anvin" Cc: Ingo Molnar Cc: Jiri Bohac Cc: Joel Granados Cc: Jonathan McDowell Cc: Mike Rapoport Cc: Paul Webb Cc: Sohil Mehta Cc: Sourabh Jain Cc: Thomas Gleinxer Cc: Yifei Liu Cc: Baoquan He Cc: Signed-off-by: Andrew Morton Signed-off-by: Sasha Levin --- include/linux/ima.h | 1 + security/integrity/ima/ima_kexec.c | 35 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/linux/ima.h b/include/linux/ima.h index 83ddee788583e..21f442c3fa887 100644 --- a/include/linux/ima.h +++ b/include/linux/ima.h @@ -145,6 +145,7 @@ static inline int ima_measure_critical_data(const char *event_label, #ifdef CONFIG_HAVE_IMA_KEXEC int __init ima_free_kexec_buffer(void); int __init ima_get_kexec_buffer(void **addr, size_t *size); +int ima_validate_range(phys_addr_t phys, size_t size); #endif #ifdef CONFIG_IMA_SECURE_AND_OR_TRUSTED_BOOT diff --git a/security/integrity/ima/ima_kexec.c b/security/integrity/ima/ima_kexec.c index 419dc405c8310..9a63c9a327d48 100644 --- a/security/integrity/ima/ima_kexec.c +++ b/security/integrity/ima/ima_kexec.c @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include "ima.h" #ifdef CONFIG_IMA_KEXEC @@ -164,3 +166,36 @@ void __init ima_load_kexec_buffer(void) pr_debug("Error restoring the measurement list: %d\n", rc); } } + +/* + * ima_validate_range - verify a physical buffer lies in addressable RAM + * @phys: physical start address of the buffer from previous kernel + * @size: size of the buffer + * + * On success return 0. On failure returns -EINVAL so callers can skip + * restoring. + */ +int ima_validate_range(phys_addr_t phys, size_t size) +{ + unsigned long start_pfn, end_pfn; + phys_addr_t end_phys; + + if (check_add_overflow(phys, (phys_addr_t)size - 1, &end_phys)) + return -EINVAL; + + start_pfn = PHYS_PFN(phys); + end_pfn = PHYS_PFN(end_phys); + +#ifdef CONFIG_X86 + if (!pfn_range_is_mapped(start_pfn, end_pfn)) +#else + if (!page_is_ram(start_pfn) || !page_is_ram(end_pfn)) +#endif + { + pr_warn("IMA: previous kernel measurement buffer %pa (size 0x%zx) lies outside available memory\n", + &phys, size); + return -EINVAL; + } + + return 0; +} -- 2.53.0