[PATCH v2 2/3] of/kexec: refactor ima_get_kexec_buffer() to use ima_validate_range()

Harshit Mogalapalli posted 3 patches 1 month, 1 week ago
There is a newer version of this series
[PATCH v2 2/3] of/kexec: refactor ima_get_kexec_buffer() to use ima_validate_range()
Posted by Harshit Mogalapalli 1 month, 1 week ago
Refactor the OF/DT ima_get_kexec_buffer() to use a generic helper to
validate the address range. No functional change intended.

Cc: stable@vger.kernel.org
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
---
 drivers/of/kexec.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/drivers/of/kexec.c b/drivers/of/kexec.c
index 1ee2d31816ae..c4cf3552c018 100644
--- a/drivers/of/kexec.c
+++ b/drivers/of/kexec.c
@@ -128,7 +128,6 @@ int __init ima_get_kexec_buffer(void **addr, size_t *size)
 {
 	int ret, len;
 	unsigned long tmp_addr;
-	unsigned long start_pfn, end_pfn;
 	size_t tmp_size;
 	const void *prop;
 
@@ -144,17 +143,9 @@ int __init ima_get_kexec_buffer(void **addr, size_t *size)
 	if (!tmp_size)
 		return -ENOENT;
 
-	/*
-	 * Calculate the PFNs for the buffer and ensure
-	 * they are with in addressable memory.
-	 */
-	start_pfn = PHYS_PFN(tmp_addr);
-	end_pfn = PHYS_PFN(tmp_addr + tmp_size - 1);
-	if (!page_is_ram(start_pfn) || !page_is_ram(end_pfn)) {
-		pr_warn("IMA buffer at 0x%lx, size = 0x%zx beyond memory\n",
-			tmp_addr, tmp_size);
-		return -EINVAL;
-	}
+	ret = ima_validate_range(tmp_addr, tmp_size);
+	if (ret)
+		return ret;
 
 	*addr = __va(tmp_addr);
 	*size = tmp_size;
-- 
2.50.1
Re: [PATCH v2 2/3] of/kexec: refactor ima_get_kexec_buffer() to use ima_validate_range()
Posted by Mimi Zohar 1 month, 1 week ago
On Mon, 2025-12-29 at 00:15 -0800, Harshit Mogalapalli wrote:
> Refactor the OF/DT ima_get_kexec_buffer() to use a generic helper to
> validate the address range. No functional change intended.
> 
> Cc: stable@vger.kernel.org
> Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>

Reviewed-by: Mimi Zohar <zohar@linux.ibm.com>