From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 B1BC243B6F2; Mon, 17 Aug 2026 14:52:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786978351; cv=none; b=g44f9KUOm8fWXmO0apzbkYT6UYZR2aFRHqgaA+gitlSNjHTKdG7F+h77avDeADVdMFnehiBf2jBI1xZ6k8K4h3BD9kTYbRZRcGhonzMEcNlB5cuNz4y7l/PKoIvQtRrqpXovJ1JKWZCNp05rJi4tslYqT7eh9UJDmV1VBY4VBwY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786978351; c=relaxed/simple; bh=Yk1mAa/XB4ZMgmqU32peJdctWBmwpa9Wf6KfcIW0giQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S4g4U95rOelTNjfQ3GsS11mpGGl7ngjicQqB3UlpQ1sFanFrCUspnWhgRPEJIhbaFkJrzJsqxH1piOpSyZ+DoP0DJ31Pqli89Bqq3R2Mo4iBIZOH9WPoU1/y7PS8vF35Be9wD/VY4ezfA0iN1ho9w4jy387iR+NSxctrAC9PgHk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=d7iOxPGB; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="d7iOxPGB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C694D1F000E9; Mon, 17 Aug 2026 14:52:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1786978350; bh=GqoN3ck2uSg0OfHyJ0WiNATquEHRT5r5mfdlMgqQHSU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=d7iOxPGBz62TKmsZAtfr3+ktxlOiGQjYS+bdZoAUVXfUygWqM5j9yXfhVfoU8Ky7y Af34vCxc445tEgXQUAx2h6euVWWcKIP/fmF5Tg3wZAOprgm9ttKJIyrrIWbUddzdNJ xRWL2JJQ1O7LcKnoWul2ACczejr/X61c7yB1zTmE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Frederick Lawler , Mimi Zohar Subject: [PATCH 6.12 171/181] ima: Instantiate file_truncate and path_truncate hooks Date: Mon, 17 Aug 2026 15:34:25 +0200 Message-ID: <20260817132542.414736323@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260817132535.394764707@linuxfoundation.org> References: <20260817132535.394764707@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mimi Zohar commit b80bed5c871a80151351342c065579405ce77145 upstream. Instantiate the file_truncate and path_truncate LSM hooks to reset the action cache flags (IMA_DONE_MASK) as soon as truncation is requested, so the file, based on policy, is re-collected, re-measured, re-audited, and re-appraised on next access. Tested-by: Frederick Lawler Cc: stable@vger.kernel.org Signed-off-by: Mimi Zohar Signed-off-by: Greg Kroah-Hartman --- security/integrity/ima/ima_main.c | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) --- a/security/integrity/ima/ima_main.c +++ b/security/integrity/ima/ima_main.c @@ -587,6 +587,43 @@ static int ima_file_check(struct file *f MAY_APPEND), FILE_CHECK); } +/* + * ima_reset_action_flags - invalidate action flags after a content change + * @inode: inode of the file whose content is about to be truncated + * + * Clear IMA_DONE_MASK so the file is re-collected, re-measured, + * re-audited, and re-appraised on next access. + */ +static void ima_reset_action_flags(struct inode *inode) +{ + struct ima_iint_cache *iint; + + if (!ima_policy_flag || !S_ISREG(inode->i_mode)) + return; + + iint = ima_iint_find(inode); + if (!iint) + return; + + mutex_lock(&iint->mutex); + iint->flags &= ~IMA_DONE_MASK; + iint->measured_pcrs = 0; + mutex_unlock(&iint->mutex); + return; +} + +static int ima_path_truncate(const struct path *path) +{ + ima_reset_action_flags(path->dentry->d_inode); + return 0; +} + +static int ima_file_truncate(struct file *file) +{ + ima_reset_action_flags(file_inode(file)); + return 0; +} + static int __ima_inode_hash(struct inode *inode, struct file *file, char *buf, size_t buf_size) { @@ -1195,11 +1232,13 @@ static struct security_hook_list ima_hoo LSM_HOOK_INIT(file_release, ima_file_free), LSM_HOOK_INIT(mmap_file, ima_file_mmap), LSM_HOOK_INIT(file_mprotect, ima_file_mprotect), + LSM_HOOK_INIT(file_truncate, ima_file_truncate), LSM_HOOK_INIT(kernel_load_data, ima_load_data), LSM_HOOK_INIT(kernel_post_load_data, ima_post_load_data), LSM_HOOK_INIT(kernel_read_file, ima_read_file), LSM_HOOK_INIT(kernel_post_read_file, ima_post_read_file), LSM_HOOK_INIT(path_post_mknod, ima_post_path_mknod), + LSM_HOOK_INIT(path_truncate, ima_path_truncate), #ifdef CONFIG_IMA_MEASURE_ASYMMETRIC_KEYS LSM_HOOK_INIT(key_post_create_or_update, ima_post_key_create_or_update), #endif