Skip to content

Commit cd9b909

Browse files
stefanbergermimizohar
authored andcommitted
ima: re-evaluate file integrity on file metadata change
Force a file's integrity to be re-evaluated on file metadata change by resetting both the IMA and EVM status flags. Co-developed-by: Mimi Zohar <zohar@linux.ibm.com> Signed-off-by: Stefan Berger <stefanb@linux.ibm.com> Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
1 parent a652aa5 commit cd9b909

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

security/integrity/ima/ima_main.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/ima.h>
2727
#include <linux/fs.h>
2828
#include <linux/iversion.h>
29+
#include <linux/evm.h>
2930

3031
#include "ima.h"
3132

@@ -211,6 +212,7 @@ static int process_measurement(struct file *file, const struct cred *cred,
211212
struct inode *real_inode, *inode = file_inode(file);
212213
struct ima_iint_cache *iint = NULL;
213214
struct ima_template_desc *template_desc = NULL;
215+
struct inode *metadata_inode;
214216
char *pathbuf = NULL;
215217
char filename[NAME_MAX];
216218
const char *pathname = NULL;
@@ -286,7 +288,8 @@ static int process_measurement(struct file *file, const struct cred *cred,
286288
}
287289

288290
/*
289-
* On stacked filesystems, detect and re-evaluate file data changes.
291+
* On stacked filesystems, detect and re-evaluate file data and
292+
* metadata changes.
290293
*/
291294
real_inode = d_real_inode(file_dentry(file));
292295
if (real_inode != inode &&
@@ -297,6 +300,15 @@ static int process_measurement(struct file *file, const struct cred *cred,
297300
iint->flags &= ~IMA_DONE_MASK;
298301
iint->measured_pcrs = 0;
299302
}
303+
304+
/*
305+
* Reset the EVM status when metadata changed.
306+
*/
307+
metadata_inode = d_inode(d_real(file_dentry(file),
308+
D_REAL_METADATA));
309+
if (evm_metadata_changed(inode, metadata_inode))
310+
iint->flags &= ~(IMA_APPRAISED |
311+
IMA_APPRAISED_SUBMASK);
300312
}
301313

302314
/* Determine if already appraised/measured based on bitmask

0 commit comments

Comments
 (0)