From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 E3BA51DE89C; Mon, 10 Mar 2025 17:38:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741628286; cv=none; b=DJndGBZZmWPPFGlSQfUjC7i9bM3E/h8RrBo2saMlD3vt9lNaj7Egz3oRSs9qKnJSPD5O33+QDwiv9Z6lE6KtWRK3J8Ei0pzXqjak0KDNHPto1ukosX+/0nfgMGxdPJkWb5iauyDBjQ9UMC4A0LjPkUFHlXgYoBulYtckD7Dsl4g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741628286; c=relaxed/simple; bh=GBoY/r60u0R+vOFhGPNGjGVEustp1xTkDQfjXA2F00Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KgJI/RCjwr5esPaPowd4lY4YmqdBZ6TTzUuLDNu6HjnEZJk63B7h+tRqAwg0aWQ3DeigE+SwgBO7xkcbX4BGYfEKvnSC7pqurdn7zkmOki3SHhjHigFJw1yzQN3Ecs8iLhRbcuy3poEuWVxKzVLhC9MMpIrwlkdOId7A6uEVwtY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=K74YrU9x; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="K74YrU9x" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C4FEC4CEE5; Mon, 10 Mar 2025 17:38:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1741628285; bh=GBoY/r60u0R+vOFhGPNGjGVEustp1xTkDQfjXA2F00Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K74YrU9xUW3y429t16S5sEwdDQVW06BSJYYNy7VVVZ8fmPUJOlLku8OfybgAh80PX nCoyegFkav9KNUWq96xSG+44JTesY7YumoPHcOCkIc0zsyRQyE7dWpS8YGr3eo5IeH yQbY8/yig4xTjtSKmy9TeL7zufRoipTYdzU3nw20= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Roberto Sassu , Mimi Zohar Subject: [PATCH 6.6 140/145] ima: Reset IMA_NONACTION_RULE_FLAGS after post_setattr Date: Mon, 10 Mar 2025 18:07:14 +0100 Message-ID: <20250310170440.405840272@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250310170434.733307314@linuxfoundation.org> References: <20250310170434.733307314@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Roberto Sassu commit 57a0ef02fefafc4b9603e33a18b669ba5ce59ba3 upstream. Commit 0d73a55208e9 ("ima: re-introduce own integrity cache lock") mistakenly reverted the performance improvement introduced in commit 42a4c603198f0 ("ima: fix ima_inode_post_setattr"). The unused bit mask was subsequently removed by commit 11c60f23ed13 ("integrity: Remove unused macro IMA_ACTION_RULE_FLAGS"). Restore the performance improvement by introducing the new mask IMA_NONACTION_RULE_FLAGS, equal to IMA_NONACTION_FLAGS without IMA_NEW_FILE, which is not a rule-specific flag. Finally, reset IMA_NONACTION_RULE_FLAGS instead of IMA_NONACTION_FLAGS in process_measurement(), if the IMA_CHANGE_ATTR atomic flag is set (after file metadata modification). With this patch, new files for which metadata were modified while they are still open, can be reopened before the last file close (when security.ima is written), since the IMA_NEW_FILE flag is not cleared anymore. Otherwise, appraisal fails because security.ima is missing (files with IMA_NEW_FILE set are an exception). Cc: stable@vger.kernel.org # v4.16.x Fixes: 0d73a55208e9 ("ima: re-introduce own integrity cache lock") Signed-off-by: Roberto Sassu Signed-off-by: Mimi Zohar Signed-off-by: Greg Kroah-Hartman --- security/integrity/ima/ima_main.c | 7 +++++-- security/integrity/integrity.h | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) --- a/security/integrity/ima/ima_main.c +++ b/security/integrity/ima/ima_main.c @@ -267,10 +267,13 @@ static int process_measurement(struct fi mutex_lock(&iint->mutex); if (test_and_clear_bit(IMA_CHANGE_ATTR, &iint->atomic_flags)) - /* reset appraisal flags if ima_inode_post_setattr was called */ + /* + * Reset appraisal flags (action and non-action rule-specific) + * if ima_inode_post_setattr was called. + */ iint->flags &= ~(IMA_APPRAISE | IMA_APPRAISED | IMA_APPRAISE_SUBMASK | IMA_APPRAISED_SUBMASK | - IMA_NONACTION_FLAGS); + IMA_NONACTION_RULE_FLAGS); /* * Re-evaulate the file if either the xattr has changed or the --- a/security/integrity/integrity.h +++ b/security/integrity/integrity.h @@ -42,6 +42,9 @@ #define IMA_CHECK_BLACKLIST 0x40000000 #define IMA_VERITY_REQUIRED 0x80000000 +/* Exclude non-action flags which are not rule-specific. */ +#define IMA_NONACTION_RULE_FLAGS (IMA_NONACTION_FLAGS & ~IMA_NEW_FILE) + #define IMA_DO_MASK (IMA_MEASURE | IMA_APPRAISE | IMA_AUDIT | \ IMA_HASH | IMA_APPRAISE_SUBMASK) #define IMA_DONE_MASK (IMA_MEASURED | IMA_APPRAISED | IMA_AUDITED | \