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 6536B25A64B; Thu, 17 Apr 2025 18:51:13 +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=1744915873; cv=none; b=jRHaE+fuQWHdnM3t5xxBSVWygH1rUkR3ERGYHnaBB9Pp5oeIZe6237J/UqQwKTsmHshCEHyg8bjmkdsHf1+gvwcnfiaVu8cIrOwVeY73uuvmE4u9CAgWVcCpNbkk3eXD3+dDKMuBiQmyCjghDETvWLx8hDDPydbTKb2hdyZrh7o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744915873; c=relaxed/simple; bh=7571AtHlhzgk/GjfdGAPf3dC5USiIrLlfcJRGTqStSc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iRImxNqUO4dARpVLOBpyS3MwO1qP3MldbeoT6knBuBvtW4owTSVlKrvKIF9ixbbR8zqJpMzsP8P8IDwp6u8683liydGt+zpr1bCgzHr7A3mpSCBRyqmk2RY8gHNsCMp7hHdwX9oXpyOzlXjOaueNrfFpxtDp42nkf3v3S4k5Xqw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=yw5UHHu/; 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="yw5UHHu/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EE3A1C4CEE4; Thu, 17 Apr 2025 18:51:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1744915873; bh=7571AtHlhzgk/GjfdGAPf3dC5USiIrLlfcJRGTqStSc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yw5UHHu/KH9e/uC7lmihPfpGXVLkyFfHuQV/pLjltMI1xxt02W/1b6TxQsMpwQwwe vYeFvXlBIJ+N/YK/xEssBhi+4QDbqODD+bNDrDuvs5dNCjArKFDVEs7hcMc1/2PKs+ a4qs7eGJNyeAG906Jwe2UTmMzMnUgBgoz2G4UAAQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Stefan Berger , Petr Vorel , Roberto Sassu , Mimi Zohar Subject: [PATCH 6.12 268/393] ima: limit the number of open-writers integrity violations Date: Thu, 17 Apr 2025 19:51:17 +0200 Message-ID: <20250417175118.385104342@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250417175107.546547190@linuxfoundation.org> References: <20250417175107.546547190@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.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mimi Zohar commit 5b3cd801155f0b34b0b95942a5b057c9b8cad33e upstream. Each time a file in policy, that is already opened for write, is opened for read, an open-writers integrity violation audit message is emitted and a violation record is added to the IMA measurement list. This occurs even if an open-writers violation has already been recorded. Limit the number of open-writers integrity violations for an existing file open for write to one. After the existing file open for write closes (__fput), subsequent open-writers integrity violations may be emitted. Cc: stable@vger.kernel.org # applies cleanly up to linux-6.6 Tested-by: Stefan Berger Reviewed-by: Petr Vorel Tested-by: Petr Vorel Reviewed-by: Roberto Sassu Signed-off-by: Mimi Zohar Signed-off-by: Greg Kroah-Hartman --- security/integrity/ima/ima.h | 1 + security/integrity/ima/ima_main.c | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) --- a/security/integrity/ima/ima.h +++ b/security/integrity/ima/ima.h @@ -182,6 +182,7 @@ struct ima_kexec_hdr { #define IMA_CHANGE_ATTR 2 #define IMA_DIGSIG 3 #define IMA_MUST_MEASURE 4 +#define IMA_EMITTED_OPENWRITERS 5 /* IMA integrity metadata associated with an inode */ struct ima_iint_cache { --- a/security/integrity/ima/ima_main.c +++ b/security/integrity/ima/ima_main.c @@ -137,8 +137,13 @@ static void ima_rdwr_violation_check(str } else { if (must_measure) set_bit(IMA_MUST_MEASURE, &iint->atomic_flags); - if (inode_is_open_for_write(inode) && must_measure) - send_writers = true; + + /* Limit number of open_writers violations */ + if (inode_is_open_for_write(inode) && must_measure) { + if (!test_and_set_bit(IMA_EMITTED_OPENWRITERS, + &iint->atomic_flags)) + send_writers = true; + } } if (!send_tomtou && !send_writers) @@ -167,6 +172,8 @@ static void ima_check_last_writer(struct if (atomic_read(&inode->i_writecount) == 1) { struct kstat stat; + clear_bit(IMA_EMITTED_OPENWRITERS, &iint->atomic_flags); + update = test_and_clear_bit(IMA_UPDATE_XATTR, &iint->atomic_flags); if ((iint->flags & IMA_NEW_FILE) ||