Skip to content

Commit cd5a262

Browse files
mimizohargregkh
authored andcommitted
ima: detect changes to the backing overlay file
commit b836c4d upstream. Commit 18b44bc ("ovl: Always reevaluate the file signature for IMA") forced signature re-evaulation on every file access. Instead of always re-evaluating the file's integrity, detect a change to the backing file, by comparing the cached file metadata with the backing file's metadata. Verifying just the i_version has not changed is insufficient. In addition save and compare the i_ino and s_dev as well. Reviewed-by: Amir Goldstein <[email protected]> Tested-by: Eric Snowberg <[email protected]> Tested-by: Raul E Rangel <[email protected]> Cc: [email protected] Signed-off-by: Mimi Zohar <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent df4133e commit cd5a262

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

fs/overlayfs/super.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2028,7 +2028,7 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
20282028
sb->s_xattr = ovl_xattr_handlers;
20292029
sb->s_fs_info = ofs;
20302030
sb->s_flags |= SB_POSIXACL;
2031-
sb->s_iflags |= SB_I_SKIP_SYNC | SB_I_IMA_UNVERIFIABLE_SIGNATURE;
2031+
sb->s_iflags |= SB_I_SKIP_SYNC;
20322032

20332033
err = -ENOMEM;
20342034
root_dentry = ovl_get_root(sb, upperpath.dentry, oe);

security/integrity/ima/ima_api.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ int ima_collect_measurement(struct integrity_iint_cache *iint,
212212
{
213213
const char *audit_cause = "failed";
214214
struct inode *inode = file_inode(file);
215+
struct inode *real_inode = d_real_inode(file_dentry(file));
215216
const char *filename = file->f_path.dentry->d_name.name;
216217
int result = 0;
217218
int length;
@@ -262,6 +263,10 @@ int ima_collect_measurement(struct integrity_iint_cache *iint,
262263
iint->ima_hash = tmpbuf;
263264
memcpy(iint->ima_hash, &hash, length);
264265
iint->version = i_version;
266+
if (real_inode != inode) {
267+
iint->real_ino = real_inode->i_ino;
268+
iint->real_dev = real_inode->i_sb->s_dev;
269+
}
265270

266271
/* Possibly temporary failure due to type of read (eg. O_DIRECT) */
267272
if (!result)

security/integrity/ima/ima_main.c

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

3031
#include "ima.h"
3132

@@ -197,7 +198,7 @@ static int process_measurement(struct file *file, const struct cred *cred,
197198
u32 secid, char *buf, loff_t size, int mask,
198199
enum ima_hooks func)
199200
{
200-
struct inode *inode = file_inode(file);
201+
struct inode *backing_inode, *inode = file_inode(file);
201202
struct integrity_iint_cache *iint = NULL;
202203
struct ima_template_desc *template_desc = NULL;
203204
char *pathbuf = NULL;
@@ -271,6 +272,19 @@ static int process_measurement(struct file *file, const struct cred *cred,
271272
iint->measured_pcrs = 0;
272273
}
273274

275+
/* Detect and re-evaluate changes made to the backing file. */
276+
backing_inode = d_real_inode(file_dentry(file));
277+
if (backing_inode != inode &&
278+
(action & IMA_DO_MASK) && (iint->flags & IMA_DONE_MASK)) {
279+
if (!IS_I_VERSION(backing_inode) ||
280+
backing_inode->i_sb->s_dev != iint->real_dev ||
281+
backing_inode->i_ino != iint->real_ino ||
282+
!inode_eq_iversion(backing_inode, iint->version)) {
283+
iint->flags &= ~IMA_DONE_MASK;
284+
iint->measured_pcrs = 0;
285+
}
286+
}
287+
274288
/* Determine if already appraised/measured based on bitmask
275289
* (IMA_MEASURE, IMA_MEASURED, IMA_XXXX_APPRAISE, IMA_XXXX_APPRAISED,
276290
* IMA_AUDIT, IMA_AUDITED)

security/integrity/integrity.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ struct integrity_iint_cache {
131131
unsigned long flags;
132132
unsigned long measured_pcrs;
133133
unsigned long atomic_flags;
134+
unsigned long real_ino;
135+
dev_t real_dev;
134136
enum integrity_status ima_file_status:4;
135137
enum integrity_status ima_mmap_status:4;
136138
enum integrity_status ima_bprm_status:4;

0 commit comments

Comments
 (0)