From nobody Mon Feb 9 12:27:05 2026 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (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 CCDED1A9F84; Mon, 29 Dec 2025 08:16:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.165.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766996170; cv=none; b=tFRaLrCGlBnuMnRl7Y519yF4FERfyRufrABaoIKhuzFWEr0erq7JODWRLbbnTjZMTI9x40Q8HmE4fw6VBbz+eMDCJPHiCvVAzG9yMLvhfGnOmKYgERLCJqMeawHySv6l3Ys9i3kXXrwFKZ5uZnxTCu2ZWfC/Vd0kvX80hqlstZA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766996170; c=relaxed/simple; bh=nCB/vq9GHemJ7H8kGdbP7b8VUFuOb3hndzc+d2kgi3k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N1B8J36BXigFFIZBY/g2ShV1+Eq6Z+YEZ7zgBtULCQJubhPIfbIrY9DckJNoHTsqdV4/+oiT1OfY8zki0WHVOU6VKOGjbXHfh1M4Kv8CTdOABtHvKbHJtiOFJom+PBJZhF9nokWCXk0AWtEyPo4FFAlBemYVeLCmVg6wi6xZSZQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=cigaM4vD; arc=none smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="cigaM4vD" Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 5BT4U3v91134126; Mon, 29 Dec 2025 08:15:31 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2025-04-25; bh=T9FEo sqsn3CPvPl9QYE9L03k4E3xg3U5lG0eXv+pu6E=; b=cigaM4vDU+1HnfctNh1uZ O80M/IHq87scJvX4/Qbf2+DqWSL8UcVxHWPf781uatocx4idcLWks2xvAfrSIET7 SX0mcjr85hOmvAY94uYbBvdmphFiq3yLnSUYOoqLLTFkMMfn9NGmGgoeYcVSIxsM dmEUR0e3nfGry2QzDV+jD/0ZpmgLzmboV2BVH3BSFWvt5tJMnUgXC6URgsRDTVSG fLTucwxyVCOcBMgAFxQjCp1LszU738C0xTBdKAKf5weGm98WHHgCNL9Bz6PHToFe YFYTA24Pm0/X2TuNqPJu6WMM5/J+j/aoGibU6yEG26RNUzfGDkhfD3j/NFduDJ+Z w== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4ba6c8scg8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Dec 2025 08:15:31 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5BT5hO90038371; Mon, 29 Dec 2025 08:15:30 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4ba5w6xkev-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Dec 2025 08:15:30 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5BT8FReh007295; Mon, 29 Dec 2025 08:15:29 GMT Received: from ca-dev112.us.oracle.com (ca-dev112.us.oracle.com [10.129.136.47]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4ba5w6xkd1-2; Mon, 29 Dec 2025 08:15:29 +0000 From: Harshit Mogalapalli To: zohar@linux.ibm.com Cc: akpm@linux-foundation.org, ardb@kernel.org, bp@alien8.de, dave.hansen@linux.intel.com, graf@amazon.com, guoweikang.kernel@gmail.com, harshit.m.mogalapalli@oracle.com, henry.willard@oracle.com, hpa@zytor.com, jbohac@suse.cz, joel.granados@kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com, noodles@fb.com, paul.x.webb@oracle.com, rppt@kernel.org, sohil.mehta@intel.com, sourabhjain@linux.ibm.com, stable@vger.kernel.org, tglx@linutronix.de, x86@kernel.org, yifei.l.liu@oracle.com Subject: [PATCH v2 1/3] ima: Add ima_validate_range() for previous kernel IMA buffer Date: Mon, 29 Dec 2025 00:15:21 -0800 Message-ID: <20251229081523.622515-2-harshit.m.mogalapalli@oracle.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20251229081523.622515-1-harshit.m.mogalapalli@oracle.com> References: <20251229081523.622515-1-harshit.m.mogalapalli@oracle.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2025-12-29_02,2025-12-26_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 mlxlogscore=999 malwarescore=0 suspectscore=0 spamscore=0 adultscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2512120000 definitions=main-2512290075 X-Authority-Analysis: v=2.4 cv=a4E9NESF c=1 sm=1 tr=0 ts=695238a3 cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=wP3pNCr1ah4A:10 a=VkNPw1HP01LnGYTKEx00:22 a=VwQbUJbxAAAA:8 a=yPCof4ZbAAAA:8 a=jkZM71ibJ-iyurowFaMA:9 X-Proofpoint-GUID: nuMDW7gWI9PBPqcyP_vtEXxKuHGNN8Yn X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMjI5MDA3NiBTYWx0ZWRfX51trV2daeV5H ugTnAP+AJM9y29it+riyzP91/0uD9q/DWPA4OdVV0Fv1zzx3a8YyAfZ0HmmfmLmqn0wXDF5xEUF CTXibOrtp3xceQnQB1njyZVII8ssrZRcA7csL/Os4T7pdJitg/M8gKHmu6eQrBKXth7H6JSUc3d l5Dl7VRwDCZpGn+PG7eVeyv8maSjAUV/0OOc7g6hhP9gL6mvK8+CAsNUmh/jP0sMSWGTUWjJaTO yg1+GhymgcA6FAzP5iWf8a4CBczZDPReJZTxOLv50Lnq3S86ymN1EiC6X9rK0lh0kHn/PH9ojb/ RFbSBqKu/YFLKwW+aSrjxmONwWmzFTntqxQeQ9N0juk3d0YK8aoKkKSr2YFlZkosdNkkSCtx34X 5DGB4qkzvzfg12DJtqr46vY6K6qLa2PnlQJp/1RuK8c7A3hLrTdOdkKCtxV09itCMG4y902kzlw +ajJ0FnmJ+R1dNX5D+g== X-Proofpoint-ORIG-GUID: nuMDW7gWI9PBPqcyP_vtEXxKuHGNN8Yn Content-Type: text/plain; charset="utf-8" When the second-stage kernel is booted with a limiting command line (e.g. "mem=3D"), 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(). Cc: stable@vger.kernel.org Signed-off-by: Harshit Mogalapalli --- 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 8e29cb4e6a01..abf8923f8fc5 100644 --- a/include/linux/ima.h +++ b/include/linux/ima.h @@ -69,6 +69,7 @@ static inline int ima_measure_critical_data(const char *e= vent_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 =20 #ifdef CONFIG_IMA_SECURE_AND_OR_TRUSTED_BOOT diff --git a/security/integrity/ima/ima_kexec.c b/security/integrity/ima/im= a_kexec.c index 7362f68f2d8b..8b24e3312ea0 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" @@ -296,3 +298,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 =3D PHYS_PFN(phys); + end_pfn =3D 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 o= utside available memory\n", + &phys, size); + return -EINVAL; + } + + return 0; +} --=20 2.50.1 From nobody Mon Feb 9 12:27:05 2026 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (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 CCE58243951; Mon, 29 Dec 2025 08:16:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.165.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766996170; cv=none; b=rI/Vl1nfuXx5FmpUJE20PQV53W815mbhPf0s/S5obtp1cIraXV/RX5dwU8wCWJerokb7wPhar6L6xWfGy4/8Eb5UU4NnHprawqF1k5GsEFz6OlKDHBnkL0kH84n1G1z7fhptPwCruNRAogHRGezv25Tx2Of1e+D41DNOZgBAJBE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766996170; c=relaxed/simple; bh=Wmx85wmq620EWgMBeQw8wBok92AaaxxkkIkdQr5RHPY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KibQ4quSbneG3ZAoM0/RVs8ynvr8RBMPZOCXOuf9p8pf51PNmC0FkNg6xuxlgsNIq2Lkjqj6/druas0NLJoPfpUMjHPPqji5DkUg15skdLrrO5oS3ABM2OD4xiWEP0ptjeDf4WJHwbP3Tm83cNNxnvuGqg8tiyB3Y7rvfYkCliE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=Hk3c2xRx; arc=none smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="Hk3c2xRx" Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 5BT2j1Ex758065; Mon, 29 Dec 2025 08:15:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2025-04-25; bh=yYT7w MenZMNN7NbypYzu5g9N+yk+N6R4Gx8aGrK6Ikw=; b=Hk3c2xRxEMqz1lV/bxegM DdBHvXy6Cp9R3pocIJH7rwDbpKvtCtAqy8H5u6AyhLHeEDCWC6yQjsaLnOh6xFDM i3qN28cSECE1fVTANjf1qg6V5UP+zgsrpdYPOTcDy/2WJRA5JFHfSMmYTmDGfBnx tTP6dFebwklCrjxmoth6ZMpSmib/m/o0ip2iLsInl9cMN8csGYMH/5OkKSemRACo DtNS7lNCFOQlPgW3RFoso7BmSMwUGGfoYx0lduGp3qT80t+MageKMyFT0x9+gcPc ebqka/7ifrBbZOYq8Ggtsz34hX05JcPRoGNaQFu/9PW2I+2uxDFK60K6IC1xmo4i w== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4ba61w9c2n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Dec 2025 08:15:33 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5BT41mJm038909; Mon, 29 Dec 2025 08:15:32 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4ba5w6xkfu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Dec 2025 08:15:32 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5BT8FRej007295; Mon, 29 Dec 2025 08:15:32 GMT Received: from ca-dev112.us.oracle.com (ca-dev112.us.oracle.com [10.129.136.47]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4ba5w6xkd1-3; Mon, 29 Dec 2025 08:15:31 +0000 From: Harshit Mogalapalli To: zohar@linux.ibm.com Cc: akpm@linux-foundation.org, ardb@kernel.org, bp@alien8.de, dave.hansen@linux.intel.com, graf@amazon.com, guoweikang.kernel@gmail.com, harshit.m.mogalapalli@oracle.com, henry.willard@oracle.com, hpa@zytor.com, jbohac@suse.cz, joel.granados@kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com, noodles@fb.com, paul.x.webb@oracle.com, rppt@kernel.org, sohil.mehta@intel.com, sourabhjain@linux.ibm.com, stable@vger.kernel.org, tglx@linutronix.de, x86@kernel.org, yifei.l.liu@oracle.com Subject: [PATCH v2 2/3] of/kexec: refactor ima_get_kexec_buffer() to use ima_validate_range() Date: Mon, 29 Dec 2025 00:15:22 -0800 Message-ID: <20251229081523.622515-3-harshit.m.mogalapalli@oracle.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20251229081523.622515-1-harshit.m.mogalapalli@oracle.com> References: <20251229081523.622515-1-harshit.m.mogalapalli@oracle.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2025-12-29_02,2025-12-26_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 mlxlogscore=999 malwarescore=0 suspectscore=0 spamscore=0 adultscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2512120000 definitions=main-2512290075 X-Authority-Analysis: v=2.4 cv=LL1rgZW9 c=1 sm=1 tr=0 ts=695238a5 cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=wP3pNCr1ah4A:10 a=VkNPw1HP01LnGYTKEx00:22 a=VwQbUJbxAAAA:8 a=yPCof4ZbAAAA:8 a=pjPCvf8BpcJgz2SLxb0A:9 X-Proofpoint-ORIG-GUID: 9oJhsk-UKZ6qUfemTxpfzq54qdwFtfIC X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMjI5MDA3NSBTYWx0ZWRfX8e/ie67fa651 AKiYjhfk591sOmuqoOsLJ+b3PFylX+CTCuDWgQChOpy3+ngbJUPKdvKCFWUVhQAZeWP5iAq60EF CpdcwPxWnm7tV2mWVxTE2ekmDMnGbU8wNX3GbA28bXJvWu1XpSjEWZxtnzlr+mtUfIVfzkpNwjr ITije5w+KN8O0KoO8vnqlKNqCBJfaTf5cJ2/fdIorl1VW+PGWD+v1EcwtpJcNL6THZ0t3ES/8uO 2oGjQf1PDuoHQ8TUgtpM6psfeET6rU+gem6uHIXEKZlxXui4LsvTOjDvvxvHquI7KtUHJYhyGG9 Gw3sqIlM5mh2ma6ltp48yTUKnXU6mZlgyvHJ//G3zcyFNl8dA5FOkEclDZA7q4+iaumBkjeMgH8 T+5wMSxV+yyli1raRr7KzxVaTMWTWxwC4n78HvBWc4Dq5gHBAPssadEJksWkuoqkvSIuUl8SizT idxheMzDP1cAvz7gttw== X-Proofpoint-GUID: 9oJhsk-UKZ6qUfemTxpfzq54qdwFtfIC Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Mimi Zohar --- 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 *si= ze) { int ret, len; unsigned long tmp_addr; - unsigned long start_pfn, end_pfn; size_t tmp_size; const void *prop; =20 @@ -144,17 +143,9 @@ int __init ima_get_kexec_buffer(void **addr, size_t *s= ize) if (!tmp_size) return -ENOENT; =20 - /* - * Calculate the PFNs for the buffer and ensure - * they are with in addressable memory. - */ - start_pfn =3D PHYS_PFN(tmp_addr); - end_pfn =3D 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 =3D 0x%zx beyond memory\n", - tmp_addr, tmp_size); - return -EINVAL; - } + ret =3D ima_validate_range(tmp_addr, tmp_size); + if (ret) + return ret; =20 *addr =3D __va(tmp_addr); *size =3D tmp_size; --=20 2.50.1 From nobody Mon Feb 9 12:27:05 2026 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (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 056641A9F84; Mon, 29 Dec 2025 08:16:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.177.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766996165; cv=none; b=vEsO0tLXtQOQB2NATnwi43LnpAAhV5l9xJhGviSCowneF5IVDFX1jlAN6pppDQitO+7UlDSAY14fXfHS9nXvC49Lacf/H8W0Hw6m6MWbGa1rv+ekLBxVkWbV0LcIFzZZ+Zu8085iNkh8713kTUZ1GM4UcQqe2zBDisyxB5nBgNw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766996165; c=relaxed/simple; bh=kWFY7U8PvmqWwQiqjOhTVBQEJTUw4UMJwJdysV/gGxA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jT1Rn2CfFyvdJP85lEzDL+Fp5TZ9fJ3sLmX9/rcG123VDue1mbobzAj9evRiMkAcVLCUeTIFqWFMJXh8RliDzTEIwTtrI/egZWArKLQ39yEj9J06IzPVhdKhkPXaU8Lkbem7Vasbb5CtGKEUqoDIK8EMLR/4eXRaqHl3e1tJ4DY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=J99jiIGz; arc=none smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="J99jiIGz" Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 5BT0RNgA694107; Mon, 29 Dec 2025 08:15:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2025-04-25; bh=lHB0/J787mnSR9SkGM/Vuf+mrrFlbP8x78mioF8t+JE=; b= J99jiIGzF96g5gcVCDRzoXtpUkecxNwP4ohJ+NK+nOFN82TiyQOooC2yaP3VSLuM hc91GW4PFWnRaJr4i4c5pqYDdmqHbU2Akm5FnegU8+XHxNc8z+6lBmEttLhaXppX q6R1dwWTEHvFjCEZ2CTcch5ZwLdBYeNu/zneU+zD5BCP3hDz6DYZUOa8xSGbT9LQ V0S+1nh+tucJ5jjHAdyAVaKEZxC7bxZBRaY3Z7Ve1u3Vvqvj/LMg9bOLRCpMk0qk ekr4DN/uonxb+MBiHfjGCyweqM1uODHdZpGAxztuRrNy4oyW8q8mMG9gOaGdl8pX uSI8MadZLClJVABxd/de1Q== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4ba680hcv1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Dec 2025 08:15:36 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5BT8EEp8039021; Mon, 29 Dec 2025 08:15:35 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4ba5w6xkgx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Dec 2025 08:15:35 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5BT8FRel007295; Mon, 29 Dec 2025 08:15:34 GMT Received: from ca-dev112.us.oracle.com (ca-dev112.us.oracle.com [10.129.136.47]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4ba5w6xkd1-4; Mon, 29 Dec 2025 08:15:34 +0000 From: Harshit Mogalapalli To: zohar@linux.ibm.com Cc: akpm@linux-foundation.org, ardb@kernel.org, bp@alien8.de, dave.hansen@linux.intel.com, graf@amazon.com, guoweikang.kernel@gmail.com, harshit.m.mogalapalli@oracle.com, henry.willard@oracle.com, hpa@zytor.com, jbohac@suse.cz, joel.granados@kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com, noodles@fb.com, paul.x.webb@oracle.com, rppt@kernel.org, sohil.mehta@intel.com, sourabhjain@linux.ibm.com, stable@vger.kernel.org, tglx@linutronix.de, x86@kernel.org, yifei.l.liu@oracle.com Subject: [PATCH v2 3/3] x86/kexec: Add a sanity check on previous kernel's ima kexec buffer Date: Mon, 29 Dec 2025 00:15:23 -0800 Message-ID: <20251229081523.622515-4-harshit.m.mogalapalli@oracle.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20251229081523.622515-1-harshit.m.mogalapalli@oracle.com> References: <20251229081523.622515-1-harshit.m.mogalapalli@oracle.com> 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 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2025-12-29_02,2025-12-26_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 mlxlogscore=999 malwarescore=0 suspectscore=0 spamscore=0 adultscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2512120000 definitions=main-2512290075 X-Proofpoint-ORIG-GUID: mTrnVpmVVnXBMx9vjB6SC8LHuuKGGYJq X-Proofpoint-GUID: mTrnVpmVVnXBMx9vjB6SC8LHuuKGGYJq X-Authority-Analysis: v=2.4 cv=HPLO14tv c=1 sm=1 tr=0 ts=695238a8 cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=IkcTkHD0fZMA:10 a=wP3pNCr1ah4A:10 a=VkNPw1HP01LnGYTKEx00:22 a=VwQbUJbxAAAA:8 a=yPCof4ZbAAAA:8 a=nkYO0nU_c48bT3HRU-QA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMjI5MDA3NiBTYWx0ZWRfX4eVbANUdtb8V Q6sjqi0WYMVICEmLFUEBzzMN4yXddN+Yp1k5tfrmltUJt8ixYUuuR64lbz7KPon21X3EwQobUFq fHz5UvdguY1Wdz+7I3q23bohy7xroPVqHiAnj8FHnr11fdyG6mrXSdOPaTc27sLnKtof0sD5BA/ AD9g086wLrLg5ng0Yt4bGwtPUdnUNk+DT2j3ibzMkKQfeyvrN47aH6CZ37SNEkBKBRwoaai4AO+ ige3b57Is1nn9goxdVwlxfAPqbKQ/QfP6eo/u0YqQE4jZ5S069U2C81v4CAFWHFymbm8XmNJJro 3UqwxmR809ltE9sRTWFQCdTCUyzOTU2aIwI+7laLqYUgUfc7UHpjYo0dZUPPw10HFm7Coz/dpzP iV2Hg2MQoKAgDunzTkdRDu8Rh3g111YqKRhiTbxthkhSUb2WQJSlnC9BqqVG2xbfFTwt7iCi2q4 miN7AReU/4NZIMmK4UA== When the second-stage kernel is booted via kexec with a limiting command line such as "mem=3D", the physical range that contains the carried over IMA measurement list may fall outside the truncated RAM leading to a kernel panic. BUG: unable to handle page fault for address: ffff97793ff47000 RIP: ima_restore_measurement_list+0xdc/0x45a #PF: error_code(0x0000) =E2=80=93 not-present page Other architectures already validate the range with page_is_ram(), as done in commit cbf9c4b9617b ("of: check previous kernel's ima-kexec-buffer against memory bounds") do a similar check on x86. Without carrying the measurement list across kexec, the attestation would fail. Cc: stable@vger.kernel.org Fixes: b69a2afd5afc ("x86/kexec: Carry forward IMA measurement log on kexec= ") Reported-by: Paul Webb Signed-off-by: Harshit Mogalapalli Reviewed-by: Mimi Zohar --- V1-> V2: Added a line about carrying measure list across kexec based on suggestion from Mimi Zohar. Made use to the new generic helper [Suggestion from Borislav] --- arch/x86/kernel/setup.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index 1b2edd07a3e1..383d4a4784f5 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -439,9 +439,15 @@ int __init ima_free_kexec_buffer(void) =20 int __init ima_get_kexec_buffer(void **addr, size_t *size) { + int ret; + if (!ima_kexec_buffer_size) return -ENOENT; =20 + ret =3D ima_validate_range(ima_kexec_buffer_phys, ima_kexec_buffer_size); + if (ret) + return ret; + *addr =3D __va(ima_kexec_buffer_phys); *size =3D ima_kexec_buffer_size; =20 --=20 2.50.1