Skip to content

Commit a422638

Browse files
Eric RichterMimi Zohar
authored andcommitted
ima: change integrity cache to store measured pcr
IMA avoids re-measuring files by storing the current state as a flag in the integrity cache. It will then skip adding a new measurement log entry if the cache reports the file as already measured. If a policy measures an already measured file to a new PCR, the measurement will not be added to the list. This patch implements a new bitfield for specifying which PCR the file was measured into, rather than if it was measured. Signed-off-by: Eric Richter <erichte@linux.vnet.ibm.com> Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
1 parent 67696f6 commit a422638

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

‎security/integrity/ima/ima_api.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ void ima_store_measurement(struct integrity_iint_cache *iint,
266266
xattr_len, NULL};
267267
int violation = 0;
268268

269-
if (iint->flags & IMA_MEASURED)
269+
if (iint->measured_pcrs & (0x1 << pcr))
270270
return;
271271

272272
result = ima_alloc_init_template(&event_data, &entry);
@@ -277,8 +277,10 @@ void ima_store_measurement(struct integrity_iint_cache *iint,
277277
}
278278

279279
result = ima_store_template(entry, violation, inode, filename, pcr);
280-
if (!result || result == -EEXIST)
280+
if (!result || result == -EEXIST) {
281281
iint->flags |= IMA_MEASURED;
282+
iint->measured_pcrs |= (0x1 << pcr);
283+
}
282284
if (result < 0)
283285
ima_free_template_entry(entry);
284286
}

‎security/integrity/ima/ima_appraise.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ static void ima_reset_appraise_flags(struct inode *inode, int digsig)
370370
return;
371371

372372
iint->flags &= ~IMA_DONE_MASK;
373+
iint->measured_pcrs = 0;
373374
if (digsig)
374375
iint->flags |= IMA_DIGSIG;
375376
return;

‎security/integrity/ima/ima_main.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ static void ima_check_last_writer(struct integrity_iint_cache *iint,
125125
if ((iint->version != inode->i_version) ||
126126
(iint->flags & IMA_NEW_FILE)) {
127127
iint->flags &= ~(IMA_DONE_MASK | IMA_NEW_FILE);
128+
iint->measured_pcrs = 0;
128129
if (iint->flags & IMA_APPRAISE)
129130
ima_update_xattr(iint, file);
130131
}
@@ -210,7 +211,11 @@ static int process_measurement(struct file *file, char *buf, loff_t size,
210211
*/
211212
iint->flags |= action;
212213
action &= IMA_DO_MASK;
213-
action &= ~((iint->flags & IMA_DONE_MASK) >> 1);
214+
action &= ~((iint->flags & (IMA_DONE_MASK ^ IMA_MEASURED)) >> 1);
215+
216+
/* If target pcr is already measured, unset IMA_MEASURE action */
217+
if ((action & IMA_MEASURE) && (iint->measured_pcrs & (0x1 << pcr)))
218+
action ^= IMA_MEASURE;
214219

215220
/* Nothing to do, just return existing appraised status */
216221
if (!action) {

0 commit comments

Comments
 (0)