From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6A461C369A0 for ; Wed, 2 Apr 2025 12:51:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=TIYkqv731cfeL17ltrsNIxcY2eH8QDnF2VgGdZyqueA=; b=hnDRnS49S/oDydzbeGs52Lwcph e4I/jfP4tzIjw5NKoAcTTkIw5T0P1pFfZZSW5r3Wa/U09KsAS9iTe2hpXuPZ6vpREE6V52/bmvw0M pDi90XAPB14ljhgv+0XzpTDSWaef6X5ih9M6cK7MNzoGq/r3aVKPdSWw56mglFiDqCTsbOUG1NXyr GwCrIELR7dMZnPDmvDgFbt9OnNrTt69Ozx/S6uoFAEjEzqsHLhnujRijX0IRuwwhbUPqkxa5GaX4G VIseE/5gG8WqNO0yIwAznmFA4buM36omruFlMRBNyXsDQNGM6C+B+sCcUug5m7wFOhRgSUnkyfq/6 ogBV3tsg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.1 #2 (Red Hat Linux)) id 1tzxZG-0000000694m-4AF4; Wed, 02 Apr 2025 12:51:42 +0000 Received: from linux.microsoft.com ([13.77.154.182]) by bombadil.infradead.org with esmtp (Exim 4.98.1 #2 (Red Hat Linux)) id 1tzxVZ-000000068BO-3Iss for kexec@lists.infradead.org; Wed, 02 Apr 2025 12:47:54 +0000 Received: from DESKTOP-VOT081N.hsd1.ga.comcast.net (unknown [20.114.144.49]) by linux.microsoft.com (Postfix) with ESMTPSA id 552AB2025659; Wed, 2 Apr 2025 05:47:51 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 552AB2025659 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1743598073; bh=TIYkqv731cfeL17ltrsNIxcY2eH8QDnF2VgGdZyqueA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fm+qKJrVOUXOB6o0pxrl+eGZ/HXdBBwWrzeph9P1dlK5GSO1qXjnHXPMtOGHknSv1 3UWNES/7HuZmbIe5oaKBNlt8pX+yf1f+IokQowtBgO/lUJiGla6cr0wnK/m04PQJHV srjip7h7MAtTReathD6kpxwApnASVV//qH2HqIJo= From: steven chen To: zohar@linux.ibm.com, stefanb@linux.ibm.com, roberto.sassu@huaweicloud.com, roberto.sassu@huawei.com, eric.snowberg@oracle.com, ebiederm@xmission.com, paul@paul-moore.com, code@tyhicks.com, bauermann@kolabnow.com, linux-integrity@vger.kernel.org, kexec@lists.infradead.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Cc: madvenka@linux.microsoft.com, nramas@linux.microsoft.com, James.Bottomley@HansenPartnership.com, bhe@redhat.com, vgoyal@redhat.com, dyoung@redhat.com Subject: [PATCH v11 7/9] ima: verify if the segment size has changed Date: Wed, 2 Apr 2025 05:47:20 -0700 Message-ID: <20250402124725.5601-8-chenste@linux.microsoft.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250402124725.5601-1-chenste@linux.microsoft.com> References: <20250402124725.5601-1-chenste@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250402_054753_850349_7605929D X-CRM114-Status: GOOD ( 10.30 ) X-BeenThere: kexec@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kexec" Errors-To: kexec-bounces+kexec=archiver.kernel.org@lists.infradead.org kexec 'load' may be called multiple times. Free and realloc the buffer only if the segment_size is changed from the previous kexec 'load' call. Signed-off-by: steven chen --- security/integrity/ima/ima_kexec.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/security/integrity/ima/ima_kexec.c b/security/integrity/ima/ima_kexec.c index 5c3b3e0b2186..ed867734ee70 100644 --- a/security/integrity/ima/ima_kexec.c +++ b/security/integrity/ima/ima_kexec.c @@ -33,6 +33,14 @@ static void ima_free_kexec_file_buf(struct seq_file *sf) static int ima_alloc_kexec_file_buf(size_t segment_size) { + /* + * kexec 'load' may be called multiple times. + * Free and realloc the buffer only if the segment_size is + * changed from the previous kexec 'load' call. + */ + if (ima_kexec_file.buf && ima_kexec_file.size == segment_size) + goto out; + ima_free_kexec_file_buf(&ima_kexec_file); /* segment size can't change between kexec load and execute */ @@ -41,6 +49,8 @@ static int ima_alloc_kexec_file_buf(size_t segment_size) return -ENOMEM; ima_kexec_file.size = segment_size; + +out: ima_kexec_file.read_pos = 0; ima_kexec_file.count = sizeof(struct ima_kexec_hdr); /* reserved space */ -- 2.25.1