From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 19421409EEE; Sat, 28 Feb 2026 17:44:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772300658; cv=none; b=px4QbyqNWvsfQllQj6TvaJZ8qRQjLy18rqkUCXe3wMyLLuY+f6v44vqOW8G7mHgjgHHE6aadfcNnAZRr0xN2JZzpFFXcKC1VppDRFGXl9faG3us09j2wsFeYi+TLyvwnBZBvuvKFA3/7NCvuy1t0XJZC4Y0O/GvOdutJvUhlRfA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772300658; c=relaxed/simple; bh=NG6KsHGhCYCyBAMOLAxtK7Ymu497bdXMUaieBzxkmTo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YzonH9mgtvuirZ47spfGSHms+iL2rpzTnwGMbrcW67tZhdsKFdajzBheEhfcxNYuAd8hW4VzeVzJBkx0aP/A8nR1EP78h+exXuMJiiN/mqgAww3Z4NWCxI2J+uLevLhB/WTVYQrWPCc2m3UhHgBQPksGhQnLEywyi+9ldBefV/M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iqicOfpq; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iqicOfpq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C8AACC116D0; Sat, 28 Feb 2026 17:44:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772300658; bh=NG6KsHGhCYCyBAMOLAxtK7Ymu497bdXMUaieBzxkmTo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iqicOfpq0RpC3NC8EhxPRqunMDybiIdJ2zGbrnDf2zzsTmyNjAKvx5OrtFQq+TOdU M2J7B29bEwk4xiv7CsZ7tV9L9+nc4rIF5LWWTv1/ISslpLR3J33CVSemrkWFJhsu9m w63clPtkAtWOYNH+dVK7kPVGYxT66MpezR7tcpBB6nQ2jjoFx/sfVyH5IXpnZte6f0 YG9PtXw1exS35yQn0i4KVi1E5KhlOl24psAI+68dFgbCl0zbB5GtFKydfq3ZZNidpz cuTr4id2ekihfXy4qA8P7tqSkMEHLB/k0bMwmmEdmLTa+WWklJ3OruubxnyPCMyORA THu0IHNF47JMw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: 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.19 698/844] ima: verify the previous kernel's IMA buffer lies in addressable RAM Date: Sat, 28 Feb 2026 12:30:11 -0500 Message-ID: <20260228173244.1509663-699-sashal@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260228173244.1509663-1-sashal@kernel.org> References: <20260228173244.1509663-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit 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 8e29cb4e6a01d..abf8923f8fc51 100644 --- a/include/linux/ima.h +++ b/include/linux/ima.h @@ -69,6 +69,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 5beb69edd12fd..36a34c54de58b 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 #include #include "ima.h" @@ -294,3 +296,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.51.0