Skip to content

Commit 0214b96

Browse files
mimizohargregkh
authored andcommitted
ima: limit the number of ToMToU integrity violations
[ Upstream commit a414016 ] 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> [ adapted IMA flag definitions location from ima.h to integrity.h ] Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 905d43b commit 0214b96

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

security/integrity/ima/ima_main.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,22 @@ static void ima_rdwr_violation_check(struct file *file,
128128
if (atomic_read(&inode->i_readcount) && IS_IMA(inode)) {
129129
if (!iint)
130130
iint = integrity_iint_find(inode);
131+
131132
/* IMA_MEASURE is set from reader side */
132-
if (iint && test_bit(IMA_MUST_MEASURE,
133-
&iint->atomic_flags))
133+
if (iint && test_and_clear_bit(IMA_MAY_EMIT_TOMTOU,
134+
&iint->atomic_flags))
134135
send_tomtou = true;
135136
}
136137
} else {
137138
if (must_measure)
138-
set_bit(IMA_MUST_MEASURE, &iint->atomic_flags);
139-
if (inode_is_open_for_write(inode) && must_measure)
140-
send_writers = true;
139+
set_bit(IMA_MAY_EMIT_TOMTOU, &iint->atomic_flags);
140+
141+
/* Limit number of open_writers violations */
142+
if (inode_is_open_for_write(inode) && must_measure) {
143+
if (!test_and_set_bit(IMA_EMITTED_OPENWRITERS,
144+
&iint->atomic_flags))
145+
send_writers = true;
146+
}
141147
}
142148

143149
if (!send_tomtou && !send_writers)

security/integrity/integrity.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@
7474
#define IMA_UPDATE_XATTR 1
7575
#define IMA_CHANGE_ATTR 2
7676
#define IMA_DIGSIG 3
77-
#define IMA_MUST_MEASURE 4
77+
#define IMA_MAY_EMIT_TOMTOU 4
78+
#define IMA_EMITTED_OPENWRITERS 5
7879

7980
enum evm_ima_xattr_type {
8081
IMA_XATTR_DIGEST = 0x01,

0 commit comments

Comments
 (0)