Skip to content

Commit a414016

Browse files
committed
ima: limit the number of ToMToU integrity violations
Each time a file in policy, that is already opened for read, is opened for write, a Time-of-Measure-Time-of-Use (ToMToU) integrity violation audit message is emitted and a violation record is added to the IMA measurement list. This occurs even if a ToMToU violation has already been recorded. Limit the number of ToMToU integrity violations per file open for read. Note: The IMA_MAY_EMIT_TOMTOU atomic flag must be set from the reader side based on policy. This may result in a per file open for read ToMToU violation. Since IMA_MUST_MEASURE is only used for violations, rename the atomic IMA_MUST_MEASURE flag to IMA_MAY_EMIT_TOMTOU. Cc: stable@vger.kernel.org # applies cleanly up to linux-6.6 Tested-by: Stefan Berger <stefanb@linux.ibm.com> Reviewed-by: Petr Vorel <pvorel@suse.cz> Tested-by: Petr Vorel <pvorel@suse.cz> Reviewed-by: Roberto Sassu <roberto.sassu@huawei.com> Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
1 parent 5b3cd80 commit a414016

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

security/integrity/ima/ima.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ struct ima_kexec_hdr {
181181
#define IMA_UPDATE_XATTR 1
182182
#define IMA_CHANGE_ATTR 2
183183
#define IMA_DIGSIG 3
184-
#define IMA_MUST_MEASURE 4
184+
#define IMA_MAY_EMIT_TOMTOU 4
185185
#define IMA_EMITTED_OPENWRITERS 5
186186

187187
/* IMA integrity metadata associated with an inode */

security/integrity/ima/ima_main.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,15 @@ static void ima_rdwr_violation_check(struct file *file,
129129
if (atomic_read(&inode->i_readcount) && IS_IMA(inode)) {
130130
if (!iint)
131131
iint = ima_iint_find(inode);
132+
132133
/* IMA_MEASURE is set from reader side */
133-
if (iint && test_bit(IMA_MUST_MEASURE,
134-
&iint->atomic_flags))
134+
if (iint && test_and_clear_bit(IMA_MAY_EMIT_TOMTOU,
135+
&iint->atomic_flags))
135136
send_tomtou = true;
136137
}
137138
} else {
138139
if (must_measure)
139-
set_bit(IMA_MUST_MEASURE, &iint->atomic_flags);
140+
set_bit(IMA_MAY_EMIT_TOMTOU, &iint->atomic_flags);
140141

141142
/* Limit number of open_writers violations */
142143
if (inode_is_open_for_write(inode) && must_measure) {

0 commit comments

Comments
 (0)