From patchwork Wed Apr 16 02:10:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: steven chen X-Patchwork-Id: 14053064 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C193822AE5D; Wed, 16 Apr 2025 02:11:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744769466; cv=none; b=AGSEJdomUEXfMudcEjTd1505oudbGVGqYzji3L34TwFoOf1RryhnQBeJtmSa8AHvn9/uKKQsUUYhhOiqeLP2kDSsN1VHUOnhv/IqBGIbW8f3ZSt8wqhP3jJXEWpCmL4p7e1jdS/Ox9I6f6r3zSHFk2/sGRR1cborn9fl6zJi7SQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744769466; c=relaxed/simple; bh=C68aO11fwY5Hq7MhMVBjpxhOBUfYTUWrOF7aOqYOLWM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qZmmHVUt0IjZ6LqTKQDKu73o6BuTCcpSSV4HN0wheIpGRcWd4D39AJDWtFNIWgeTwpslMtPIUr3BY7AAeyrmrUMUDJ363PJF1B0YSLIqyw8M1E+dE9BPj4ZJlmI8/h5F3dP91jHCQk1RIGoRuqhfd4pqlv9+LuzLC1JQomwrLlo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=ad7rB5dm; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="ad7rB5dm" Received: from DESKTOP-VOT081N.hsd1.ga.comcast.net (unknown [172.200.70.13]) by linux.microsoft.com (Postfix) with ESMTPSA id 2C96E210C453; Tue, 15 Apr 2025 19:11:01 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 2C96E210C453 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1744769464; bh=6xgOBYzerQDrucaQC/lEMeygmGpDLxyAasYBprqw4mk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ad7rB5dm89SYDtjRH6L1G+DqFNyHVb1FLhdlv6ucB5wqHx4QFCbB9APsfsVYnldtl ofg3dunWmQLqeR92Gl3pA/MRaypR70q9CB9iauRaPHEedfEWUkTW0dWXNOEOi6MUGW 7rzFG2pCRMMFIju5/NnGPtfwfxUQfeSQpVR+FKHQ= 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 v12 7/9] ima: verify if the segment size has changed Date: Tue, 15 Apr 2025 19:10:25 -0700 Message-ID: <20250416021028.1403-8-chenste@linux.microsoft.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250416021028.1403-1-chenste@linux.microsoft.com> References: <20250416021028.1403-1-chenste@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-security-module@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Steven Chen 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 Acked-by: Baoquan He Reviewed-by: Mimi Zohar --- 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 */