Skip to content

Commit a2d4f47

Browse files
committed
Merge tag 'integrity-v6.15' of git://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity
Pull ima updates from Mimi Zohar: "Two performance improvements, which minimize the number of integrity violations" * tag 'integrity-v6.15' of git://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity: ima: limit the number of ToMToU integrity violations ima: limit the number of open-writers integrity violations
2 parents f174ac5 + a414016 commit a2d4f47

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

security/integrity/ima/ima.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ 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
185+
#define IMA_EMITTED_OPENWRITERS 5
185186

186187
/* IMA integrity metadata associated with an inode */
187188
struct ima_iint_cache {

security/integrity/ima/ima_main.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,22 @@ 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-
if (inode_is_open_for_write(inode) && must_measure)
141-
send_writers = true;
140+
set_bit(IMA_MAY_EMIT_TOMTOU, &iint->atomic_flags);
141+
142+
/* Limit number of open_writers violations */
143+
if (inode_is_open_for_write(inode) && must_measure) {
144+
if (!test_and_set_bit(IMA_EMITTED_OPENWRITERS,
145+
&iint->atomic_flags))
146+
send_writers = true;
147+
}
142148
}
143149

144150
if (!send_tomtou && !send_writers)
@@ -167,6 +173,8 @@ static void ima_check_last_writer(struct ima_iint_cache *iint,
167173
if (atomic_read(&inode->i_writecount) == 1) {
168174
struct kstat stat;
169175

176+
clear_bit(IMA_EMITTED_OPENWRITERS, &iint->atomic_flags);
177+
170178
update = test_and_clear_bit(IMA_UPDATE_XATTR,
171179
&iint->atomic_flags);
172180
if ((iint->flags & IMA_NEW_FILE) ||

0 commit comments

Comments
 (0)